Use the right form of names to be stored in the database.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Mon, 17 Jan 2011 04:37:07 +0530
changeset 440 56ea209e559f
parent 439 66bdb28ebaf6
child 441 10f16121a46b
Use the right form of names to be stored in the database.
pytask/profile/models.py
pytask/profile/views.py
pytask/taskapp/views.py
--- a/pytask/profile/models.py	Mon Jan 17 04:06:21 2011 +0530
+++ b/pytask/profile/models.py	Mon Jan 17 04:37:07 2011 +0530
@@ -4,7 +4,7 @@
 
 
 GENDER_CHOICES = (
-  ( 'Male', 'Male'),
+  ('Male', 'Male'),
   ('Female', 'Female'),
 )
 
--- a/pytask/profile/views.py	Mon Jan 17 04:06:21 2011 +0530
+++ b/pytask/profile/views.py	Mon Jan 17 04:37:07 2011 +0530
@@ -28,7 +28,6 @@
     """ Display the profile information of the user specified in the ID.
     """
 
-    
     user = shortcuts.get_object_or_404(User, pk=user_id)
     profile = user.get_profile()
 
@@ -164,12 +163,13 @@
     viewing_user = get_user(uid)
     viewing_profile = viewing_user.get_profile()
 
-    working_tasks = viewing_user.approved_tasks.filter(status="WR")
-    completed_tasks = viewing_user.approved_tasks.filter(status="CM")
+    working_tasks = viewing_user.approved_tasks.filter(status="Working")
+    completed_tasks = viewing_user.approved_tasks.filter(status="Completed")
     reviewing_tasks = viewing_user.reviewing_tasks.all()
     claimed_tasks = viewing_user.claimed_tasks.all()
 
-    can_view_info = True if profile.rights in ["MG", "DC"] else False
+    can_view_info = True if profile.role in [
+      'Administrator', 'Coordinator'] else False
 
     context = {"user": user,
                "profile": profile,
--- a/pytask/taskapp/views.py	Mon Jan 17 04:06:21 2011 +0530
+++ b/pytask/taskapp/views.py	Mon Jan 17 04:37:07 2011 +0530
@@ -12,6 +12,8 @@
 
 from pytask.views import show_msg
 
+from pytask.profile import models as profile_models
+
 from pytask.taskapp import forms as taskapp_forms
 from pytask.taskapp import models as taskapp_models
 
@@ -28,7 +30,8 @@
 
     context.update(csrf(request))
 
-    can_create_task = False if profile.rights == "CT" else True
+    can_create_task = False if (
+      profile.role == profile_models.ROLE_CHOICES[3][0]) else True
     if can_create_task:
         if request.method == "POST":
             form = taskapp_forms.CreateTaskForm(request.POST)
@@ -56,9 +59,9 @@
 
 def browse_tasks(request):
 
-    open_tasks = taskapp_models.Task.objects.filter(status="OP")
-    working_tasks = taskapp_models.Task.objects.filter(status="WR")
-    comp_tasks = taskapp_models.Task.objects.filter(status="CM")
+    open_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[1][0])
+    working_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[3][0])
+    comp_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[6][0])
 
     context = {"open_tasks": open_tasks,
                "working_tasks": working_tasks,
@@ -71,8 +74,8 @@
 
     profile = user.get_profile()
 
-    can_approve = True if profile.rights in ["MG", "DC"] else False
-    unpub_tasks = taskapp_models.Task.objects.filter(status="UP").exclude(status="DL")
+    can_approve = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else False
+    unpub_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[0][0]).exclude(status=taskapp_models.TASK_STATUS_CHOICES[5][0])
     if can_approve:
         context.update({"unpub_tasks": unpub_tasks})
 
@@ -105,11 +108,11 @@
 
     context.update(csrf(request))
 
-    if task.status == "DL":
+    if task.status == taskapp_models.TASK_STATUS_CHOICES[5][0]:
         return show_msg(user, 'This task no longer exists',
                         reverse('browse_tasks'), 'browse the tasks')
 
-    task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\
+    task_viewable = True if ( task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] ) or profile.role != profile_models.ROLE_CHOICES[3][0] \
                          else False
     if not task_viewable:
         return show_msg(user, "You are not authorised to view this task",
@@ -131,20 +134,20 @@
 
     context['selected_users'] = selected_users
     context['is_selected'] = True if user in selected_users else False
-    context['can_approve'] = True if task.status == "UP" and\
-                                     profile.rights in ["MG", "DC"]\
+    context['can_approve'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and\
+                                     profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]]\
                                      else False
