Commit fb65c313 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'check-translations-with-pep' into 'master'

Check obsolete translations with codestyle and fix codestyle test

See merge request !985
parents 7e408ae6 9633bdd2
......@@ -16,19 +16,13 @@ stages:
- test
- deploy
obsolete-translations:
stage: test
image: $PY37_IMAGE
cache: {}
script:
# Check for obsolete translations in .po files (starting with `#~`).
- (grep --include="*.po" --quiet --recursive --regexp "^#~" website && exit 1) || exit 0
pep8:
codestyle:
stage: test
image: $PY36_IMAGE
script:
- tox -e flake8
# Check for obsolete translations in .po files (starting with `#~`).
- (grep --include="*.po" --quiet --recursive --regexp "^#~" website && exit 1) || exit 0
.djangotest: &djangotest
stage: test
......
......@@ -27,7 +27,7 @@ env =
PIPENV_SUPPRESS_NESTED_WARNING=1
[testenv:flake8]
basepython=python36
basepython=python3.6
deps= flake8
skip_install=True
commands=
......
......@@ -19,9 +19,9 @@ class MemberGroupMembershipInlineFormSet(forms.BaseInlineFormSet):
"""
Solely here for performance reasons.
Needed because the `__str__()` of `MemberGroupMembership` (which is displayed
above each inline form) uses the username, name of the member and name of
the group.
Needed because the `__str__()` of `MemberGroupMembership` (which is
displayed above each inline form) uses the username, name of the member
and name of the group.
"""
def __init__(self, *args, **kwargs):
......@@ -40,28 +40,6 @@ class MemberGroupMembershipInline(admin.StackedInline):
autocomplete_fields = ('member',)
@admin.register(models.Committee)
class CommitteeAdmin(TranslatedModelAdmin):
"""Manage the committees"""
inlines = (MemberGroupMembershipInline,)
form = MemberGroupForm
list_display = ('name', 'since', 'until', 'active', 'email')
list_filter = ('until', 'active',)
search_fields = ('name', 'description')
filter_horizontal = ('permissions',)
fields = ('name', 'description', 'photo', 'permissions', 'since',
'until', 'contact_mailinglist', 'contact_email',
'wiki_namespace', 'active')
def email(self, instance):
if instance.contact_email:
return instance.contact_email
elif instance.contact_mailinglist:
return instance.contact_mailinglist.name + '@thalia.nu'
return None
@admin.register(models.Society)
class CommitteeAdmin(TranslatedModelAdmin):
"""Manage the societies"""
......
......@@ -31,7 +31,8 @@ def membergroup_member_card(membership):
if 'since' in membership:
since_text = _('Committee member since: ') + '?'
if membership['since'].year > 1970:
since_text = _('Committee member since: ') + str(membership['since'].year)
since_text = _('Committee member since: {}').format(
membership['since'].year)
meta_text += '<p class="px-1">{}</p>'.format(since_text)
if 'role' in membership and membership['role']:
meta_text += '<p class="px-1">{}</p>'.format(membership['role'])
......
......@@ -59,25 +59,26 @@ class CommitteeMembersTest(TestCase):
m1 = MemberGroupMembership(group=self.testcie,
member=self.testuser,
since=timezone.now().date().replace(
year=2014, month=1, day=1),
year=2014, month=1, day=1),
until=timezone.now().date().replace(
year=2014, month=3, day=1))
year=2014, month=3, day=1))
m1.save()
m2 = MemberGroupMembership(group=self.testcie,
member=self.testuser,
since=timezone.now().date().replace(
year=2014, month=1, day=1),
year=2014, month=1, day=1),
until=timezone.now().date().replace(
year=2014, month=2, day=1))
year=2014, month=2, day=1))
with self.assertRaises(ValidationError):
m2.full_clean()
def test_until_date(self):
m = MemberGroupMembership(group=self.testcie,
member=self.testuser,
until=timezone.now().date().replace(year=2000),
chair=False)
m = MemberGroupMembership(
group=self.testcie,
member=self.testuser,
until=timezone.now().date().replace(year=2000),
chair=False)
with self.assertRaises(ValidationError):
m.clean()
m.since = timezone.now().date().replace(year=1900)
......
......@@ -2,8 +2,7 @@ from django.shortcuts import get_object_or_404, render, redirect, reverse
import datetime
from utils.snippets import datetime_to_lectureyear
from utils.translation import localize_attr_name
from .models import Board, MemberGroup, MemberGroupMembership, Committee, \
Society
from .models import Board, MemberGroupMembership, Committee, Society
def committee_index(request):
......
......@@ -120,8 +120,8 @@ def export(request, event_id):
if registration.member
else ''),
_('Email'): (registration.member.email
if registration.member
else ''),
if registration.member
else ''),
_('Status'): status,
_('Date cancelled'): cancelled,
}
......
......@@ -185,7 +185,10 @@ class EventRetrieveSerializer(serializers.ModelSerializer):
return instance.is_pizza_event()
def _google_maps_url(self, instance):
return create_google_maps_url(instance.map_location, zoom=13, size='450x250')
return create_google_maps_url(
instance.map_location,
zoom=13,
size='450x250')
class EventListSerializer(serializers.ModelSerializer):
......
......@@ -33,7 +33,8 @@ def _extract_date(param):
if param is None:
return None
try:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
return timezone.make_aware(
datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
except ValueError:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%d'))
......@@ -161,7 +162,8 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
queryset, many=True, context={'member': request.member})
return Response(serializer.data)
@action(detail=False, permission_classes=(IsAdminUser, UnpublishedEventPermissions,))
@action(detail=False,
permission_classes=(IsAdminUser, UnpublishedEventPermissions,))
def unpublished(self, request):
"""
Defines a custom route that outputs the correctly formatted
......
......@@ -330,8 +330,8 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
start_reminder.save()
self.start_reminder = start_reminder
if self.registration_required:
self.start_reminder.users.set(self.participants.values_list(
'member', flat=True))
self.start_reminder.users.set(
self.participants.values_list('member', flat=True))
else:
self.start_reminder.users.set(Member.current_members.all())
elif start_reminder.pk is not None:
......
......@@ -36,8 +36,10 @@ def get_automatic_lists():
['leden', 'members'], '[THALIA]',
Member.all_with_membership('member'), True, True, True)
lists += _create_automatic_list(
['begunstigers', 'benefactors'], '[THALIA]', Member.all_with_membership(
Membership.BENEFACTOR), multilingual=True)
['begunstigers', 'benefactors'],
'[THALIA]',
Member.all_with_membership(Membership.BENEFACTOR),
multilingual=True)
lists += _create_automatic_list(
['ereleden', 'honorary'], '[THALIA]', Member.all_with_membership(
'honorary'), multilingual=True)
......
......@@ -138,7 +138,9 @@ class MemberListSerializer(serializers.ModelSerializer):
def _photo(self, instance):
if instance.profile.photo:
return self.context['request'].build_absolute_uri(
thumbnail(instance.profile.photo, settings.THUMBNAIL_SIZES['medium'], 1))
thumbnail(instance.profile.photo,
settings.THUMBNAIL_SIZES['medium'],
1))
else:
return self.context['request'].build_absolute_uri(
static('members/images/default-avatar.jpg'))
......
......@@ -20,7 +20,8 @@ def _extract_date(param):
if param is None:
return None
try:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
return timezone.make_aware(
datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
except ValueError:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%d'))
......
......@@ -13,11 +13,13 @@ register = template.Library()
@register.inclusion_tag('includes/grid_item.html')
def member_card(member, meta_text=None, ribbon=None):
if meta_text is None and member.profile.starting_year:
meta_text = '<p class="px-1">{}: {}</p>'.format(_('Cohort'), member.profile.starting_year)
meta_text = '<p class="px-1">{}: {}</p>'.format(
_('Cohort'), member.profile.starting_year)
image_url = static('members/images/default-avatar.jpg')
if member.profile.photo:
image_url = thumbnail(member.profile.photo, settings.THUMBNAIL_SIZES['medium'])
image_url = thumbnail(member.profile.photo,
settings.THUMBNAIL_SIZES['medium'])
return grid_item(
title=member.profile.display_name(),
......
......@@ -5,12 +5,15 @@ from pytz.exceptions import InvalidTimeError
from rest_framework import viewsets, filters
from rest_framework.decorators import action
from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticatedOrReadOnly, \
IsAuthenticated
from rest_framework.permissions import (
IsAuthenticatedOrReadOnly, IsAuthenticated
)
from rest_framework.response import Response
from partners.api.serializers import PartnerEventCalendarJSSerializer, \
PartnerEventSerializer, PartnerSerializer
from partners.api.serializers import (
PartnerEventCalendarJSSerializer, PartnerEventSerializer,
PartnerSerializer
)
from partners.models import Partner, PartnerEvent
......@@ -19,7 +22,8 @@ def _extract_date(param):
if param is None:
return None
try:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
return timezone.make_aware(
datetime.strptime(param, '%Y-%m-%dT%H:%M:%S'))
except ValueError:
return timezone.make_aware(datetime.strptime(param, '%Y-%m-%d'))
......
......@@ -100,11 +100,13 @@ class PaymentAdminViewTest(TestCase):
'/admin/payments/payment/%s/change/' % self.payment.pk
)
process_payment.assert_called_once_with(payment_qs, payment_type)
process_payment.assert_called_once_with(
payment_qs, payment_type)
messages_success.assert_called_once_with(
response.wsgi_request, _('Successfully processed %s.') %
model_ngettext(self.payment, 1)
response.wsgi_request,
_('Successfully processed %s.') %
model_ngettext(self.payment, 1)
)
with self.subTest('Send post with failed processing'):
......@@ -115,6 +117,7 @@ class PaymentAdminViewTest(TestCase):
})
messages_error.assert_called_once_with(
response.wsgi_request, _('Could not process %s.') %
model_ngettext(self.payment, 1)
response.wsgi_request,
_('Could not process %s.') %
model_ngettext(self.payment, 1)
)
......@@ -20,5 +20,3 @@ class PaymentWidget(Widget):
context['url'] = payment.get_admin_url()
context['processed'] = payment.processed
return context
......@@ -3,7 +3,6 @@ import os
import random
import logging
from PIL.JpegImagePlugin import JpegImageFile
from django.conf import settings
from django.db import models
from django.urls import reverse
......
from io import BytesIO
from zipfile import ZipFile
from django.test import Client, TestCase, RequestFactory
from django.test import Client, TestCase
from members.models import Member
from photos.models import Album, Photo
......
......@@ -127,7 +127,6 @@ class AlbumTest(TestCase):
since=date(year=2015, month=1, day=1),
until=None)
for i in range(10):
with open("photos/fixtures/thom_assessor.png", "rb") as f:
fi = SimpleUploadedFile(name='photo{}.png'.format(i),
......@@ -150,7 +149,7 @@ class AlbumTest(TestCase):
until=date(year=2018, month=1, day=1))
with self.subTest():
self.album.date=date(year=2017, month=1, day=1)
self.album.date = date(year=2017, month=1, day=1)
self.album.save()
response = self.client.get(reverse(
......@@ -158,7 +157,7 @@ class AlbumTest(TestCase):
self.assertEqual(response.status_code, 200)
with self.subTest():
self.album.date=date(year=2018, month=9, day=5)
self.album.date = date(year=2018, month=9, day=5)
self.album.save()
response = self.client.get(reverse(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment