diff --git a/Pipfile b/Pipfile index 0559c57..5ee1c1c 100644 --- a/Pipfile +++ b/Pipfile @@ -8,7 +8,7 @@ pylint = "*" [packages] django = "*" -django-thumbs-v2 = "*" +easy-thumbnails = "*" image = "*" django-widget-tweaks = "*" # Commented out to not explicitly specify Python3 subversion. diff --git a/lostplaces/lostplaces/settings.py b/lostplaces/lostplaces/settings.py index 086f9d6..628b038 100644 --- a/lostplaces/lostplaces/settings.py +++ b/lostplaces/lostplaces/settings.py @@ -41,7 +41,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'django_thumbs', + 'easy_thumbnails', 'widget_tweaks', ] @@ -137,3 +137,11 @@ AUTH_USER_MODEL = 'lostplaces_app.Explorer' # Templates to use for authentication LOGIN_REDIRECT_URL = 'home' LOGOUT_REDIRECT_URL = 'home' + +THUMBNAIL_ALIASES = { + '': { + 'thumbnail': {'size': (390, 220), 'crop': True}, + 'hero': {'size': (700, 400), 'crop': True}, + 'large': {'size': (1920, 1080), 'crop': True}, + }, +} \ No newline at end of file diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index a52f252..392e089 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -9,129 +9,126 @@ import uuid from django.db import models from django.dispatch import receiver from django.contrib.auth.models import AbstractUser -from django_thumbs.fields import ImageThumbsField +from easy_thumbnails.fields import ThumbnailerImageField # Create your models here. class Explorer(AbstractUser): - """ - Custom user model - Addtional fields wbd - """ + """ + Custom user model + Addtional fields wbd + """ - def __str__(self): - return self.username + def __str__(self): + return self.username class Voucher(models.Model): - """ - Vouchers are authorization tokens to allow the registration of new users. - A voucher has a code, a creation and a deletion date, which are all positional. - Creation date is being set automatically during voucher creation. - """ + """ + Vouchers are authorization tokens to allow the registration of new users. + A voucher has a code, a creation and a deletion date, which are all positional. + Creation date is being set automatically during voucher creation. + """ - code = models.CharField(unique=True, max_length=10) - created = models.DateTimeField(auto_now_add=True) - expires = models.DateField() + code = models.CharField(unique=True, max_length=10) + created = models.DateTimeField(auto_now_add=True) + expires = models.DateField() - def __str__(self): - return "Voucher " + str(self.pk) + def __str__(self): + return "Voucher " + str(self.pk) class Place (models.Model): - """ - Place defines a lost place (location, name, description etc.). - """ + """ + Place defines a lost place (location, name, description etc.). + """ - name = models.CharField(max_length=50) - submitted_by = models.ForeignKey( - Explorer, - on_delete=models.SET_NULL, - null=True, - blank=True, - related_name='places' - ) - location = models.CharField(max_length=50) - latitude = models.FloatField() - longitude = models.FloatField() - description = models.TextField() + name = models.CharField(max_length=50) + submitted_when = models.DateTimeField(auto_now_add=True, null=True) + submitted_by = models.ForeignKey( + Explorer, + on_delete=models.SET_NULL, + null=True, + blank=True, + related_name='places' + ) + location = models.CharField(max_length=50) + latitude = models.FloatField() + longitude = models.FloatField() + description = models.TextField() - def __str__(self): - return self.name + def __str__(self): + return self.name def generate_image_upload_path(instance, filename): - """ - Callback for generating path for uploaded images. - """ + """ + Callback for generating path for uploaded images. + """ - return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] + return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] class PlaceImage (models.Model): - """ - PlaceImage defines an image file object that points to a file in uploads/. - Intermediate image sizes are generated as defined in SIZES. - PlaceImage references a Place to which it belongs. - """ + """ + PlaceImage defines an image file object that points to a file in uploads/. + Intermediate image sizes are generated as defined in SIZES. + PlaceImage references a Place to which it belongs. + """ - SIZES=( - {'code': 'thumbnail', 'wxh': '390x390'}, - {'code': 'hero', 'wxh': '700x700'}, - {'code': 'large', 'wxh': '1920x1920'} - ) - - description = models.TextField(blank=True) - filename = ImageThumbsField( - upload_to=generate_image_upload_path, - max_length=50, - sizes=SIZES - ) - place = models.ForeignKey( - Place, - on_delete=models.CASCADE, - related_name='images' - ) - submitted_by = models.ForeignKey( - Explorer, - on_delete=models.SET_NULL, - null=True, - blank=True, - related_name='images' - ) + SIZES=( + {'code': 'thumbnail', 'wxh': '390x390'}, + {'code': 'hero', 'wxh': '700x700'}, + {'code': 'large', 'wxh': '1920x1920'} + ) + + description = models.TextField(blank=True) + filename = ThumbnailerImageField(upload_to=generate_image_upload_path) + place = models.ForeignKey( + Place, + on_delete=models.CASCADE, + related_name='images' + ) + submitted_by = models.ForeignKey( + Explorer, + on_delete=models.SET_NULL, + null=True, + blank=True, + related_name='images' + ) - def __str__(self): - """ - Returning the name of the corresponding place + id - of this image as textual represntation of this instance - """ + def __str__(self): + """ + Returning the name of the corresponding place + id + of this image as textual represntation of this instance + """ - return ' '.join([self.place.name, str(self.pk)]) + return ' '.join([self.place.name, str(self.pk)]) # These two auto-delete files from filesystem when they are unneeded: @receiver(models.signals.post_delete, sender=PlaceImage) def auto_delete_file_on_delete(sender, instance, **kwargs): - """ - Deletes file from filesystem - when corresponding `PlaceImage` object is deleted. - """ - if instance.filename: - if os.path.isfile(instance.filename.path): - os.remove(instance.filename.path) + """ + Deletes file from filesystem + when corresponding `PlaceImage` object is deleted. + """ + if instance.filename: + if os.path.isfile(instance.filename.path): + os.remove(instance.filename.path) @receiver(models.signals.pre_save, sender=PlaceImage) def auto_delete_file_on_change(sender, instance, **kwargs): - """ - Deletes old file from filesystem - when corresponding `PlaceImage` object is updated - with new file. - """ - if not instance.pk: - return False + """ + Deletes old file from filesystem + when corresponding `PlaceImage` object is updated + with new file. + """ + if not instance.pk: + return False - try: - old_file = PlaceImage.objects.get(pk=instance.pk).filename - except PlaceImage.DoesNotExist: - return False + try: + old_file = PlaceImage.objects.get(pk=instance.pk).filename + except PlaceImage.DoesNotExist: + return False - new_file = instance.filename - if not old_file == new_file: - if os.path.isfile(old_file.path): - os.remove(old_file.path) + new_file = instance.filename + if not old_file == new_file: + if os.path.isfile(old_file.path): + os.remove(old_file.path) diff --git a/lostplaces/lostplaces_app/templates/create_place.html b/lostplaces/lostplaces_app/templates/create_place.html index 6039205..c33cb79 100644 --- a/lostplaces/lostplaces_app/templates/create_place.html +++ b/lostplaces/lostplaces_app/templates/create_place.html @@ -4,13 +4,45 @@ # {% block title %}Place erstellen{% endblock %} {% block maincontent %} +
{% endblock maincontent %} \ No newline at end of file diff --git a/lostplaces/lostplaces_app/templates/home.html b/lostplaces/lostplaces_app/templates/home.html new file mode 100644 index 0000000..908863e --- /dev/null +++ b/lostplaces/lostplaces_app/templates/home.html @@ -0,0 +1,54 @@ +{% extends 'global.html'%} +{% load static %} + +# {% block title %}Start{% endblock %} + +{% block maincontent %} + +{% if user.is_authenticated %} + Hi {{ user.username }}! + +{% else %} +Du bist nicht eingeloggt.
+ login | + signup +{% endif %} + +{{place.description}}
+{{place.description}}
Kamera
+Wachhund
+Zaun
+Security
+Du bist nicht eingeloggt.
- login | - signup -{% endif %} - -{% endblock maincontent %} \ No newline at end of file