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

Fix CSRF and Rules Admin (params field). #13

Open
wants to merge 5 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
15 changes: 6 additions & 9 deletions schedule/forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
from schedule.models import Event, Occurrence, Rule
import datetime
import time


class SpanForm(forms.ModelForm):

start = forms.DateTimeField(widget=forms.SplitDateTimeWidget)
end = forms.DateTimeField(widget=forms.SplitDateTimeWidget, help_text = _("The end time must be later than start time."))
end = forms.DateTimeField(widget=forms.SplitDateTimeWidget, help_text=_("The end time must be later than start time."))

def clean_end(self):
if self.cleaned_data['end'] <= self.cleaned_data['start']:
Expand All @@ -17,25 +15,24 @@ def clean_end(self):


class EventForm(SpanForm):
end_recurring_period = forms.DateTimeField(help_text=_("This date is ignored for one time only events."), required=False)

def __init__(self, hour24=False, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)

end_recurring_period = forms.DateTimeField(help_text = _("This date is ignored for one time only events."), required=False)


class Meta:
model = Event
exclude = ('creator', 'created_on', 'calendar')


class OccurrenceForm(SpanForm):

class Meta:
model = Occurrence
exclude = ('original_start', 'original_end', 'event', 'cancelled')


class RuleForm(forms.ModelForm):
params = forms.CharField(widget=forms.Textarea, help_text=_("Extra parameters to define this type of recursion. Should follow this format: rruleparam:value;otherparam:value."))

def clean_params(self):
params = self.cleaned_data["params"]
Expand Down
8 changes: 4 additions & 4 deletions schedule/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Meta:
verbose_name = _('event')
verbose_name_plural = _('events')
app_label = 'schedule'
get_latest_by = 'start'
get_latest_by = 'start'

def __unicode__(self):
date_format = u'l, %s' % ugettext("DATE_FORMAT")
Expand Down Expand Up @@ -158,7 +158,7 @@ def _occurrences_after_generator(self, after=None):
difference = self.end - self.start
while True:
o_start = date_iter.next()
if o_start > self.end_recurring_period:
if self.end_recurring_period is not None and o_start > self.end_recurring_period:
raise StopIteration
o_end = o_start + difference
if o_end > after:
Expand All @@ -175,11 +175,11 @@ def occurrences_after(self, after=None):
while True:
next = generator.next()
yield occ_replacer.get_occurrence(next)

def next_occurrence(self):
for o in self.occurrences_after():
return o


class EventRelationManager(models.Manager):
'''
Expand Down
5 changes: 2 additions & 3 deletions schedule/models/rules.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.db import models
from django.utils.translation import ugettext, ugettext_lazy as _

from dateutil import rrule
from django.utils.translation import ugettext_lazy as _

RRULE_WEEKDAYS = {"MO":0,"TU":1,"WE":2,"TH":3,"FR":4,"SA":5,"SU":6}

Expand Down Expand Up @@ -45,7 +44,7 @@ class Rule(models.Model):
name = models.CharField(_("name"), max_length=32)
description = models.TextField(_("description"))
frequency = models.CharField(_("frequency"), choices=freqs, max_length=10)
params = models.TextField(_("params"), null=True, blank=True)
params = models.TextField(_("params"), null=True, blank=True, help_text=_("Extra parameters to define this type of recursion. Should follow this format: rruleparam:value;otherparam:value."))

class Meta:
verbose_name = _('rule')
Expand Down
1 change: 1 addition & 0 deletions schedule/templates/schedule/cancel_occurrence.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>{% trans "Delete" %}</h1>
{% trans "Are you sure that you really want to cancel this occurrence?" %}

<form action="." method="POST">
{% csrf_token %}
<h2>{{ occurrence.title }}</h2>
<strong>From</strong> {{ occurrence.start|date:_("DATETIME_FORMAT") }}
<strong>to</strong> {{ occurrence.end|date:_("DATETIME_FORMAT") }} <br/>
Expand Down
1 change: 1 addition & 0 deletions schedule/templates/schedule/create_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<b>{% trans "Create or change event. All fields are required." %}</b>
<br/><br/>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
Expand Down
1 change: 1 addition & 0 deletions schedule/templates/schedule/delete_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>{% trans "Delete" %}</h1>
{% trans "Are you sure that you really want to delete it?" %}

<form action="." method="POST">
{% csrf_token %}
{{ object }} <br/>
<input type="submit" value="{% trans "Delete" %}" />
<input type="button" value="{% trans "Cancel" %}" onclick="window.location='{{next}}'"/>
Expand Down
1 change: 1 addition & 0 deletions schedule/templates/schedule/edit_occurrence.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<b>{% trans "Create or change occurrence. All fields are required." %}</b>
<br/><br/>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
Expand Down