Commit 052c14aa authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Implemented expiration date selection with client and strict server validation

parent 20ff5bd4
......@@ -7,7 +7,8 @@ from flowspy.flowspec.models import *
from ipaddr import *
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.db.models import Avg, Max, Min, Count
import datetime
class RouteForm(forms.ModelForm):
......@@ -40,6 +41,15 @@ class RouteForm(forms.ModelForm):
return self.cleaned_data["destination"]
except Exception:
raise forms.ValidationError('Invalid network address format')
def clean_expires(self):
date = self.cleaned_data['expires']
if date:
range_days = (date - datetime.date.today()).days
if range_days > 0 and range_days < 11:
return self.cleaned_data["expires"]
else:
raise forms.ValidationError('Invalid date range')
def clean(self):
name = self.cleaned_data.get('name', None)
......
......@@ -97,7 +97,7 @@ class Route(models.Model):
status = models.CharField(max_length=20, choices=ROUTE_STATES, blank=True, null=True, verbose_name="Status", default="PENDING")
# is_online = models.BooleanField(default=False)
# is_active = models.BooleanField(default=False)
expires = models.DateField(default=days_offset, blank=True, null=True,)
expires = models.DateField(default=days_offset)
response = models.CharField(max_length=512, blank=True, null=True)
comments = models.TextField(null=True, blank=True, verbose_name="Comments")
......
......@@ -90,29 +90,6 @@ def add_route(request):
return render_to_response('apply.html', {'form': form, 'applier':applier},
context_instance=RequestContext(request))
@login_required
@never_cache
def add_then(request):
applier = request.user.pk
if request.method == "GET":
form = RouteForm()
return render_to_response('apply.html', {'form': form, 'applier': applier},
context_instance=RequestContext(request))
else:
form = RouteForm(request.POST)
if form.is_valid():
route=form.save(commit=False)
route.applier = request.user
route.expires = days_offset()
route.save()
form.save_m2m()
route.commit_add()
return HttpResponseRedirect(reverse("group-routes"))
else:
return render_to_response('apply.html', {'form': form, 'applier':applier},
context_instance=RequestContext(request))
@login_required
@never_cache
def edit_route(request, route_slug):
......
......@@ -24,6 +24,7 @@
$("#id_port").css('width', '100px').attr('size', '5');
$("#id_destinationport").css('width', '100px').attr('size', '5');
$('#id_then').attr("multiple", "");
$( "#id_expires" ).datepicker({ dateFormat: 'yy-mm-dd' , maxDate: '+10d', minDate: '+1d', changeMonth: false, changeYear: false }).datepicker( $.datepicker.regional[ "el" ] );
$('#then_diag').dialog({
height: 220,
width: 340,
......@@ -186,6 +187,12 @@ th {
</table>
</fieldset>
<fieldset>
<legend>{% trans "Expiration" %}</legend>
<table>
<tr><th>{{ form.expires.label_tag }}</th><td>{{ form.expires }}<span class="error">{{ form.expires.errors|join:", " }}</span></td></tr>
</table>
</fieldset>
<fieldset>
<legend>{% trans "Use/Comments" %}</legend>
{% blocktrans %}
<p>Give a short description of the intended use of this rule, that justifies the parameter selection above. Feel free to include any additional comments.</p>
......
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