Commit 6aa5382c authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Fix frontend events form

parent 46257732
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import get_language, ugettext_lazy as _
from .models import RegistrationInformationField from .models import RegistrationInformationField
class RegistrationInformationFieldForm(forms.ModelForm): class RegistrationInformationFieldForm(forms.ModelForm):
order = forms.IntegerField(label=_('order'), initial=0) order = forms.IntegerField(label=_('order'), initial=0)
class Meta: class Meta:
...@@ -36,8 +35,10 @@ class FieldsForm(forms.Form): ...@@ -36,8 +35,10 @@ class FieldsForm(forms.Form):
elif field.type == RegistrationInformationField.TEXT_FIELD: elif field.type == RegistrationInformationField.TEXT_FIELD:
self.fields[key] = forms.CharField() self.fields[key] = forms.CharField()
self.fields[key].label = field.name self.fields[key].label = getattr(field, '{}_{}'.format(
self.fields[key].help_text = field.description 'name', get_language()))
self.fields[key].help_text = getattr(field, '{}_{}'.format(
'description', get_language()))
self.fields[key].initial = information_field['value'] self.fields[key].initial = information_field['value']
if not field.type == RegistrationInformationField.BOOLEAN_FIELD: if not field.type == RegistrationInformationField.BOOLEAN_FIELD:
self.fields[key].required = field.required self.fields[key].required = field.required
......
...@@ -118,7 +118,8 @@ class Event(models.Model, metaclass=ModelTranslateMeta): ...@@ -118,7 +118,8 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
return self.registrationinformationfield_set.count() > 0 return self.registrationinformationfield_set.count() > 0
def reached_participants_limit(self): def reached_participants_limit(self):
return self.max_participants <= self.registration_set.count() return (self.max_participants is not None and
self.max_participants <= self.registration_set.count())
@property @property
def status(self): def status(self):
......
...@@ -12,7 +12,7 @@ from django.utils import timezone ...@@ -12,7 +12,7 @@ from django.utils import timezone
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from .models import Event, Registration from .models import Event, Registration, RegistrationInformationField
from .forms import FieldsForm from .forms import FieldsForm
...@@ -240,6 +240,12 @@ def registration(request, event_id, action=None): ...@@ -240,6 +240,12 @@ def registration(request, event_id, action=None):
obj.save() obj.save()
form_field_values = form.field_values() form_field_values = form.field_values()
for field in form_field_values: for field in form_field_values:
import pdb
pdb.set_trace()
if (field['field'].type ==
RegistrationInformationField.INTEGER_FIELD
and field['value'] is None):
field['value'] = 0
field['field'].set_value_for(obj, field['field'].set_value_for(obj,
field['value']) field['value'])
else: else:
......
Markdown is supported
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