Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

School history #1173

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions trojsten/events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.contrib import admin
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from easy_select2 import select2_modelform
from import_export import fields, resources
from import_export.admin import ExportMixin
Expand Down Expand Up @@ -67,6 +68,7 @@ def get_queryset(self, request):


class EventParticipantExport(resources.ModelResource):
user__school__verbose_name = fields.Field()
type = fields.Field()

street = fields.Field()
Expand All @@ -83,6 +85,9 @@ class Meta:
]
widgets = {'user__birth_date': {'format': '%d.%m.%Y'}}

def dehydrate_user__school__verbose_name(selfs, obj):
return obj.user.school.verbose_name if obj.user.school else _('Other_school')

def dehydrate_type(self, obj):
return obj.get_type_display()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ <h1>Zoznam účastníkov</h1>
<td>{{ participant.user.get_full_name }}</td>
<td>{{ participant.year_at_event | school_year }}</td>
<td>
{% if participant.user.school.has_abbreviation %}
<abbr title="{{ participant.user.school.verbose_name }}"
{% if participant.school_at_event.has_abbreviation %}
<abbr title="{{ participant.school_at_event.verbose_name }}"
data-toggle="tooltip" data-placement="top">
{{ participant.user.school.abbreviation }}
{{ participant.school_at_event.abbreviation }}
</abbr>
{% else %}
{{ participant.user.school.verbose_name }}
{{ participant.school_at_event.verbose_name }}
{% endif %}
</td>
</tr>
Expand All @@ -39,13 +39,13 @@ <h1>Zoznam účastníkov</h1>
<tr {% if user == organizer.user %}class="active"{% endif %}>
<td colspan="2">{{ organizer.user.get_full_name }}</td>
<td>
{% if organizer.user.school.has_abbreviation %}
<abbr title="{{ organizer.user.school.verbose_name }}"
{% if organizer.school_at_event.has_abbreviation %}
<abbr title="{{ organizer.school_at_event.verbose_name }}"
data-toggle="tooltip" data-placement="top">
{{ organizer.user.school.abbreviation }}
{{ organizer.school_at_event.abbreviation }}
</abbr>
{% else %}
{{ organizer.user.school.verbose_name }}
{{ organizer.school_at_event.verbose_name }}
{% endif %}
</td>
</tr>
Expand Down
63 changes: 51 additions & 12 deletions trojsten/events/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from django.utils import timezone
from wiki.models import Article, ArticleRevision, URLPath

from trojsten.people.models import User
from trojsten.people.models import User, UserSchool
from trojsten.schools.models import School
from trojsten.utils.test_utils import get_noexisting_id

from .models import Event, EventParticipant, EventPlace, EventType
Expand Down Expand Up @@ -193,25 +194,63 @@ def test_participant_substitute_display(self):


class ParticipantsAndOrganizersListViewTest(TestCase):
def test_school_year(self):
def setUp(self):
current_year = timezone.now().year
site = Site.objects.get(pk=settings.SITE_ID)
user = User.objects.create(
self.user = User.objects.create(
username='ferko', first_name='Ferko', last_name='Mrkvicka',
graduation=current_year - 1)

group = Group.objects.create(name="skupina")
place = EventPlace.objects.create(name="Miesto")
type_camp = EventType.objects.create(name="sustredenie",
organizers_group=group, is_camp=True)
type_camp.sites.add(site)
event = Event.objects.create(
self.place = EventPlace.objects.create(name="Miesto")
self.type_camp = EventType.objects.create(name="sustredenie",
organizers_group=group, is_camp=True)
self.type_camp.sites.add(site)
self.event = Event.objects.create(
start_time=datetime.datetime(day=12, month=3, year=current_year - 2, tzinfo=pytz.utc),
end_time=datetime.datetime(day=17, month=3, year=current_year - 2, tzinfo=pytz.utc),
place=place, type=type_camp,
place=self.place, type=self.type_camp,
)
EventParticipant.objects.create(event=event, user=user, going=True, type=0)
EventParticipant.objects.create(event=self.event, user=self.user, going=True, type=0)

part_list_url = reverse('participants_list', kwargs={'event_id': event.id})
response = self.client.get(part_list_url)
self.old_school = School.objects.create(
abbreviation='GYMN1', verbose_name='Gymnázium Janka Hraška',
street='Hronca 42', city='Bratislava', zip_code='123 45'
)
self.current_school = School.objects.create(
abbreviation='GYMN2', verbose_name='Gymnázium Janka Hraška',
street='Hronca 42', city='Bratislava', zip_code='123 45'
)
UserSchool.objects.create(
user=self.user, school=self.old_school, start_time=self.event.start_time + timezone.timedelta(-10)
)
UserSchool.objects.create(
user=self.user, school=self.current_school, start_time=self.event.end_time + timezone.timedelta(10)
)

self.part_list_url = reverse('participants_list', kwargs={'event_id': self.event.id})

def test_school_year(self):
response = self.client.get(self.part_list_url)

self.assertContains(response, '<td>3</td>')

def test_old_school_at_event_time(self):
response = self.client.get(self.part_list_url)

self.assertContains(response, self.old_school.abbreviation)
self.assertNotContains(response, self.current_school.abbreviation)

def test_current_school_at_event_time(self):
event = Event.objects.create(
start_time=self.event.end_time + timezone.timedelta(20),
end_time=self.event.end_time + timezone.timedelta(30),
place=self.place, type=self.type_camp,
)
EventParticipant.objects.create(event=event, user=self.user, going=True, type=0)

url = reverse('participants_list', kwargs={'event_id': event.id})
response = self.client.get(url)

self.assertContains(response, self.current_school.abbreviation)
self.assertNotContains(response, self.old_school.abbreviation)
9 changes: 7 additions & 2 deletions trojsten/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ class ParticipantsAndOrganizersListView(DetailView):
def get_context_data(self, **kwargs):
context = super(ParticipantsAndOrganizersListView, self).get_context_data(**kwargs)
event = context['event']
participants = event.participants.select_related('user__school')
participants = event.participants
for participant in participants:
participant.year_at_event = participant.user.school_year_at(event.start_time)
participant.school_at_event = participant.user.school_at(event.start_time)

organizers = event.organizers
for organizer in organizers:
organizer.school_at_event = organizer.user.school_at(event.start_time)
context.update({
'participants': participants,
'organizers': event.organizers.select_related('user__school'),
'organizers': organizers,
})
return context

Expand Down
Loading