Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/polls/forms.py
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-04-17 19:53:32 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-04-17 19:53:32 (GMT)
commit75fb7483b0a3c0c362e11e4d5b4c5085a55626ba (patch)
tree814ee2b67e8696d0fec36c2280a8b51617fd55c3 /webapp/polls/forms.py
parent559dac8c0f400198c9c89a9aa09902fb1c44c4e1 (diff)
Refactoring and adding dates registers to poll document
Diffstat (limited to 'webapp/polls/forms.py')
-rw-r--r--webapp/polls/forms.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/webapp/polls/forms.py b/webapp/polls/forms.py
index 9f62e1f..651f12f 100644
--- a/webapp/polls/forms.py
+++ b/webapp/polls/forms.py
@@ -1,4 +1,5 @@
import re
+import copy
from django import forms
@@ -43,23 +44,25 @@ class PollForm(forms.Form):
return name
- def clean_status(self):
- # Preserving the state. REFACTORING: Idea to preserve in any document
- # The refactoring is big, django form must be capable that accept
- # any type of mongo document
+ def save(self):
+ # REQUIRE: when use this method, run is_valid method first
- id = self.cleaned_data['id']
- status = self.cleaned_data['status']
+ _data = copy.deepcopy(self.cleaned_data)
+ for field_name, field_value in self.cleaned_data.iteritems():
+ if not field_value:
+ del _data[field_name]
- if id and not status:
+ id = self.cleaned_data['id']
+ if id:
+ # Preserving!. REFACTORING: Idea to preserve in any document
+ # The refactoring is big, django form must be capable that accept
+ # any type of mongo document
poll = Poll.get(id)
- status = poll.status
+ old_data = poll.to_python(with_dates=True)
+ old_data.update(_data)
+ _data = old_data
- return status
-
- def save(self):
- # REQUIRE: when use this method, run is_valid method first
- poll = Poll(data=self.cleaned_data)
+ poll = Poll(data=_data)
try:
poll_id = poll.save()