Permalink
Browse files

Merge branch 'develop' into country-in-person-event-api

  • Loading branch information...
pbanaszkiewicz committed Oct 6, 2018
2 parents 432f70f + f7f0fdf commit 11d1a2313769325b27a7cb0dadc4952bae4118a6
Showing with 59 additions and 15 deletions.
  1. +1 −0 amy/settings.py
  2. +6 −12 api/filters.py
  3. +25 −1 workshops/forms.py
  4. +17 −0 workshops/migrations/0157_auto_20181006_0859.py
  5. +6 −1 workshops/models.py
  6. +4 −1 workshops/views.py
@@ -102,6 +102,7 @@
]
if DEBUG:
ALLOWED_HOSTS.append('127.0.0.1')
ALLOWED_HOSTS.append('localhost')
##################### T E M P L A T E S #####################
@@ -8,22 +8,16 @@
from workshops.models import Event, Task, Tag, Person, Badge
def filter_tag_by_name(queryset, name, values):
# tags = Tag.objects.filter(name__in=values)
# for tag in tags:
# queryset = queryset.filter(tags=tag)
# return queryset
return Tag.objects.all()
class EventFilter(filters.FilterSet):
start_after = filters.DateFilter(field_name='start', lookup_expr='gte')
start_before = filters.DateFilter(field_name='start', lookup_expr='lte')
end_after = filters.DateFilter(field_name='end', lookup_expr='gte')
end_before = filters.DateFilter(field_name='end', lookup_expr='lte')
TAG_CHOICES = Tag.objects.all().values_list('name', 'name')
tag = filters.MultipleChoiceFilter(
choices=TAG_CHOICES, field_name='tags', method=filter_tag_by_name,
tags = filters.ModelMultipleChoiceFilter(
field_name='tags__name',
to_field_name='name',
queryset=Tag.objects.all(),
conjoined=True,
)
order_by = filters.OrderingFilter(
fields=(
@@ -36,7 +30,7 @@ class EventFilter(filters.FilterSet):
class Meta:
model = Event
fields = (
'completed', 'tag',
'completed', 'tags',
'administrator', 'host',
'start', 'start_before', 'start_after',
'end', 'end_before', 'end_after',
@@ -1850,11 +1850,18 @@ class BulkMatchTrainingRequestForm(forms.Form):
widget=ModelSelect2(url='membership-lookup'),
)
seat_open_training = forms.BooleanField(
label='Open training seat',
required=False,
help_text="Some TTT events allow for open training; check this field "
"to count this person into open applications.",
)
helper = BootstrapHelper(add_submit_button=False,
form_tag=False,
add_cancel_button=False)
helper.layout = Layout(
'event', 'seat_membership',
'event', 'seat_membership', 'seat_open_training',
)
helper.add_input(
Submit(
@@ -1873,12 +1880,29 @@ class BulkMatchTrainingRequestForm(forms.Form):
def clean(self):
super().clean()
event = self.cleaned_data['event']
member_site = self.cleaned_data['seat_membership']
open_training = self.cleaned_data['seat_open_training']
if any(r.person is None for r in self.cleaned_data.get('requests', [])):
raise ValidationError('Some of the requests are not matched '
'to a trainee yet. Before matching them to '
'a training, you need to accept them '
'and match with a trainee.')
if member_site and open_training:
raise ValidationError(
"Cannot simultaneously match as open training and use "
"a Membership instructor training seat."
)
if open_training and not event.open_TTT_applications:
raise ValidationError({
'seat_open_training': ValidationError(
'Selected TTT event does not allow for open training seats.'
),
})
class MatchTrainingRequestForm(forms.Form):
"""Form used to match a training request to a Person."""
@@ -0,0 +1,17 @@
# Generated by Django 2.1 on 2018-10-06 13:59
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('workshops', '0156_auto_20180927_1516'),
]
operations = [
migrations.AlterModelOptions(
name='language',
options={'ordering': ['name']},
),
]
@@ -919,6 +919,9 @@ class Language(models.Model):
def __str__(self):
return self.name
class Meta:
ordering = ["name"]
#------------------------------------------------------------
# In order to make our custom filters chainable, we have to
@@ -1073,7 +1076,9 @@ class Event(AssignmentMixin, models.Model):
null=True, blank=True,
help_text=PUBLISHED_HELP_TEXT,
)
end = models.DateField(null=True, blank=True)
end = models.DateField(
null=True, blank=True,
)
slug = models.SlugField(
max_length=STR_LONG, unique=True,
help_text='Use <code>YYYY-MM-DD-location</code> format, where '
@@ -3144,6 +3144,7 @@ def all_trainingrequests(request):
if match_form.is_valid():
member_site = match_form.cleaned_data['seat_membership']
open_seat = match_form.cleaned_data['seat_open_training']
# Perform bulk match
for r in match_form.cleaned_data['requests']:
@@ -3156,7 +3157,9 @@ def all_trainingrequests(request):
person=r.person,
role=Role.objects.get(name='learner'),
event=match_form.cleaned_data['event'],
seat_membership=member_site)
seat_membership=member_site,
seat_open_training=open_seat,
)
requests_count = len(match_form.cleaned_data['requests'])
today = datetime.date.today()

0 comments on commit 11d1a23

Please sign in to comment.