Commit e791bbfc authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Perform date checks

during project add form validation
parent e3b0fbae
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
from urlparse import urljoin
from random import random
from datetime import datetime, timedelta
from django import forms
from django.utils.translation import ugettext as _
......@@ -765,6 +766,26 @@ class ProjectApplicationForm(forms.ModelForm):
self.precursor_application = kwargs.get('instance')
super(ProjectApplicationForm, self).__init__(*args, **kwargs)
def clean_start_date(self):
start_date = self.cleaned_data.get('start_date')
now = datetime.now()
if start_date and now - start_date > timedelta(days=1):
raise forms.ValidationError(
_(astakos_messages.INVALID_PROJECT_START_DATE))
return start_date
def clean_end_date(self):
start_date = self.cleaned_data.get('start_date')
end_date = self.cleaned_data.get('end_date')
now = datetime.now()
if end_date and now - end_date > timedelta(days=1):
raise forms.ValidationError(
_(astakos_messages.INVALID_PROJECT_END_DATE))
if start_date and end_date <= start_date:
raise forms.ValidationError(
_(astakos_messages.INCONSISTENT_PROJECT_DATES))
return end_date
def clean(self):
userid = self.data.get('user', None)
self.user = None
......
......@@ -169,6 +169,9 @@ MEMBER_LEAVE_POLICY_CLOSED = 'The project\'s member leave policy
NOT_MEMBERSHIP_REQUEST = 'This is not a valid membership request.'
MEMBERSHIP_REQUEST_EXISTS = 'The membership request already exists.'
NO_APPLICANT = 'Project application requires an applicant. None found.'
INVALID_PROJECT_START_DATE = 'Project start date should be equal or greater than the current date'
INVALID_PROJECT_END_DATE = 'Project end date should be equal or greater than than the current date'
INCONSISTENT_PROJECT_DATES = 'Project end date should be greater than the project start date'
ADD_PROJECT_MEMBERS_Q_HELP = 'Add a comma separated list of user emails, eg. user1@user.com, user2@user.com'
MISSING_IDENTIFIER = 'Missing identifier.'
UNKNOWN_USER_ID = 'There is no user identified by %s.'
......
......@@ -24,27 +24,32 @@
users. </span>
</span>
</legend>
{% for field in form %}
{% if field.name in details_fields %}
<div class="form-row {% if field.errors|length %}with-errors
{% for key, err in form.errors.items %}
{% if key == "__all__" %}
<div class="form-error">{{ err }}</div>
{% endif %}
{% endfor %}
{% for field in form %}
{% if field.name in details_fields %}
<div class="form-row {% if field.errors|length %}with-errors
{% endif %}
{% if field.is_hidden %}with-hidden{% endif %}">
{{ field.errors }}
<p class="clearfix {% if field.blank %}required{% endif %}">
{{ field.label_tag }}
{{ field|safe }}
<span class="extra-img">&nbsp;</span>
{% if field.help_text %}
<span class="info">
<em>more info</em>
<span>{{ field.help_text|safe }}</span>
</span>
{% endif %}
</p>
</div>
{% endif %}
{% endfor %}
{{ field.errors }}
<p class="clearfix {% if field.blank %}required{% endif %}">
{{ field.label_tag }}
{{ field|safe }}
<span class="extra-img">&nbsp;</span>
{% if field.help_text %}
<span class="info">
<em>more info</em>
<span>{{ field.help_text|safe }}</span>
</span>
{% endif %}
</p>
</div>
{% endif %}
{% endfor %}
......
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