Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-10-04 18:01:48 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-10-04 18:01:48 (GMT)
commit5b21d357296cb0bd94619d1d5db588a12352e2da (patch)
tree595be1d5bdb1b10b3f35ee95c65a85afcf63ce6b
parent15aa79fe0f21cf12a55940fca464b28f1ba2cca0 (diff)
Refactor UnploadPollResultFormView
-rw-r--r--webapp/polls/views.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/webapp/polls/views.py b/webapp/polls/views.py
index 1d41c65..526cabc 100644
--- a/webapp/polls/views.py
+++ b/webapp/polls/views.py
@@ -368,19 +368,24 @@ class UnploadPollResultFormView(TemplateView):
existing = []
not_authored_by_user = []
poll_not_assigned_to_user = []
- news = []
+ date_time_string = Clock.get_time_string()
for file_ in files:
+ file_name = file_.name
+ tmp_file_path = file_.temporary_file_path()
try:
- prf = PollResultFile(file_.temporary_file_path())
+ prf = PollResultFile(tmp_file_path)
if prf.exists():
- existing.append(file_.name)
+ existing.append(file_name)
elif not prf.is_authored_by(user):
- not_authored_by_user.append(file_.name)
+ not_authored_by_user.append(file_name)
elif not prf.poll_is_assigned_to(user):
- poll_not_assigned_to_user.append(file_.name)
+ poll_not_assigned_to_user.append(file_name)
else:
- news.append(file_)
+ prf.name = file_name
+ prf.set_upload_timestamp(date_time_string)
+ prf.save()
+ processed_files.append(file_name)
except ValueError:
fname = file_.name
msg = u'{0}: No es un .poll_result vĂ¡lido.'.format(fname)
@@ -405,17 +410,6 @@ class UnploadPollResultFormView(TemplateView):
)
messages.add_message(self.request, messages.ERROR, msg)
- date_time_string = Clock.get_time_string()
- uploaded_files = [
- (f.name, f.temporary_file_path()) for f in news
- ]
- for name, path in uploaded_files:
- result_file = PollResultFile(path)
- result_file.name = name
- result_file.set_upload_timestamp(date_time_string)
- result_file.save()
- processed_files.append(name)
-
if len(processed_files):
messages.add_message(
self.request,