From 985ab2ed7571bbf3a13c4865252c39ebd018975a Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 5 Aug 2020 18:57:09 +0200 Subject: [PATCH] Unified indentation using 4 spacec according to PEP8. --- lostplaces/lostplaces/settings.py | 6 +- lostplaces/lostplaces_app/forms.py | 62 +++---- lostplaces/lostplaces_app/models.py | 172 +++++++++--------- .../templates/create_place.html | 66 +++---- lostplaces/lostplaces_app/templates/home.html | 10 +- .../templates/partials/form/inputField.html | 22 +-- .../templates/placeOverview.html | 56 +++--- .../templates/update_place.html | 66 +++---- lostplaces/lostplaces_app/urls.py | 4 +- lostplaces/lostplaces_app/views.py | 12 +- lostplaces/templates/registration/login.html | 6 +- lostplaces/templates/signup.html | 60 +++--- 12 files changed, 271 insertions(+), 271 deletions(-) diff --git a/lostplaces/lostplaces/settings.py b/lostplaces/lostplaces/settings.py index 795ee64..1bdf660 100644 --- a/lostplaces/lostplaces/settings.py +++ b/lostplaces/lostplaces/settings.py @@ -42,7 +42,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'easy_thumbnails', - 'widget_tweaks', + 'widget_tweaks', ] MIDDLEWARE = [ @@ -141,7 +141,7 @@ LOGOUT_REDIRECT_URL = 'home' THUMBNAIL_ALIASES = { '': { 'thumbnail': {'size': (300, 300), 'crop': False}, - 'hero': {'size': (700, 700), 'crop': False}, - 'large': {'size': (1920, 1920), 'crop': False}, + 'hero': {'size': (700, 700), 'crop': False}, + 'large': {'size': (1920, 1920), 'crop': False}, }, } diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index 69e9a2d..d88d090 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -8,43 +8,43 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import Explorer, Place, PlaceImage, Voucher class ExplorerCreationForm(UserCreationForm): - class Meta: - model = Explorer - fields = ('username', 'email') - voucher = forms.CharField(max_length=10, help_text='The Voucher you got from an administrator') + class Meta: + model = Explorer + fields = ('username', 'email') + voucher = forms.CharField(max_length=10, help_text='The Voucher you got from an administrator') - def is_valid(self): - super().is_valid() - sumitted_voucher = self.cleaned_data.get('voucher') - try: - fetched_voucher = Voucher.objects.get(code=sumitted_voucher) - except Voucher.DoesNotExist: - self.add_error('voucher', 'Invalid voucher') - return False + def is_valid(self): + super().is_valid() + sumitted_voucher = self.cleaned_data.get('voucher') + try: + fetched_voucher = Voucher.objects.get(code=sumitted_voucher) + except Voucher.DoesNotExist: + self.add_error('voucher', 'Invalid voucher') + return False - fetched_voucher.delete() - return True + fetched_voucher.delete() + return True class ExplorerChangeForm(UserChangeForm): - class Meta: - model = Explorer - fields = ('username', 'email') + class Meta: + model = Explorer + fields = ('username', 'email') class PlaceForm(forms.ModelForm): - class Meta: - model = Place - fields = '__all__' - exclude = ['submitted_by'] - + class Meta: + model = Place + fields = '__all__' + exclude = ['submitted_by'] + class PlaceImageCreateForm(forms.ModelForm): - class Meta: - model = PlaceImage - fields = ['filename'] - widgets = { - 'filename': forms.ClearableFileInput(attrs={'multiple': True}) - } + class Meta: + model = PlaceImage + fields = ['filename'] + widgets = { + 'filename': forms.ClearableFileInput(attrs={'multiple': True}) + } - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) - self.fields['filename'].required = False + self.fields['filename'].required = False diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index 03cb646..907f3bc 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -14,115 +14,115 @@ 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_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() + 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. - """ - - 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' - ) + """ + 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. + """ + + 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 c33cb79..e739819 100644 --- a/lostplaces/lostplaces_app/templates/create_place.html +++ b/lostplaces/lostplaces_app/templates/create_place.html @@ -5,43 +5,43 @@ {% block maincontent %}
-
- Place erstellen - {% csrf_token %} -
-
- {% include 'partials/form/inputField.html' with field=place_form.name %} -
-
- {% include 'partials/form/inputField.html' with field=place_form.location %} -
-
+
+ Place erstellen + {% csrf_token %} +
+
+ {% include 'partials/form/inputField.html' with field=place_form.name %} +
+
+ {% include 'partials/form/inputField.html' with field=place_form.location %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=place_form.latitude %} -
-
- {% include 'partials/form/inputField.html' with field=place_form.longitude %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=place_form.latitude %} +
+
+ {% include 'partials/form/inputField.html' with field=place_form.longitude %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=place_form.description %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=place_form.description %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=place_image_form.filename %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=place_image_form.filename %} +
+
-
- -
-
+
+ +
+
diff --git a/lostplaces/lostplaces_app/templates/home.html b/lostplaces/lostplaces_app/templates/home.html index d5956fb..a151e0f 100644 --- a/lostplaces/lostplaces_app/templates/home.html +++ b/lostplaces/lostplaces_app/templates/home.html @@ -8,7 +8,7 @@

Explore the latest locations

- - - - {% endfor %} + + + + {% endfor %} diff --git a/lostplaces/lostplaces_app/templates/partials/form/inputField.html b/lostplaces/lostplaces_app/templates/partials/form/inputField.html index 4206f51..1d141c2 100644 --- a/lostplaces/lostplaces_app/templates/partials/form/inputField.html +++ b/lostplaces/lostplaces_app/templates/partials/form/inputField.html @@ -1,16 +1,16 @@ {% load widget_tweaks %}
- - {% render_field field class="LP-Input__Field"%} + + {% render_field field class="LP-Input__Field"%} - - {% if field.errors %} - {% for error in field.errors%} - {{error}} - {% endfor %} - {% elif field.help_text%} - {{ field.help_text }} - {% endif %} - + + {% if field.errors %} + {% for error in field.errors%} + {{error}} + {% endfor %} + {% elif field.help_text%} + {{ field.help_text }} + {% endif %} +
\ No newline at end of file diff --git a/lostplaces/lostplaces_app/templates/placeOverview.html b/lostplaces/lostplaces_app/templates/placeOverview.html index 75c473b..d0444f7 100644 --- a/lostplaces/lostplaces_app/templates/placeOverview.html +++ b/lostplaces/lostplaces_app/templates/placeOverview.html @@ -11,8 +11,8 @@
- -
+ +

{{place.name}}

@@ -26,26 +26,26 @@
    -
  • -
    -

    Kamera

    -
    -
  • -
  • -
    -

    Wachhund

    -
    -
  • -
  • -
    -

    Zaun

    -
    -
  • -
  • -
    -

    Security

    -
    -
  • +
  • +
    +

    Kamera

    +
    +
  • +
  • +
    +

    Wachhund

    +
    +
  • +
  • +
    +

    Zaun

    +
    +
  • +
  • +
    +

    Security

    +
    +
@@ -57,22 +57,22 @@
-
+

Bilder

    - {% for place_image in place.images.all %} + {% for place_image in place.images.all %}
  • -
  • - {% endfor %} + + {% endfor %}
diff --git a/lostplaces/lostplaces_app/templates/update_place.html b/lostplaces/lostplaces_app/templates/update_place.html index 3eaefa1..29af400 100644 --- a/lostplaces/lostplaces_app/templates/update_place.html +++ b/lostplaces/lostplaces_app/templates/update_place.html @@ -5,43 +5,43 @@ {% block maincontent %}
-
- Place aktualisieren - {% csrf_token %} -
-
- {% include 'partials/form/inputField.html' with field=form.name %} -
-
- {% include 'partials/form/inputField.html' with field=form.location %} -
-
+
+ Place aktualisieren + {% csrf_token %} +
+
+ {% include 'partials/form/inputField.html' with field=form.name %} +
+
+ {% include 'partials/form/inputField.html' with field=form.location %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=form.latitude %} -
-
- {% include 'partials/form/inputField.html' with field=form.longitude %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=form.latitude %} +
+
+ {% include 'partials/form/inputField.html' with field=form.longitude %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=form.description %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=form.description %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=form.filename %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=form.filename %} +
+
-
- -
-
+
+ +
+
diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py index feb6737..c810057 100644 --- a/lostplaces/lostplaces_app/urls.py +++ b/lostplaces/lostplaces_app/urls.py @@ -1,7 +1,7 @@ from django.urls import path from .views import ( hello_world, - HomeView, + HomeView, place_detail_view, place_list_view, SignUpView, @@ -11,7 +11,7 @@ from .views import ( urlpatterns = [ path('hello_world/', hello_world), # You know what this is :P - path('', HomeView.as_view(), name='home'), + path('', HomeView.as_view(), name='home'), path('signup/', SignUpView.as_view(), name='signup'), path('place//', place_detail_view, name='place_detail'), path('place/create/', PlaceCreateView.as_view(), name='place_create'), diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 8144e4c..8e97fe2 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -29,12 +29,12 @@ def hello_world(request): return render(request, 'hello_world.html', {'text':'Hello World!'}) class HomeView(View): - def get(self, request, *args, **kwargs): - place_list = Place.objects.all().order_by('submitted_when')[:10] - context = { - 'place_list': place_list - } - return render(request, 'home.html', context) + def get(self, request, *args, **kwargs): + place_list = Place.objects.all().order_by('submitted_when')[:10] + context = { + 'place_list': place_list + } + return render(request, 'home.html', context) class PlaceUpdateView(UpdateView): template_name = 'update_place.html' diff --git a/lostplaces/templates/registration/login.html b/lostplaces/templates/registration/login.html index afd54d9..ffe8e03 100644 --- a/lostplaces/templates/registration/login.html +++ b/lostplaces/templates/registration/login.html @@ -7,9 +7,9 @@

Login

- {% csrf_token %} - {{ form.as_p }} - + {% csrf_token %} + {{ form.as_p }} +
{% endblock maincontent %} \ No newline at end of file diff --git a/lostplaces/templates/signup.html b/lostplaces/templates/signup.html index 2ef3042..b6cd18a 100644 --- a/lostplaces/templates/signup.html +++ b/lostplaces/templates/signup.html @@ -7,38 +7,38 @@ {% block maincontent %}
-
- Registrierung - {% csrf_token %} -
-
- {% include 'partials/form/inputField.html' with field=form.username %} -
-
- {% include 'partials/form/inputField.html' with field=form.email %} -
-
+
+ Registrierung + {% csrf_token %} +
+
+ {% include 'partials/form/inputField.html' with field=form.username %} +
+
+ {% include 'partials/form/inputField.html' with field=form.email %} +
+
-
-
- {% include 'partials/form/inputField.html' with field=form.password1 %} -
-
-
-
- {% include 'partials/form/inputField.html' with field=form.password2 %} -
-
-
-
- {% include 'partials/form/inputField.html' with field=form.voucher %} -
-
+
+
+ {% include 'partials/form/inputField.html' with field=form.password1 %} +
+
+
+
+ {% include 'partials/form/inputField.html' with field=form.password2 %} +
+
+
+
+ {% include 'partials/form/inputField.html' with field=form.voucher %} +
+
-
- -
-
+
+ +
+