-    context['can_edit'] = True if is_creator and task.status == "UP" else False
-    context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False
-    context['can_delete'] = True if task.status == "UP" and is_creator else False
+    context['can_edit'] = True if is_creator and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] else False
+    context['can_close'] = True if task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], taskapp_models.TASK_STATUS_CHOICES[4][0], taskapp_models.TASK_STATUS_CHOICES[6][0]] and is_reviewer else False
+    context['can_delete'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False
 
-    context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False
-    context['task_claimable'] = True if task.status in ["OP", "WR"] else False
+    context['can_assign_pynts'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] and is_reviewer else False
+    context['task_claimable'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False
 
-    context['can_comment'] = True if task.status != "UP" or\
-                                     profile.rights!="CT" else False
+    context['can_comment'] = True if task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] or\
+                                     profile.role != profile_models.ROLE_CHOICES[3][0] else False
 
-    context['can_mod_reviewers'] = True if profile.rights in ["MG", "DC"] else\
+    context['can_mod_reviewers'] = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else\
                                    False
 
     if request.method == 'POST':
@@ -177,7 +180,7 @@
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
     is_creator = True if user == task.created_by else False
-    can_edit = True if task.status == "UP" and is_creator else False
+    can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False
     if not can_edit:
         raise http.Http404
 
@@ -209,7 +212,7 @@
 
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
-    if profile.rights not in ["MG", "DC"] or task.status != "UP":
+    if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]:
         raise http.Http404
 
     context = {"user": user,
@@ -227,12 +230,12 @@
 
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
-    if profile.rights not in ["MG", "DC"] or task.status != "UP":
+    if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]:
         raise http.Http404
 
     task.approved_by = user
     task.approval_datetime = datetime.now()
-    task.status = "OP"
+    task.status = taskapp_models.TASK_STATUS_CHOICES[1][0]
     task.save()
 
     context = {"user": user,
@@ -251,7 +254,7 @@
     task_url = reverse('view_task', kwargs={'task_id': task_id})
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
-    can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False
+    can_mod_reviewers = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else False
     if not can_mod_reviewers:
         raise http.Http404
 
@@ -348,7 +351,7 @@
     user = request.user
     old_reports = task.reports.all()
 
-    if not task.status == "WR":
+    if not task.status == taskapp_models.TASK_STATUS_CHOICES[3][0]:
         raise http.Http404
 
     can_upload = True if user in task.selected_users.all() else False
@@ -395,7 +398,7 @@
     user = request.user
     profile = user.get_profile()
 
-    can_create = True if profile.rights != "CT" else False
+    can_create = True if profile.role != profile_models.ROLE_CHOICES[3][0] else False
     if not can_create:
         raise http.Http404
 
@@ -451,11 +454,11 @@
 
     context.update(csrf(request))
 
-    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
+    can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\
                        else False
 
-    can_approve = True if profile.rights in ["MG", "DC"] and \
-                          textbook.status == "UP" else False
+    can_approve = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] and \
+                          textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0] else False
 
     context.update({"can_edit": can_edit,
                     "can_approve": can_approve})
@@ -465,17 +468,17 @@
 
     user = request.user
 
-    open_textbooks = taskapp_models.TextBook.objects.filter(status="OP").\
+    open_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[1][0]).\
                                       order_by("creation_datetime")
-    comp_textbooks = taskapp_models.TextBook.objects.filter(status="CM").\
+    comp_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[3][0]).\
                                       order_by("creation_datetime")
     context = {"user": user,
                "open_textbooks": open_textbooks,
                "comp_textbooks": comp_textbooks,
               }
 
-    if user.is_authenticated() and user.get_profile().rights in ["DC", "MG"]:
-        unpub_textbooks = taskapp_models.TextBook.objects.filter(status="UP")
+    if user.is_authenticated() and user.get_profile().role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]]:
+        unpub_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[0][0])
 
         context.update({"unpub_textbooks": unpub_textbooks})
 
@@ -491,7 +494,7 @@
     textbook_url = reverse(
       'view_textbook', kwargs={'task_id': textbook.id})
 
-    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
+    can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\
                        else False
 
     if not can_edit:
@@ -523,7 +526,7 @@
     claim_url = reverse('claim_task', kwargs={'task_id': task_id})
     task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id)
 
-    if task.status == "UP":
+    if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]:
         raise http.Http404
 
     user = request.user
@@ -543,7 +546,7 @@
     is_reviewer = True if user in reviewers else False
     has_claimed = True if user in claimed_users else False
 
-    task_claimable = True if task.status in ["OP", "WR"] else False
+    task_claimable = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False
     can_claim = True if task_claimable and ( not has_claimed )\
                         and ( not is_reviewer ) and (not is_creator ) \
                         else False
@@ -602,8 +605,8 @@
     
     is_creator = True if user == task.created_by else False
 
-    if ( is_creator or profile.rights in ["CR", "DC"] ) and \
-       task.status in ["OP", "WR"]:
+    if (is_creator or profile.role in [profile_models.ROLE_CHOICES[1][0], profile_models.ROLE_CHOICES[2][0]]) and \
+       task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]]:
 
         if task_claimed:
 
@@ -617,7 +620,7 @@
 
                     task.selected_users.add(selected_user)
                     task.claimed_users.remove(selected_user)
-                    task.status = "WR"
+                    task.status = taskapp_models.TASK_STATUS_CHOICES[3][0]
                     task.save()
 
                     return shortcuts.redirect(task_url)
@@ -642,7 +645,7 @@
 
     textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id)
 
-    if profile.rights not in ["MG", "DC"] or textbook.status != "UP":
+    if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]:
         raise http.Http404
 
     context = {"user": user,
@@ -660,12 +663,12 @@
 
     textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id)
 
-    if profile.rights not in ["MG", "DC"] or textbook.status != "UP":
+    if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]:
         raise http.Http404
 
     textbook.approved_by = user
     textbook.approval_datetime = datetime.now()
-    textbook.status = "OP"
+    textbook.status = taskapp_models.TB_STATUS_CHOICES[1][0]
     textbook.save()
 
     context = {"user": user,