summaryrefslogtreecommitdiff
path: root/taskapp
diff options
context:
space:
mode:
authorMadhusudan.C.S2011-01-14 00:59:09 +0530
committerMadhusudan.C.S2011-01-14 00:59:09 +0530
commitbb35c0a7546440247dad47f57d748259d0e9a744 (patch)
tree76f740c37954d23da88fcd2af856f74a5bc1e9e5 /taskapp
parent8b708b1b475caad85e12022db6d3d9af3387fbfe (diff)
downloadpytask-bb35c0a7546440247dad47f57d748259d0e9a744.tar.gz
pytask-bb35c0a7546440247dad47f57d748259d0e9a744.tar.bz2
pytask-bb35c0a7546440247dad47f57d748259d0e9a744.zip
Purging the repository for the new set of changes by Nishanth.
Diffstat (limited to 'taskapp')
-rw-r--r--taskapp/__init__.py0
-rw-r--r--taskapp/admin.py9
-rw-r--r--taskapp/events/__init__.py0
-rw-r--r--taskapp/events/request.py130
-rw-r--r--taskapp/events/task.py271
-rw-r--r--taskapp/events/user.py56
-rw-r--r--taskapp/forms/__init__.py0
-rw-r--r--taskapp/forms/task.py107
-rw-r--r--taskapp/forms/user.py65
-rw-r--r--taskapp/management/__init__.py1
-rw-r--r--taskapp/management/commands/__init__.py0
-rw-r--r--taskapp/management/commands/seed_db.py58
-rw-r--r--taskapp/models.py183
-rw-r--r--taskapp/tests.py23
-rw-r--r--taskapp/utilities/__init__.py0
-rw-r--r--taskapp/utilities/helper.py8
-rw-r--r--taskapp/utilities/notification.py300
-rw-r--r--taskapp/utilities/request.py62
-rw-r--r--taskapp/utilities/task.py37
-rw-r--r--taskapp/utilities/user.py17
-rw-r--r--taskapp/views/__init__.py1
-rw-r--r--taskapp/views/task.py726
-rw-r--r--taskapp/views/user.py347
23 files changed, 0 insertions, 2401 deletions
diff --git a/taskapp/__init__.py b/taskapp/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/taskapp/__init__.py
+++ /dev/null
diff --git a/taskapp/admin.py b/taskapp/admin.py
deleted file mode 100644
index d7d10d2..0000000
--- a/taskapp/admin.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from django.contrib import admin
-
-from pytask.taskapp.models import Profile, Task, Comment, Notification, Request
-
-admin.site.register(Profile)
-admin.site.register(Task)
-admin.site.register(Comment)
-admin.site.register(Notification)
-admin.site.register(Request)
diff --git a/taskapp/events/__init__.py b/taskapp/events/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/taskapp/events/__init__.py
+++ /dev/null
diff --git a/taskapp/events/request.py b/taskapp/events/request.py
deleted file mode 100644
index d69f717..0000000
--- a/taskapp/events/request.py
+++ /dev/null
@@ -1,130 +0,0 @@
-from datetime import datetime
-from pytask.taskapp.models import Profile
-from pytask.taskapp.events.task import addReviewer
-from pytask.taskapp.events.user import changeRole
-from pytask.taskapp.utilities.notification import create_notification
-
-def reply_to_request(request_obj, reply, replied_by):
- """
- makes a request replied with the given reply.
- arguments:
- request_obj - Request object for which change is intended
- reply - a boolean value to be given as reply (True/False)
- replied_by - the user object who replies to the request
- """
- if not request_obj.is_replied:
- request_obj.reply = reply
- request_obj.is_replied = True
- request_obj.reply_date = datetime.now()
- request_obj.replied_by = replied_by
- request_obj.save()
-
- if request_obj.role == "PY":
- ## note that we are not doing any check. we make requests invalid when an event like closing task happens.
- task = request_obj.task
- pynts = request_obj.pynts
- receiving_user = request_obj.receiving_user
- requested_by = request_obj.sent_by
- create_notification(request_obj.role, receiving_user, replied_by, reply, task, request_obj.remarks, requested_by, receiving_user, pynts)
- if receiving_user != requested_by:
- create_notification(request_obj.role, requested_by, replied_by, reply, task, request_obj.remarks, requested_by, receiving_user, pynts)
-
- elif request_obj.role == "MT":
- task = request_obj.task
- requested_by = request_obj.sent_by
- if reply:
- ## tell the replied user that he is reviewer for this task and give him learn more link
- create_notification("NT", request_obj.replied_by, task=task)
-
- ## now check if there are such similar requests and mark them as invalid
- ## they cannot be of type PY and so we can use the replied_by to get requests
- pending_requests = replied_by.request_sent_to.filter(is_valid=True, is_replied=False, role="MT",task=task)
- for req in pending_requests:
- create_notification("MT", req.sent_by, replied_by, False, task=req.task, remarks = "User has already accepted one such request and is a reviewer.", requested_by = req.sent_by)
- req.is_valid = False
- req.save()
-
- ## alert all the reviewers including who made request and all assigned users
- for a_reviewer in task.reviewers.all():
- create_notification(request_obj.role, a_reviewer, replied_by, True, task, request_obj.remarks, requested_by)
- for a_user in task.assigned_users.all():
- create_notification(request_obj.role, a_user, replied_by, True, task, request_obj.remarks, requested_by)
-
- addReviewer(task, request_obj.replied_by)
- else:
- ## tell the requested user that his request was rejected due to these reasons.
- create_notification(request_obj.role, requested_by, replied_by, False, task, request_obj.remarks, requested_by)
-
- elif request_obj.role == "DV":
- if reply:
- ## here we look for requests that are similar => requesting for DV and make them invalid
- ## also we drop a notification to user who made request
- pending_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False,role="DV")
- for req in pending_requests:
- req.is_valid = False
- req.save()
- create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \
- remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \
- requested_by = req.sent_by )
-
- ## tell only the user who made him a DV
- ## drop a welcome message to that fucker
- create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
- create_notification("ND", request_obj.replied_by, requested_by=request_obj.sent_by)
- changeRole(role=request_obj.role, user=request_obj.replied_by)
-
- else:
- create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
-
- elif request_obj.role == "MG":
- if reply:
- ## tell all the MG and AD
- alerting_users = Profile.objects.filter(user__is_active=True).exclude(rights="CT").exclude(rights="DV")
- for a_profile in alerting_users:
- create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
-
- ## here we look for requests that less or similar => requesting for DV or MG and make them invalid
- ## also we drop a notification to user who made request
- active_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False)
- pending_requests = active_requests.filter(role="DV") | active_requests.filter(role="MG")
- for req in pending_requests:
- req.is_valid = False
- req.save()
- create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \
- remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \
- requested_by = req.sent_by )
-
- ## drop a welcome message to that fucker
- create_notification("NG", request_obj.replied_by, requested_by=request_obj.sent_by)
- changeRole(role=request_obj.role, user=request_obj.replied_by)
-
- else:
- create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
-
- elif request_obj.role == "AD":
- if reply:
-
- ## here we look for requests that less or similar => requesting for DV or MG or AD and make them invalid
- ## also we drop a notification to user who made request
- active_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False)
- pending_requests = active_requests.filter(role="DV") | active_requests.filter(role="MG") | active_requests.filter(role="AD")
- for req in pending_requests:
- req.is_valid = False
- req.save()
- create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \
- remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \
- requested_by = req.sent_by )
- ## tell all the AD
- alerting_users = Profile.objects.filter(user__is_active=True).filter(rights="AD")
- for a_profile in alerting_users:
- create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
-
- ## drop a welcome message to that fucker
- create_notification("NA", request_obj.replied_by, requested_by=request_obj.sent_by)
- changeRole(role=request_obj.role, user=request_obj.replied_by)
-
- else:
- create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
-
- return True #Reply has been added successfully
- return False #Already replied
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
deleted file mode 100644
index 77ad361..0000000
--- a/taskapp/events/task.py
+++ /dev/null
@@ -1,271 +0,0 @@
-from datetime import datetime
-from pytask.taskapp.models import Profile, Task, Comment, Map
-from pytask.taskapp.utilities.task import getTask
-from pytask.taskapp.utilities.request import create_request
-from pytask.taskapp.utilities.helper import get_key
-from pytask.taskapp.utilities.notification import create_notification
-
-def publishTask(task, rem_reviewers=True, rem_comments=True):
- """ set the task status to open """
-
- # if task.sub_type == 'D':
- # deps, subs = task.map_subs.all(), []
- #else:
- # subs, deps = task.map_subs.all(), []
-
- task = getTask(task.id)
- if task.subs or any(map(lambda t:t.status!="CM",task.deps)):
- task.status = "LO"
- else:
- task.status = "OP"
-
- if rem_reviewers:
- task.reviewers.clear()
- task.reviewers.add(task.created_by)
-
- if rem_comments:
- task.comment_set.update(is_deleted=True)
- task.comment_set.update(deleted_by=task.created_by)
-
- task.published_datetime = datetime.now()
- task.save()
-
- pending_requests = task.request_task.filter(is_valid=True, is_replied=False)
- pending_requests.update(is_valid=False)
-
- return task
-
-def addSubTask(main_task, sub_task):
- """ add the task to subs attribute of the task and update its status.
- sub task can be added only if a task is in UP/OP/LO state.
- """
-
- ## Shall modify after talking to pr about subtasks
- ## I think i might even remove the concept of subtasks
-
- main_task.sub_type = "S"
- main_task.save()
-
- try:
- mapobj = Map.objects.get(main=main_task)
- except Map.DoesNotExist:
- mapobj = Map()
- mapobj.main = main_task
- mapobj.save()
- mapobj.subs.add(sub_task)
- mapobj.save()
-
- sub_tasks = getTask(main_task.id).subs
- if main_task.status == "OP":
- if any(map(lambda t:t.status!="CM",sub_tasks)):
- main_task.status = "LO"
- else:
- "CM"
- main_task.save()
-
-def addDep(main_task, dependency):
- """ add the dependency task to deps attribute of the task.
- update the status of main_task accordingly.
- note that deps can be added only if task is in UP/OP/LO state.
- And also if the task doesn't have any subs.
- """
-
- main_task.sub_type = "D"
- main_task.save()
-
- try:
- mapobj = Map.objects.get(main=main_task)
- except Map.DoesNotExist:
- mapobj = Map()
- mapobj.main = main_task
- mapobj.save()
-
- mapobj.subs.add(dependency)
- mapobj.save()
-
- deps = getTask(main_task.id).deps
-
- if main_task.status in ["OP", "LO"]:
- if all(map(lambda t:t.status=="CM",deps)):
- main_task.status = "OP"
- else:
- main_task.status = "LO"
-
- main_task.save()
-
-def reqReviewer(task, reviewer, req_by):
- """ create a request object with role as MT.
- """
-
- create_request(sent_by=req_by, role="MT", sent_to=reviewer, task=task)
-
-def addReviewer(task,reviewer):
- """ add the reviewer to reviewers list of the task """
-
- task.reviewers.add(reviewer)
- task.save()
- return task
-
-def createTask(title,desc,created_by,pynts):
- """ creates a bare minimum task with title, description and pynts.
- the creator of the task will be assigned as a reviewer for the task.
- """
-
- while True:
- id = get_key()
- try:
- task = Task.objects.get(id__iexact=id)
- continue
- except Task.DoesNotExist:
- break
-
- try:
- task = Task.objects.exclude(status="DL").get(title__iexact=title)
- return None
- except:
- task = Task(title=title)
-
- task.id = id
- task.desc = desc
- task.created_by = created_by
- task.pynts = pynts
- task.creation_datetime = datetime.now()
- task.published_datetime = datetime.now()
- task.save()
- return task
-
-def addClaim(task, message, user):
- """ add claim data to the database if it does not exist
- and also update the claimed users field of the task.
- """
-
- task.claimed_users.add(user)
- task.save()
-
- pending_reqs = user.request_sent_to.filter(is_replied=False, is_valid=True, role="MT", task=task).all()
- for req in pending_reqs:
- req.is_valid = False
- req.save()
- user_url = '<a href="/user/view/uid=%s">%s</a>'%(user.id, user.username)
- reason = "User has claimed the task and hence cannot be a reviewer and this request was made invalid."
- create_notification("MT", req.sent_by, user, task=task, reply=False, remarks=reason, requested_by=req.sent_by)
-
- for a_reviewer in task.reviewers.all():
- create_notification("CL", a_reviewer, user, task=task, remarks=message)
-
-def assignTask(task, added_user, assigned_by):
- """ check for the status of task and assign it to the particular user """
-
- if task.status in ['OP', 'WR']:
- task.assigned_users.add(added_user)
- task.claimed_users.remove(added_user)
- task.status = "WR"
- task.save()
-
- create_notification("AU", added_user, assigned_by, task=task)
-
-
-def updateTask(task, title=None, desc=None, pynts=None, tags_field=None):
- """ update the property accordingly.
- while updating title, check for uniqueness of title.
- return None if any error.
- """
-
- if title:
- try:
- task.title = title
- task.save()
- except Task.IntegrityError:
- return None
- if desc:task.desc = desc
- if pynts:task.pynts = pynts
- if tags_field:task.tags_field = tags_field
- task.save()
- return task
-
-def removeTask(main_task, sub_task):
- """ get the corresponding map object and remove the sub_task.
- """
-
- mapobj = Map.objects.get(main=main_task)
- mapobj.subs.remove(sub_task)
- mapobj.save()
-
-def removeUser(main_task, rem_user, removed_by, reason=None):
- """ right now, just remove the user from the list of assigned_users.
- """
-
- main_task.assigned_users.remove(rem_user)
- main_task.save()
-
- ## TODiscuss : when a user is kicked off, his pending requests for pynts is made invalid
- rem_user.request_receiving_user.filter(task=main_task,role="PY",is_valid=True,is_replied=False).update(is_valid=False)
-
- create_notification("RU", rem_user, removed_by, task=main_task, remarks=reason)
- ## TODO : create notification to the victim
-
-def assignPynts(task, given_by, given_to, points):
- """ make a proper request object.
- """
-
- create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points )
-
-def completeTask(task, marked_by):
- """ set the status of task as completed.
- We dont have to inform parent tasks.
- That part is taken care by getTask method.
- """
-
- task.status = "CM"
- task.save()
-
- pending_requests = task.request_task.filter(is_replied=False)
- pending_requests.update(is_valid=False)
-
- ## generate notification appropriately using marked_by
- ## we also have to mark unread requests as invalid
-
- for a_user in task.assigned_users.all():
- create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
-
- for a_user in task.claimed_users.all():
- create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
-
- for a_reviewer in task.reviewers.all():
- create_notification(role="CM", sent_to=a_reviewer, sent_from=marked_by, task=task)
-
-def closeTask(task, closed_by, reason=None):
- """ set the status of task as CD.
- generate notifications accordingly.
- """
-
- task.status = "CD"
- task.save()
-
- pending_requests = task.request_task.filter(is_replied=False)
- pending_requests.update(is_valid=False)
-
- ## generate notifications here
-
- for a_user in task.assigned_users.all():
- create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason)
-
- for a_user in task.claimed_users.all():
- create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason)
-
- for a_reviewer in task.reviewers.all():
- create_notification(role="CD", sent_to=a_reviewer, sent_from=closed_by, task=task, remarks=reason)
-
-def deleteTask(task, deleted_by, reason=None):
- """ set the task status as DL
- notify all its other viewers about the deleting of task.
- """
-
- task.status = "DL"
- task.save()
-
- pending_requests = task.request_task.filter(is_replied=False,is_valid=True)
- pending_requests.update(is_valid=False)
-
- for a_reviewer in task.reviewers.exclude(id=deleted_by.id):
- create_notification("DL", sent_to=a_reviewer, sent_from=deleted_by, task=task, remarks=reason)
diff --git a/taskapp/events/user.py b/taskapp/events/user.py
deleted file mode 100644
index 754cab0..0000000
--- a/taskapp/events/user.py
+++ /dev/null
@@ -1,56 +0,0 @@
-from django.contrib.auth.models import User
-from pytask.taskapp.models import Profile, Task, Comment
-
-""" A collection of helper methods. note that there is no validation done here.
-we take care of validation and others checks in methods that invoke these methods.
-"""
-
-def updateProfile(user_profile, properties):
- """ updates the given properties in the profile for a user.
- args:
- user_profile : a profile object
- properties : a dictionary with attributes to set as keys and corresponding values
- """
-
- for attr,value in properties.items():
- user_profile.__setattr__(attr,value)
- user_profile.save()
-
-def createUser(username,email,password,dob,gender):
- """ create a user and create a profile and update its properties
- args:
- username : a username that does not exist
- email : a valid email
- password : a password
- dob : a date object
- gender : u'M'/u'F'
- """
-
- try:
- user = User.objects.get(username=username)
- return user
- except:
- user = User(username=username, email=email)
- user.set_password(password)
- user.save()
- properties = {'dob':dob, 'gender':gender}
- user_profile = Profile(user=user)
- updateProfile(user_profile, properties)
- return user
-
-def createSuUser(username,email,password,dob,gender):
- """ create user using createUser method and set the is_superuser flag """
-
- su_user = createUser(username,email,password,dob,gender)
- su_user.is_staff = True
- su_user.is_superuser = True
- su_user.save()
- return su_user
-
-def changeRole(role, user):
- """ change the status of user to role.
- """
-
- user_profile = user.get_profile()
- user_profile.rights = role
- user_profile.save()
diff --git a/taskapp/forms/__init__.py b/taskapp/forms/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/taskapp/forms/__init__.py
+++ /dev/null
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
deleted file mode 100644
index ef294a2..0000000
--- a/taskapp/forms/task.py
+++ /dev/null
@@ -1,107 +0,0 @@
-from django import forms
-from pytask.taskapp.models import Task, WorkReport
-
-class TaskCreateForm(forms.ModelForm):
- class Meta:
- model = Task
- fields = ['title', 'desc', 'tags_field', 'pynts']
- #publish = forms.BooleanField(required=False)
-
- def clean_title(self):
- data = self.cleaned_data['title'].strip()
- try:
- Task.objects.exclude(status="DL").get(title__iexact=data)
- raise forms.ValidationError("Another task with same title exists")
- except Task.DoesNotExist:
- return data
-
- def clean_desc(self):
- data = self.cleaned_data['desc'].strip()
- if not data:
- raise forms.ValidationError("Enter some description for the task")
-
- return data
-
-class EditTaskForm(forms.ModelForm):
- class Meta:
- model = Task
- fields = ['title', 'desc', 'tags_field', 'pynts']
-
- def clean_desc(self):
- data = self.cleaned_data['desc'].strip()
- if not data:
- raise forms.ValidationError("Enter some description for the task")
-
- return data
-
- def clean_title(self):
- data = self.cleaned_data['title'].strip()
- try:
- prev_task = Task.objects.exclude(status="DL").get(title__iexact=data)
- if prev_task.id != self.instance.id:
- raise forms.ValidationError("Another task with same title exists")
- else:
- return data
- except Task.DoesNotExist:
- return data
-
-def AddReviewerForm(choices,instance=None):
- """ return a form object with appropriate choices """
-
- class myform(forms.Form):
- reviewer = forms.ChoiceField(choices=choices, required=True)
- form = myform(instance) if instance else myform()
- return form
-
-class ClaimTaskForm(forms.Form):
- message = forms.CharField(label="Proposal")
-
- def clean_message(self):
- data = self.cleaned_data['message'].strip()
- if not data:
- raise forms.ValidationError('Enter something as a proposal')
- return data
-
-
-def ChoiceForm(choices, instance=None):
- """ return a form object with appropriate choices """
-
- class myform(forms.Form):
- choice = forms.ChoiceField(choices=choices, required=True)
- form = myform(instance) if instance else myform()
- return form
-
-def AddTaskForm(task_choices, is_plain=False):
- """ if is_plain is true, it means the task has no subs/deps.
- so we also give a radio button to choose between subs and dependencies.
- else we only give choices.
- """
-
- class myForm(forms.Form):
- if is_plain:
- type_choices = [('S','Subtasks'),('D','Dependencies')]
- type = forms.ChoiceField(type_choices, widget=forms.RadioSelect)
-
- task = forms.ChoiceField(choices=task_choices)
- return myForm()
-
-def AssignPyntForm(choices, instance=None):
-
- class myForm(forms.Form):
- user = forms.ChoiceField(choices=choices, required=True)
- pynts = forms.IntegerField(min_value=0, required=True, help_text="Choose wisely since it cannot be undone.")
- return myForm(instance) if instance else myForm()
-
-def RemoveUserForm(choices, instance=None):
-
- class myForm(forms.Form):
- user = forms.ChoiceField(choices=choices, required=True)
- reason = forms.CharField(min_length=1, required=True)
- return myForm(instance) if instance else myForm()
-
-class WorkReportForm(forms.ModelForm):
-
- class Meta:
- model = WorkReport
- fields = ['remarks', 'attachment']
-
diff --git a/taskapp/forms/user.py b/taskapp/forms/user.py
deleted file mode 100644
index 4cde155..0000000
--- a/taskapp/forms/user.py
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/python2.5
-
-import os
-import PIL
-
-from pytask.taskapp.utilities.helper import get_key
-
-from django import forms
-from pytask.taskapp.models import GENDER_CHOICES, Profile
-from registration.forms import RegistrationFormUniqueEmail
-from registration.models import RegistrationProfile
-from pytask.taskapp.utilities.notification import create_notification
-
-class UserProfileEditForm(forms.ModelForm):
- """Form used to edit the profile of a user"""
-
- class Meta:
- model = Profile
- exclude = ('user','rights','dob','pynts')
-
- def clean_photo(self):
- uploaded_photo = self.data.get('photo', None)
- prev_photo = self.instance.photo
- if uploaded_photo:
- if uploaded_photo.size > 1048576:
- raise forms.ValidationError('Images only smaller than 1MB allowed')
- tmp_im_path = '/tmp/'+get_key()
- tmp_file = open(tmp_im_path, 'w')
- tmp_file.write(uploaded_photo.read())
- tmp_file.close()
- try:
- PIL.Image.open(tmp_im_path)
- except IOError:
- raise forms.ValidationError('Image format unknown')
- os.remove(tmp_im_path)
-
- if prev_photo: os.remove(prev_photo.path)
- return uploaded_photo
- else:
- return prev_photo
-
-
-class RegistrationFormCustom(RegistrationFormUniqueEmail):
- """Used instead of RegistrationForm used by default django-registration backend, this adds date of birth and gender to the default django-registration RegistrationForm"""
-
- dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth')
- gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender')
-
- def save(self,profile_callback=None):
- new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],password=self.cleaned_data['password1'],email=self.cleaned_data['email'])
-
- new_profile = Profile(user=new_user,dob=self.cleaned_data['dob'],gender=self.cleaned_data['gender'])
- new_profile.save()
-
- create_notification('NU',new_user)
-
- return new_user
-
-def UserChoiceForm(choices, instance=None):
- """ take a list of users and return a choice form.
- """
-
- class myForm(forms.Form):
- user = forms.ChoiceField(choices, required=True)
- return myForm(instance) if instance else myForm()
diff --git a/taskapp/management/__init__.py b/taskapp/management/__init__.py
deleted file mode 100644
index 8b13789..0000000
--- a/taskapp/management/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/taskapp/management/commands/__init__.py b/taskapp/management/commands/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/taskapp/management/commands/__init__.py
+++ /dev/null
diff --git a/taskapp/management/commands/seed_db.py b/taskapp/management/commands/seed_db.py
deleted file mode 100644
index 97263d5..0000000
--- a/taskapp/management/commands/seed_db.py
+++ /dev/null
@@ -1,58 +0,0 @@
-import sys
-from datetime import datetime
-from django.core.management.base import NoArgsCommand
-
-from django.contrib.auth.models import User
-
-from pytask.taskapp.events import task as taskEvents
-from pytask.taskapp.events import user as userEvents
-
-from pytask.taskapp.utilities.request import create_request
-from pytask.taskapp.utilities.notification import create_notification
-
-
-def seed_db():
- """ a method to seed the database with random data """
-
- defaultReviewer = userEvents.createSuUser("admin", "admin@example.com", "123456", datetime.now(), "M")
- reviewer_profile = defaultReviewer.get_profile()
- userEvents.updateProfile(reviewer_profile, {'rights':"AD"})
-
- for i in range(1,21):
-
- username = 'user'+str(i)
- email = username+'@example.com'
- password = '123456'
- dob = datetime.now()
- gender = "M"
- user = userEvents.createUser(username,email,password,dob,gender)
- create_notification("NU", user)
-
- if i%4==0:
- create_request(defaultReviewer, "MG", user)
- elif i%3==0:
- create_request(defaultReviewer, "DV", user)
- elif i%2==0:
- create_request(defaultReviewer, "AD", user)
- elif i in [7, 13]:
- user.is_active = False
- user.save()
-
- for i in range(1,21):
-
- title = "Task "+str(i)
- desc = "I am "+title
- created_by = defaultReviewer
- pynts = 20
-
- task = taskEvents.createTask(title,desc,created_by,pynts)
- if task:
- taskEvents.addReviewer(task, defaultReviewer)
- if i%2==0:taskEvents.publishTask(task)
-
-class Command(NoArgsCommand):
-
- def handle_noargs(self, **options):
- """ Just copied the code from seed_db.py """
-
- seed_db()
diff --git a/taskapp/models.py b/taskapp/models.py
deleted file mode 100644
index 7900645..0000000
--- a/taskapp/models.py
+++ /dev/null
@@ -1,183 +0,0 @@
-import os
-
-from django.core.files.storage import FileSystemStorage
-from django.db import models
-from django.contrib.auth.models import User
-
-import tagging
-from tagging.fields import TagField
-
-from pytask.taskapp.utilities.helper import get_key
-
-GENDER_CHOICES = (( 'M', 'Male'), ('F', 'Female'))
-RIGHTS_CHOICES = (
- ("AD", "Admin"),
- ("MG", "Manager"),
- ("DV", "Developer"),
- ("CT", "Contributor"),)
-
-STATUS_CHOICES = (
- ("UP", "Unpublished"),
- ("OP", "Open"),
- ("LO", "Locked"),
- ("WR", "Working"),
- ("CD", "Closed"),
- ("DL", "Deleted"),
- ("CM", "Completed"))
-
-NOTIFY_CHOICES = (
- ("MT", "Add Reviewer"),
- ("DV", "Developer"),
- ("MG", "Manager"),
- ("AD", "Admin"),
- ("PY", "Assign pynts"),
- ("CM", "Task completed"),
- ("CD", "Task closed"),
- ("DL", "Task deleted"),
- ("NU", "New User"),
- ("NT", "New Reviewer"),
- ("ND", "New Developer"),
- ("NG", "New Manager"),
- ("NA", "New Admin"),
- ("AU", "Assign user"), ## i mean assign the task
- ("RU", "Remove user"), ## remove from working users list in task
-)
-
-IMAGES_DIR = "./images"
-UPLOADS_DIR = "./uploads"
-
-class CustomImageStorage(FileSystemStorage):
-
- def path(self, name):
- """ we return images directory path.
- """
-
- return os.path.join(IMAGES_DIR, name)
-
- def get_available_name(self, name):
- """ here we are going with username as the name of image.
- """
-
- root, ext = os.path.splitext(name)
- file_name = get_key() + ext
- while self.exists(file_name):
- file_name = get_key() + ext
- return file_name
-
-class Profile(models.Model):
-
- user = models.ForeignKey(User, unique = True)
- dob = models.DateField(verbose_name = u"Date of Birth", help_text = "YYYY-MM-DD")
- gender = models.CharField(max_length = 1, choices = GENDER_CHOICES)
- rights = models.CharField(max_length = 2, choices = RIGHTS_CHOICES, default = u"CT")
- pynts = models.PositiveSmallIntegerField(default = 0)
-
- aboutme = models.TextField(blank = True)
- foss_comm = TagField(verbose_name="FOSS Communities")
- phonenum = models.CharField(max_length = 15, blank = True, verbose_name = u"Phone Number")
- homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog")
- street = models.CharField(max_length = 80, blank = True)
- city = models.CharField(max_length = 25, blank = True)
- country = models.CharField(max_length = 25, blank = True)
- nick = models.CharField(max_length = 20, blank = True)
- photo = models.ImageField(storage = CustomImageStorage(),upload_to = IMAGES_DIR, blank = True)
-
- def __unicode__(self):
- return unicode(self.user.username)
-
-class Task(models.Model):
-
- prim_key = models.AutoField(primary_key = True)
- id = models.CharField(max_length = 10, unique = True)
- title = models.CharField(max_length = 100, verbose_name = u"Title", help_text = u"Keep it simple and below 100 chars.")
- desc = models.TextField(verbose_name = u"Description")
- status = models.CharField(max_length = 2, choices = STATUS_CHOICES, default = "UP")
- tags_field = TagField(verbose_name = u"Tags", help_text = u"Give comma seperated tags")
-
- pynts = models.PositiveSmallIntegerField(help_text = u"No.of pynts a user gets on completing the task")
- progress = models.PositiveSmallIntegerField(default = 0)
-
- reviewers = models.ManyToManyField(User, related_name = "%(class)s_reviewers")
- created_by = models.ForeignKey(User, related_name = "%(class)s_created_by")
- claimed_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_claimed_users")
- assigned_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_assigned_users")
-
- creation_datetime = models.DateTimeField()
- published_datetime = models.DateTimeField()
- sub_type = models.CharField(max_length=1, choices = (('D','Dependency'),('S','Subtask')), default = 'D')
-
- def __unicode__(self):
- return unicode(self.title)
-
-class Map(models.Model):
-
- main = models.ForeignKey('Task', related_name = "%(class)s_main")
- subs = models.ManyToManyField('Task', blank = True, null = True, related_name = "%(class)s_subs")
-
-class Comment(models.Model):
-
- task = models.ForeignKey('Task')
- data = models.TextField()
- created_by = models.ForeignKey(User, related_name = "%(class)s_created_by")
- creation_datetime = models.DateTimeField()
- deleted_by = models.ForeignKey(User, null = True, blank = True, related_name = "%(class)s_deleted_by")
- is_deleted = models.BooleanField()
- attachment = models.FileField(upload_to = UPLOADS_DIR, blank = True)
-
- def __unicode__(self):
- return unicode(self.task.title)
-
-class Request(models.Model):
-
- sent_to = models.ManyToManyField(User, related_name = "%(class)s_sent_to", blank = False)
- sent_by = models.ForeignKey(User, related_name = "%(class)s_sent_by", blank = False)
- role = models.CharField(max_length = 2, blank = False)
- reply = models.BooleanField(default = False, blank = False)
- remarks = models.TextField(default = "",blank = True)
-
- is_read = models.BooleanField(default = False, blank = False)
- is_valid = models.BooleanField(default = True, blank = False)
-
- creation_date = models.DateTimeField()
- reply_date = models.DateTimeField()
- is_replied = models.BooleanField(default = False)
- replied_by = models.ForeignKey(User, related_name = "%(class)s_replied_by", blank = True, null = True)
-
- task = models.ForeignKey(Task,related_name = "%(class)s_task", blank = True, null = True)
- receiving_user = models.ForeignKey(User, related_name = "%(class)s_receiving_user", blank = True, null = True)
- pynts = models.PositiveIntegerField(default=0)
-
- def __unicode__(self):
-
- return u"Request %s %s"%(self.sent_by.username, self.role)
-
-class Notification(models.Model):
-
- role = models.CharField(max_length = 2, choices = NOTIFY_CHOICES, blank = False)
- sent_to = models.ForeignKey(User, related_name = "%(class)s_sent_to", blank = False)
- sent_from = models.ForeignKey(User, related_name = "%(class)s_sent_from", null = True, blank = True)
- task = models.ForeignKey(Task, related_name = "%(class)s_task", null = True, blank = True)
-
- sub = models.CharField(max_length = 100)
- message = models.TextField()
- remarks = models.CharField(max_length = 100)
-
- sent_date = models.DateTimeField()
- is_read = models.BooleanField(default = False)
- is_deleted = models.BooleanField(default = False)
-
- def __unicode__(self):
- return u"%s %s %s"%(self.sent_to, self.message, self.sent_date.ctime())
-
-class WorkReport(models.Model):
-
- attachment = models.FileField(upload_to=IMAGES_DIR)
- remarks = models.TextField()
- revision = models.PositiveIntegerField(default=0)
- task = models.ForeignKey(Task, related_name = "%(class)s_report")
- submitted_by = models.ForeignKey(User, related_name = "%(class)s_submitted_by")
-
- created_at = models.DateTimeField()
-
-#tagging.register(Profile)
-#tagging.register(Task)
diff --git a/taskapp/tests.py b/taskapp/tests.py
deleted file mode 100644
index 2247054..0000000
--- a/taskapp/tests.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""
-This file demonstrates two different styles of tests (one doctest and one
-unittest). These will both pass when you run "manage.py test".
-
-Replace these with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-class SimpleTest(TestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.failUnlessEqual(1 + 1, 2)
-
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
-
->>> 1 + 1 == 2
-True
-"""}
-
diff --git a/taskapp/utilities/__init__.py b/taskapp/utilities/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/taskapp/utilities/__init__.py
+++ /dev/null
diff --git a/taskapp/utilities/helper.py b/taskapp/utilities/helper.py
deleted file mode 100644
index ebd7213..0000000
--- a/taskapp/utilities/helper.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import string,random
-
-def get_key():
- """ return a 10 character random key.
- """
-
- return ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])
-
diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py
deleted file mode 100644
index 4d67c11..0000000
--- a/taskapp/utilities/notification.py
+++ /dev/null
@@ -1,300 +0,0 @@
-from datetime import datetime
-from django.contrib.auth.models import User
-from pytask.taskapp.models import Notification, RIGHTS_CHOICES
-
-def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None):
- """
- creates a notification based on the passed arguments.
- role: role of the notification - look at choices in models
- sent_to: a user to which the notification is to be sent
- sent_from : a user from which the message has originated
- A user who approves/rejects in case of request
- A reviewer who closes/complets the task
- reply: A boolean
- task: a task if applicable
- requested_by: a user makes the request
- A reviewer who assigns pynts in case of pynts
- A reviewer who requests to act as a reviewer
- remarks: any remarks for rejecting
- receiving_user: user receiving pynts
- pynts: the obvious
- """
-
- notification = Notification(sent_date = datetime.now())
- notification.role = role
- notification.sent_to = sent_to
- notification.save()
-
- if role == "PY":
-
- notification.sent_from = sent_from
- notification.task = task
- notification.pynts = pynts
-
- task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
- pynts_url = '<a href="/task/assignpynts/tid=%s">%s</a>'%(task.id, "click here")
- reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
- admin_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
- user_url = '<a href="/user/view/uid=%s">%s</a>'%(receiving_user.id, receiving_user.username)
-
- if reply:
- notification.sub = "Approved request for assign of pynts for %s"%task.title[:20]
- notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been approved by %s<br />
- %s if you want the view/assign pynts page of the task.<br />"""%(reviewer_url, pynts, user_url, task_url, admin_url, pynts_url)
-
- else:
- notification.sub = "Rejected request for assign of pynts for %s"%task.title[:20]
- notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been rejected by %s.<br /> """%(reviewer_url, pynts, user_url, task_url, admin_url)
- if remarks:
- notification.remarks = remarks
- notification.message += "Reason: %s<br />"%remarks
- notification.message += "<br />"
-
- elif role == "MT":
-
- notification.task = task
- notification.sent_from = sent_from
-
- task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
- requested_reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
- new_reviewer = sent_from
- new_reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(new_reviewer.id, new_reviewer.username)
-
- if reply:
- notification.sub = "New reviewer for the task %s"%task.title[:20]
- notification.message = "%s has accepted the request made by %s, asking him act as a reviewer for the task %s<br />"%(new_reviewer_url, requested_reviewer_url, task_url)
- notification.message += "He can be contacted on %s"%new_reviewer.email
-
- else:
- notification.sub = "%s rejected request to act as a reviewer"%new_reviewer.username
- notification.message = "%s has rejected your request asking him to act as a reviewer for %s.<br />"%(new_reviewer_url, task_url)
- if remarks:
- notification.remarks = remarks
- notification.message += "Remarks: %s<br />"%remarks
-
- elif role in ["DV", "MG", "AD"]:
-
- notification.sent_from = sent_from
- accepting_user = sent_from
- user_url = '<a href="/user/view/uid=%s">%s</a>'%(accepting_user.id, accepting_user.username) ## i mean the user who has accepted it
- requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
- role_rights = dict(RIGHTS_CHOICES)[role]
- role_learn_url = "/about/%s"%role_rights.lower()
- a_or_an = "an" if role_rights == "AD" else "a"
-
- if reply:
- notification.sub = "New %s for the site"%role_rights
- notification.message = "%s has accepted request made by %s asking him to act as %s %s for the website.<br />"%(user_url, requested_by_url, a_or_an, role_rights)
- else:
- notification.sub = "Rejected your request to act as %s"%role_rights
- notification.message = "%s has rejected your request asking him to act as %s %s.<br />"%(user_url, a_or_an, role_rights)
- if remarks:
- notification.remarks = remarks
- notification.message += "Remarks: %s<br />"%remarks
-
- elif role == "NT":
-
- notification.task = task
- new_reviewer = sent_to
- reviewer_learn_url = '<sup><a href="/about/reviewer/">learn more</a></sup>'
- task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
-
- notification.sub = "You are reviewering the task %s"%task.title[:20]
- notification.message = "You have accepted to act as a reviewer%s for the task %s.<br />"%(reviewer_learn_url, task_url)
- notification.message += " Here is a list of other reviewers and their email addresses.<br /> <ul>"
-
- for a_reviewer in task.reviewers.exclude(id=new_reviewer.id):
- notification.message += "<li> %s - %s </li>"%(a_reviewer.username, a_reviewer.email)
- notification.message += "</ul>"
-
- working_users = task.assigned_users.all()
- if working_users:
- notification.message += "List of users working on the task.<br />"
- notification.message += "<ul>"
- for a_user in working_users:
- notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
- notification.message += "</ul><br />"
- notification.message += "Happy Reviewering."
-
- elif role == "NU":
-
- start_here_url = '<a href="/about/starthere/" taget="_blank">click here</a>'
- notification.sub = "Welcome %s"%sent_to.username
- notification.message = "Welcome to PyTasks %s.<br />"%sent_to.username
- notification.message += "%s to know more."%start_here_url
-
- elif role in ["ND", "NG", "NA"]:
-
- rights_dict = dict(RIGHTS_CHOICES)
-
- if role == "ND":
- role_rights = rights_dict["DV"]
- elif role == "NG":
- role_rights = rights_dict["MG"]
- elif role == "NA":
- role_rights = rights_dict["AD"]
-
- requested_by_url = r'<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
- role_learn_url = r'<a href="/about/%s" target="_blank">click here</a>'%role_rights.lower()
- a_or_an = "an" if role_rights == "Admin" else "a"
-
- notification.sub = "You are now %s %s"%(a_or_an, role_rights)
- notification.message = r"You have accepted the request made by %s asking you to act as %s %s in the site "%(requested_by_url, a_or_an, role_rights)
- notification.message += "and you are now %s %s in the site.<br /> %s to learn more on %s."%(a_or_an, role_rights, role_learn_url, role_rights)
-
-
- elif role in ["CM", "CD"]:
-
- notification.sent_from = sent_from
- notification.role = role
- notification.task = task
- notification.remarks = remarks
-
- reviewer = sent_from
- reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username)
- task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
-
- if role == "CM":
- notification.sub = "%s has been marked complete"%task.title
- notification.message = "The task %s has been marked complete by %s.<br />"%(task_url, reviewer_url)
-
- elif role == "CD":
- notification.sub = "%s has been closed"%task.title
- notification.message = "The task %s has been closed by %s.<br />"%(task_url, reviewer_url)
-
- if remarks:
- notification.remarks = remarks
- notification.message += "<b>Remarks:</b> %s"%remarks
-
- elif role == "AU":
-
- notification.task = task
- notification.sent_from = sent_from
- added_user = sent_to
- reviewer = sent_from
- assigned_by_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username)
- task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
-
- notification.sub = "Your claim for the task %s accepted."%task.title[:20]
- notification.message = "You have been selected to work on the task %s by %s.<br />"%(task_url, assigned_by_url)
- notification.message += "You can now start working on the task and will be pynted by the reviewers for your work.<br />"
-
- notification.message += " Here is a list of reviewers for the task and their email addresses.<br /> <ul>"
- for a_reviewer in task.reviewers.all():
- notification.message += "<li> %s - %s </li>"%(a_reviewer.username, a_reviewer.email)
- notification.message += "</ul>"
-
- working_users = task.assigned_users.exclude(id=added_user.id)
- if working_users:
- notification.message += "List of other users working on the task.<br />"
- notification.message += "<ul>"
- for a_user in working_users:
- notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
- notification.message += "</ul><br />"
-
- elif role == "RU":
-
- notification.task = task
- notification.sent_from = sent_from
- removed_user = sent_to
- reviewer = sent_from
- removed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username)
- task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
- claim_url = '<a href="/task/claim/tid=%s">%s</a>'%(task.id, "clicking here")
-
- notification.sub = "You have been removed from working users of %s"%task.title[:20]
- notification.message = "%s has removed you from the working users list of %s.<br />"%(removed_by_url, task_url)
- notification.message += "if you want to work on the task again, you can claim the task by %s.<br />"%claim_url
- if remarks:
- notification.remarks = remarks
- notification.message += "<b>Reason: </b>%s"%(remarks)
-
- elif role == "DL":
-
- notification.sent_from = sent_from
- notification.task = task
- deleted_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
-
- notification.sub = "Task deleted"
- notification.message = 'The unpublished task "%s" viewable by you has been deleted by its creator %s.<br />'%(task.title, deleted_by_url)
-
- if remarks:
- notification.remarks = remarks
- notification.message += "<b>Reason: </b>%s"%remarks
-
- elif role == "CL":
-
- notification.sent_from = sent_from
- notification.task = task
- notification.remarks = remarks
-
- claimed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
- claim_url = '<a href="/task/claim/tid=%s">claim</a>'%(task.id)
- task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
-
- notification.sub = 'New claim for the task "%s"'%(task.title[:20])
- notification.message = '%s has submitted a %s for the task "%s" reviewered by you.<br />'%(claimed_by_url, claim_url, task_url)
- notification.message += '<b>Claim proposal:</b> %s'%(remarks)
-
-
-
- notification.save()
-
-def mark_notification_read(notification_id):
- """
- makes a notification identified by the notification_id read.
- arguments:
- notification_id - a number denoting the id of the Notification object
- """
- try:
- notification = Notification.objects.get(id = notification_id)
- except Notification.DoesNotExist:
- return False
- notification.is_read = True
- notification.save()
- return True
-
-def delete_notification(notification_id):
- """
- deletes a notification identified by the notification_id.
- arguments:
- notification_id - a number denoting the id of the Notification object
- """
- try:
- notification = Notification.objects.get(id = notification_id)
- except Notification.DoesNotExist:
- return False
- notification.is_deleted = True
- notification.save()
- return True
-
-def get_notification(nid, user):
- """ if notification exists, and belongs to the current user, return it.
- else return None.
- """
-
- user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date')
- current_notifications = user_notifications.filter(id=nid)
- if user_notifications:
- current_notification = current_notifications[0]
-
- try:
- newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False)
- newest_notification = user_notifications.reverse()[0]
- if newest_notification == newer_notification:
- newest_notification = None
- except Notification.DoesNotExist:
- newest_notification, newer_notification = None, None
-
- try:
- older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False)
- oldest_notification = user_notifications[0]
- if oldest_notification == older_notification:
- oldest_notification = None
- except:
- oldest_notification, older_notification = None, None
-
- return newest_notification, newer_notification, current_notification, older_notification, oldest_notification
-
- else:
- return None, None, None, None, None
diff --git a/taskapp/utilities/request.py b/taskapp/utilities/request.py
deleted file mode 100644
index 9a61291..0000000
--- a/taskapp/utilities/request.py
+++ /dev/null
@@ -1,62 +0,0 @@
-from datetime import datetime
-
-from django.contrib.auth.models import User
-from pytask.taskapp.models import Request, Profile
-
-def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0):
- """
- creates an unreplied request, based on the passed arguments
- sent_to - a list of users to which the request is to be sent
- sent_by - sender of request
- role - a two character field which represents the role requested, if role = 'PY' then sent to all admins
- task - a requesting task (useful for sending admins a request to give Pynts to the user)
- receiving_user - user to whom the Pynts is assigned to(useful for sending admins a request to give Pynts to the user)
- pynts - the pynts assigned to the receiving user
- """
- req = Request(creation_date=datetime.now())
- req.sent_by = sent_by
- req.reply_date = datetime(1970,01,01)
- req.role = role
- req.pynts = pynts
- if task:
- req.task = task
- req.save()
- if role == 'PY':
- admin_profiles = Profile.objects.filter(rights='AD')
- for admin_profile in admin_profiles:
- req.sent_to.add(admin_profile.user)
- req.receiving_user = receiving_user
- else:
- req.sent_to.add(sent_to)
- req.save()
-
-def get_request(rid, user):
- """ see if the request is replied or if he can not view the request,
- raise 404 error. else return request.
- """
-
- active_requests = user.request_sent_to.filter(is_valid=True, is_replied=False).order_by('creation_date')
- current_requests = active_requests.filter(id=rid)
- if current_requests:
- current_request = current_requests[0]
-
- try:
- newer_request = current_request.get_next_by_creation_date(sent_to=user, is_replied=False, is_valid=True)
- newest_request = active_requests.reverse()[0]
- if newer_request == newest_request:
- newest_request = None
- except Request.DoesNotExist:
- newer_request, newest_request = None, None
-
- try:
- older_request = current_request.get_previous_by_creation_date(sent_to=user, is_replied=False, is_valid=True)
- oldest_request = active_requests[0]
- if oldest_request == older_request:
- oldest_request = None
- except Request.DoesNotExist:
- older_request, oldest_request = None, None
-
- return newest_request, newer_request, current_request, older_request, oldest_request
-
- else:
- return None, None, None, None, None
diff --git a/taskapp/utilities/task.py b/taskapp/utilities/task.py
deleted file mode 100644
index 3a7ebdf..0000000
--- a/taskapp/utilities/task.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from django.http import Http404
-from pytask.taskapp.models import Task, Map
-
-def getTask(tid):
- """ retreive the task from database.
- if the task has deps or subs, update its status correspondingly.
- """
-
- try:
- task = Task.objects.get(id=tid)
- except Task.DoesNotExist:
- raise Http404
- try:
- mapobj = Map.objects.get(main=task)
- except Map.DoesNotExist:
- mapobj = Map()
- mapobj.main = task
- mapobj.save()
-
- task_subs = mapobj.subs.all()
-
- if task.sub_type == "D":
- task.deps, task.subs = task_subs, []
- elif task.sub_type == "S":
- task.subs, task.deps = task_subs, []
-
- deps, subs = task.deps, task.subs
- if deps and task.status in ["OP", "LO"]:
- task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO"
-
- ## a task with subs will remain in "LO" and will be made "OP" only if all subs are removed.
- if subs and task.status in ["OP", "LO"]:
- task.status = "LO"
-
- task.save()
- return task
-
diff --git a/taskapp/utilities/user.py b/taskapp/utilities/user.py
deleted file mode 100644
index 12ac9fb..0000000
--- a/taskapp/utilities/user.py
+++ /dev/null
@@ -1,17 +0,0 @@
-"""
-A collection of utility functions for user.
-"""
-
-def get_user(user):
- """ get the no of unread requests and notifications and add them as properties for user.
- """
-
- unread_notifications = user.notification_sent_to.filter(is_read=False,is_deleted=False)
- unread_requests = user.request_sent_to.filter(is_valid=True,is_replied=False,is_read=False)
-
- user.unread_notifications = unread_notifications
- user.unread_requests = unread_requests
-
- return user
-
-
diff --git a/taskapp/views/__init__.py b/taskapp/views/__init__.py
deleted file mode 100644
index 8b13789..0000000
--- a/taskapp/views/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
deleted file mode 100644
index ec5046e..0000000
--- a/taskapp/views/task.py
+++ /dev/null
@@ -1,726 +0,0 @@
-from datetime import datetime
-
-from django.http import HttpResponse, Http404
-from django.shortcuts import render_to_response, redirect
-
-from pytask.taskapp.models import User, Task, Comment, Request, Notification, WorkReport
-from pytask.taskapp.utilities.task import getTask
-from pytask.taskapp.forms.task import TaskCreateForm, AddReviewerForm, AddTaskForm, ChoiceForm, AssignPyntForm, RemoveUserForm, EditTaskForm, ClaimTaskForm, WorkReportForm
-from pytask.taskapp.events.task import createTask, reqReviewer, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignPynts, completeTask, closeTask, addReviewer, deleteTask
-from pytask.taskapp.views.user import show_msg
-from pytask.taskapp.utilities.user import get_user
-
-## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add reviewer and all
-## do not create su user thro syncdb
-
-def browse_tasks(request):
- """ display all the tasks """
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
-
- task_list = task_list.exclude(tags_field__icontains="textbook")
-
- context = {'user':user,
- 'task_list':task_list,
- }
- return render_to_response('task/browse.html', context)
-
-def show_textbooks(request):
- """ display all the tasks """
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
-
- task_list = task_list.filter(tags_field__icontains="textbook")
-
- context = {'user':user,
- 'task_list':task_list,
- }
- return render_to_response('task/browse.html', context)
-
-def upload_work(request, tid):
- """ Check if the work is in WR state and the user is in assigned_users.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- if not task.status == "WR":
- return show_msg(user, "The task is not in a stage to upload content", task_url, "view the task")
-
- can_upload = True if user in task.assigned_users.all() else False
-
- old_reports = task.workreport_report.all()
-
- context = {
- 'user': user,
- 'task': task,
- 'old_reports': old_reports,
- 'can_upload': can_upload,
- }
-
- if request.method == "POST":
- if not can_upload:
- return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task")
-
- form = WorkReportForm(request.POST, request.FILES)
-
- if form.is_valid():
- r = WorkReport(attachment = form.cleaned_data['attachment'],
- remarks = form.cleaned_data['remarks'],
- revision = old_reports.count(),
- task = task,
- submitted_by = user,
- created_at = datetime.now(),
- )
-
- r.save()
- return redirect(task_url)
-
- else:
- context.update({"form":form})
- return render_to_response('task/report.html', context)
-
- else:
- form = WorkReportForm()
- context.update({"form":form})
- return render_to_response('task/report.html', context)
-
-
-def publish_task(request, tid):
- """ check if user is the reviewer and also if the task status is UP.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
-
- if user == task.created_by:
- context = {
- 'user':user,
- }
- if task.status == "UP":
- if request.method == "POST":
- publishTask(task)
- return show_msg(user, "The task has been published", task_url, "view the task")
- else:
- return render_to_response('task/publish.html', context)
- else:
- return show_msg(user, "The task is already published", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to do this", '/task/browse/', "browse tasks")
-
-def view_task(request, tid):
- """ get the task depending on its tid and display accordingly if it is a get.
- check for authentication and add a comment if it is a post request.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- if task.status == "DL":
- return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
- comments = task.comment_set.filter(is_deleted=False).order_by('creation_datetime')
- reviewers = task.reviewers.all()
-
- deps, subs = task.deps, task.subs
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
- context = {'user':user,
- 'task':task,
- 'comments':comments,
- 'reviewers':reviewers,
- 'subs':subs,
- 'deps':deps,
- 'is_guest':is_guest,
- 'is_reviewer':is_reviewer,
- }
-
- claimed_users = task.claimed_users.all()
-
-
- is_requested_reviewer = True if user.is_authenticated() and user.request_sent_to.filter(is_valid=True,is_replied=False,role="MT",task=task) else False
- task_viewable = True if ( task.status != "UP" ) or is_reviewer or is_requested_reviewer else False
- if not task_viewable:
- return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks")
-
- context['is_requested_reviewer'] = is_requested_reviewer
-
- context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
- context['can_edit'] = True if task.status == "UP" and is_reviewer 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 user == task.created_by else False
-
- context['can_mod_reviewers'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_reviewer else False
- context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_reviewer 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"] and not is_guest else False
-
- if task.status == "CD":
- context['closing_notification'] = Notification.objects.filter(task=task,role="CD")[0]
- elif task.status == "CM":
- context['completed_notification'] = Notifications.objects.filter(task=task,role="CM")[0]
- elif task.status == "WR":
- context['assigned_users'] = task.assigned_users.all()
-
- if request.method == 'POST':
- if not is_guest:
- data = request.POST.get("data", "").strip()
- if not data:
- context['error_msg'] = "Enter some message to comment"
- return render_to_response('task/view.html', context)
- new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now())
- new_comment.save()
- return redirect(task_url)
- else:
- errors.append("You must be logged in to post a comment")
- return render_to_response('task/view.html', context)
- else:
- return render_to_response('task/view.html', context)
-
-def create_task(request):
- """ check for rights and create a task if applicable.
- if user cannot create a task, redirect to homepage.
- """
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- is_guest = True if not user.is_authenticated() else False
-
- if not is_guest:
- user_profile = user.get_profile()
- can_create_task = False if user_profile.rights == "CT" else True
- if can_create_task:
- if request.method == "POST":
- form = TaskCreateForm(request.POST)
- if form.is_valid():
- data = form.cleaned_data
- title = data['title']
- desc = data['desc']
- pynts = data['pynts']
- #publish = data['publish'] # just in case if we have to show the option
- task = createTask(title,desc,user,pynts)
-
- addReviewer(task, user)
- updateTask(task,tags_field=data['tags_field'])
- # if publish: publishTask(task)
- task_url = '/task/view/tid=%s'%task.id
- return redirect(task_url)
- else:
- return render_to_response('task/create.html',{'user':user, 'form':form})
- else:
- form = TaskCreateForm()
- return render_to_response('task/create.html',{'user':user, 'form':form})
- else:
- return show_msg(user, 'You are not authorised to create a task.')
- else:
- return show_msg(user, 'You are not authorised to create a task.', "/", "home page")
-
-def add_reviewer(request, tid):
- """ check if the current user has the rights to edit the task and add him.
- if user is not authenticated, redirect him to concerned page. """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
- errors = []
-
- is_guest = True if not user.is_authenticated() else False
-
- if (not is_guest) and user in task.reviewers.all():
-
- pending_requests = Request.objects.filter(is_replied=False,is_valid=True,role="MT",task=task).order_by('creation_date').reverse()
- user_pending_requests = pending_requests.filter(sent_by=user)
-
- ## now iam going for a brute force method
- user_list = list(User.objects.filter(is_active=True))
- for reviewer in task.reviewers.all():
- user_list.remove(reviewer)
-
- for a_user in task.claimed_users.all():
- user_list.remove(a_user)
-
- for a_user in task.assigned_users.all():
- user_list.remove(a_user)
-
- for req in user_pending_requests:
- user_list.remove(req.sent_to.all()[0])
-
- non_reviewers = ((_.id, _.username) for _ in user_list)
- non_reviewer_ids = [ str(a_user.id) for a_user in user_list ]
- ## code till must be made elegant and not brute force like above
-
- form = AddReviewerForm(non_reviewers)
-
- context = {
- 'user':user,
- 'task':task,
- 'pending_requests':pending_requests,
- 'form':form,
- }
-
- if request.method == "POST":
- data = request.POST
- uid = data.get('reviewer', None)
- if uid in non_reviewer_ids:
- new_reviewer = User.objects.get(id=int(uid))
- reqReviewer(task, new_reviewer, user)
- return redirect('/task/addreviewer/tid=%s'%task.id)
- else:
- ## bogus post request
- raise Http404
- else:
- return render_to_response('task/addreviewer.html', context)
- else:
- return show_msg(user, 'You are not authorised to add reviewers for this task', task_url, 'view the task')
-
-def add_tasks(request, tid):
- """ first display tasks which can be subtasks for the task and do the rest.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- deps, subs = task.deps, task.subs
- is_plain = False if deps or subs else True
-
- ## again a brute force method
- valid_tasks = []
- for a_task in Task.objects.all():
- if not ( a_task in deps or a_task in subs or a_task.status=="CD" or a_task==task ):
- valid_tasks.append(a_task)
-
- task_choices = [ (_.id,_.title) for _ in valid_tasks ]
- errors = []
-
- is_guest = True if not user.is_authenticated() else False
-
- if (not is_guest) and user in task.reviewers.all():
- if task.status in ["UP", "OP", "LO"]:
- form = AddTaskForm(task_choices, is_plain)
- if request.method == "POST":
- ## first decide if adding subs and deps can be in same page
- ## only exclude tasks with status deleted
- data = request.POST
- if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.')
- if not data.get('task', None): errors.append('Please choose a one task')
-
- if not errors:
- if is_plain:
- update_method = addDep if data['type'] == "D" else addSubTask
- elif deps:
- update_method = addDep
- elif subs:
- update_method = addSubTask
- else:
- print "Screw you"
-
- ## we might iterate over a task list later on
- task_id = data['task']
- sub_or_dep = getTask(task_id)
- update_method(task, sub_or_dep)
-
- return redirect(task_url)
- else:
- return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
- else:
- return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
- else:
- errors = ["The task cannot be added subtasks or dependencies in this state"]
-# return render_to_response('task/add.html', {'form':form, 'errors':errors})
- return show_msg(user, 'The task cannot be added subtasks or dependencies now', task_url, 'view the task')
- else:
- return show_msg(user, 'You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
-
-def remove_task(request, tid):
- """ display a list of tasks and remove the selectes ones.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- if (not is_guest) and user in task.reviewers.all():
-
- if task.status in ["UP", "LO", "OP"]:
-
- deps, subs = task.deps, task.subs
- task_list = deps if task.sub_type == "D" else subs
-
- if task_list:
- choices = [(_.id,_.title) for _ in task_list ]
- form = ChoiceForm(choices)
-
- errors = []
-
- context = {
- 'user':user,
- 'task':task,
- 'form':form,
- }
-
- if request.method == "POST":
- data = request.POST
- if not data.get('choice', None):
- errors.append("Please choose a task to remove.")
- context['errors'] = errors
- if not errors:
- tid = data['choice']
- sub_task = getTask(tid)
- removeTask(task, sub_task)
- return redirect(task_url)
- else:
- return render_to_response('task/removetask.html', context)
- else:
- return render_to_response('task/removetask.html', context)
- else:
- return show_msg(user, "The task has no subtasks/dependencies to be removed", task_url, "view the task")
- else:
- return show_msg(user, "subtasks/dependencies cannot be removed at this stage", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to do this", task_url, "view the task")
-
-def claim_task(request, tid):
- """ display a list of claims for get and display submit only if claimable """
-
- ## create claims model and create a new database with required tables for it
- ## see if that "one to n" or "n to one" relationship has a special field
-
- task_url = "/task/view/tid=%s"%tid
- claim_url = "/task/claim/tid=%s"%tid
-
- errors = []
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- #claims = task.notifications_task.filter(role="CL",sent_to=task.created_by)
- # this is what the next line should be when i re sync the db
- claims = Notification.objects.filter(task=task, sent_to=task.created_by, role="CL")
-
- reviewers = task.reviewers.all()
- claimed_users = task.claimed_users.all()
- assigned_users = task.assigned_users.all()
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in reviewers else False
-
- task_claimable = True if task.status in ["OP", "WR"] else False
- user_can_claim = True if task_claimable and not ( is_guest or is_reviewer ) and ( user not in claimed_users ) and ( user not in assigned_users ) else False
- task_claimed = True if claimed_users else False
-
- context = {'user':user,
- 'is_reviewer':is_reviewer,
- 'task':task,
- 'claims':claims,
- 'user_can_claim':user_can_claim,
- 'task_claimable':task_claimable,
- 'task_claimed':task_claimed,
- 'errors':errors}
-
- if not is_guest:
- form = ClaimTaskForm()
- context['form'] = form
- if request.method == "POST":
- form = ClaimTaskForm(request.POST)
- context['form'] = form
- if form.is_valid():
- claim_proposal = form.cleaned_data['message']
- addClaim(task, claim_proposal, user)
- return redirect(claim_url)
- else:
- return render_to_response('task/claim.html', context)
- else:
- return render_to_response('task/claim.html', context)
- else:
- return show_msg(user, 'You are not logged in to view claims for this task', task_url, 'view the task')
-
-def rem_user(request, tid):
- """ show a list of working users and ask for a message/reason for removing user.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
-
- if (not is_guest) and is_reviewer:
-
- assigned_users = task.assigned_users.all()
- choices = [ (_.id,_.username) for _ in assigned_users ]
- context = {
- 'user':user,
- 'task':task,
- }
-
- if task.status in ["WR"]:
- if assigned_users:
- form = RemoveUserForm(choices)
- context['form'] = form
- if request.method == "POST":
- data = request.POST
- form = RemoveUserForm(choices, data)
- if form.is_valid():
- data = form.cleaned_data
- uid = data['user']
- reason = data['reason']
- rem_user = User.objects.get(id=uid)
- removeUser(task, rem_user, user, reason)
- return redirect(task_url)
- else:
- context['form'] = form
- return render_to_response('task/remove_user.html', context)
- else:
- return render_to_response('task/remove_user.html',context)
- else:
- return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
- else:
- return show_msg(user, "This is not the stage to remove users", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to do this", task_url, "view the task")
-
-def assign_task(request, tid):
- """ first get the status of the task and then assign it to one of claimed users
- generate list of claimed users by passing it as an argument to a function.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
-
- claimed_users = task.claimed_users.all()
- assigned_users = task.assigned_users.all()
-
- task_claimed = True if claimed_users else False
-
- if (not is_guest) and is_reviewer:
- if task.status in ["OP", "WR"]:
- if task_claimed:
- user_list = ((user.id,user.username) for user in claimed_users)
- form = ChoiceForm(user_list)
-
- if request.method == "POST":
- uid = request.POST['choice']
- assigned_user = User.objects.get(id=uid)
- assignTask(task, assigned_user, user)
- return redirect(task_url)
- else:
- return render_to_response('task/assign.html',{'user':user, 'task':task,'form':form})
- elif assigned_users:
- return show_msg(user, 'When the no of users you need for the task is more than the no of users willing to do the task, I\'d say please re consider the task :P',task_url, 'view the task')
- else:
- return show_msg(user, 'Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task')
- else:
- return show_msg(user, "The task cannot be assigned to users at this stage", task_url, 'view the task')
- else:
- return show_msg(user, 'You are not authorised to perform this action', task_url, 'view the task')
-
-def assign_pynts(request, tid):
- """ Check if the user is a reviewer and pynts can be assigned.
- Then display all the approved pynts.
- Then see if reviewer can assign pynts to users also or only reviewers.
- Then put up a form for reviewer to assign pynts accordingly.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- ## the moment we see that user had requested pynts, it means he had worked and hence we change the status to WR
- ## we have to discuss on this since, pynts may also be given to reviewer
- task.status = "WR"
- task.save()
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if (not is_guest) and user in task.reviewers.all() else False
-
- if is_reviewer:
- if task.status in ["OP", "WR"]:
- choices = [(_.id,_.username) for _ in task.reviewers.all()]
- if task.status == "WR":
- choices.extend([(_.id, _.username) for _ in task.assigned_users.all() ])
- prev_pynts = task.request_task.filter(role="PY",is_valid=True,is_replied=True,reply=True).count()
- pynt_requests = task.request_task.filter(role="PY",is_valid=True).order_by('creation_date').reverse()
- form = AssignPyntForm(choices)
-
- context = {
- 'user':user,
- 'task':task,
- 'prev_pynts':prev_pynts,
- 'pynt_requests':pynt_requests,
- 'form':form,
- }
-
- if request.method == "POST":
- data = request.POST
- form = AssignPyntForm(choices, data)
- if form.is_valid():
- data = form.cleaned_data
- uid = data['user']
- points = data['pynts']
- given_to = User.objects.get(id=uid)
- assignPynts(task=task, given_by=user, given_to=given_to, points=points)
- return redirect('/task/assignpynts/tid=%s'%task.id)
- else:
- context['form'] = form
- return render_to_response('task/assignpynts.html', context)
- else:
- return render_to_response('task/assignpynts.html', context)
- else:
- return show_msg(user, "Pynts cannot be assigned at this stage", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to perform this action", task_url, "view the task")
-
-def edit_task(request, tid):
- """ see what are the attributes that can be edited depending on the current status
- and then give the user fields accordingly.
- """
-
- task = getTask(tid)
-
- task_url = "/task/view/tid=%s"%tid
- user = get_user(request.user) if request.user.is_authenticated() else request.user
-
- is_reviewer = True if user in task.reviewers.all() else False
- can_edit = True if is_reviewer and task.status == "UP" else False
-
- if can_edit:
- form = EditTaskForm(instance=task)
- if request.method=="POST":
- data = request.POST
- form = EditTaskForm(data, instance=task)
- if form.is_valid():
- form.save()
- return redirect(task_url)
- else:
- return render_to_response('task/edittask.html',{'user':user, 'form':form})
- else:
- return render_to_response('task/edittask.html',{'user':user, 'form':form})
- else:
- return show_msg(user, "You cannot edit the task at this stage", task_url, "view the task")
-
-def complete_task(request, tid):
- """ call the event called complete task.
- and also pass it the current user to know who marked it as complete.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
-
- claimed_users = task.claimed_users.all()
- assigned_users = task.assigned_users.all()
-
- assign_pynts_url = '/task/assignpynts/tid=%s'%task.id
- task_assigned_pynts = task.pynt_set.all()
-
-
- if is_reviewer:
- if task.status in ["OP", "WR"]:
-
- context = {
- 'user':user,
- 'task':task,
- }
-
- if task_assigned_pynts:
- if request.method=="POST":
- completeTask(task, user)
- return redirect(task_url)
- else:
- return render_to_response('task/complete.html', context)
- else:
- return show_msg(user, "Nobody has been pynted for doing this task.", assign_pynts_url, "assign pynts")
- else:
- return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to do this", task_url, "view the task")
-
-def close_task(request, tid):
- """ task can be closed only if task is published.
- call the event close task if everything is fine.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- user = get_user(request.user) if request.user.is_authenticated() else request.user
- task = getTask(tid)
-
- is_guest = True if not user.is_authenticated() else False
- is_reviewer = True if user in task.reviewers.all() else False
-
- if is_reviewer:
-
- context = {
- 'user':user,
- 'task':task,
- }
-
- if not task.status in ["UP", "CD", "DL", "CM"]:
- if request.method == "POST":
- data = request.POST
- if not data.get("reason", None):
- context["error"] = "Please enter a reason for closing the task"
- return render_to_response('task/close.html', context)
- else:
- closeTask(task, user, data['reason'])
- return show_msg(user, "The task has been closed.", task_url, "view the task.")
- else:
- return render_to_response('task/close.html', context)
- else:
- return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task")
- else:
- return show_msg(user, "You are not authorised to do this", task_url, "view the task")
-
-def delete_task(request, tid):
- """ mark the task status as DL.
- take a reason from the user and pass on to all the other reviewers.
- """
-
- task_url = "/task/view/tid=%s"%tid
-
- task = getTask(tid)
- user = get_user(request.user) if request.user.is_authenticated() else request.user
-
- if task.status == "DL":
- return show_msg(user, "This task no longer exists", '/task/browse/', "to browse other tasks")
-
- can_delete = True if task.status == "UP" and task.created_by == user else False
-
- if can_delete:
- if request.method == "POST":
- data = request.POST
- reason = data.get('reason', None)
- deleteTask(task, user, reason)
- return show_msg(user, "The task is deleted", '/', "to return to home page")
- else:
- return render_to_response('task/delete.html',{'user':user,})
- else:
- return show_msg(user, "You are not authorised to do this at this stage", task_url, "view the task")
diff --git a/taskapp/views/user.py b/taskapp/views/user.py
deleted file mode 100644
index 153e9dd..0000000
--- a/taskapp/views/user.py
+++ /dev/null
@@ -1,347 +0,0 @@
-import os
-
-from django.http import HttpResponse, Http404
-from django.shortcuts import redirect, render_to_response
-from django.contrib.auth.models import User
-from django.contrib.auth.decorators import login_required
-
-from pytask.taskapp.models import Task, Profile, Request
-
-from pytask.taskapp.events.user import createUser
-from pytask.taskapp.events.request import reply_to_request
-
-from pytask.taskapp.forms.user import UserProfileEditForm, UserChoiceForm
-
-from pytask.taskapp.utilities.request import get_request, create_request
-from pytask.taskapp.utilities.notification import get_notification, create_notification
-from pytask.taskapp.utilities.user import get_user
-
-about = {
- "addreviewers": "about/addreviewers.html",
- "reviewer": "about/reviewer.html",
- "starthere": "about/starthere.html",
- "task": "about/task.html",
- "tasklife": "about/tasklife.html",
- "developer": "about/developer.html",
- "notification": "about/notification.html",
- "request": "about/request.html",
- "manager": "about/manager.html",
- "admin": "about/admin.html",
-}
-
-def show_msg(user, message, redirect_url=None, url_desc=None):
- """ simply redirect to homepage """
-
- return render_to_response('show_msg.html',{'user':user, 'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc})
-
-def homepage(request):
- """ check for authentication and display accordingly. """
-
- user = request.user
- is_guest = False
- is_reviewer = False
- can_create_task = False
- task_list = []
-
- if not user.is_authenticated():
- is_guest = True
- disp_num = 10
- task_list = Task.objects.exclude(status="UP").exclude(status="CD").exclude(status="CM").order_by('published_datetime').reverse()[:10]
- return render_to_response('index.html', {'user':user, 'is_guest':is_guest, 'task_list':task_list})
-
- else:
- user = get_user(request.user)
- user_profile = user.get_profile()
- is_reviewer = True if user.task_reviewers.all() else False
- can_create_task = False if user_profile.rights == u"CT" else True
-
- context = {'user':user,
- 'is_guest':is_guest,
- 'is_reviewer':is_reviewer,
- 'task_list':task_list,
- 'can_create_task':can_create_task,
- }
-
- context["unpublished_tasks"] = user.task_reviewers.filter(status="UP")
- context["reviewered_tasks"] = user.task_reviewers.exclude(status="UP").exclude(status="CM").exclude(status="CD").exclude(status="DL")
- context["claimed_tasks"] = user.task_claimed_users.exclude(status="UP").exclude(status="CM").exclude(status="CD").exclude(status="DL")
- context["working_tasks"] = user.task_assigned_users.filter(status="WR")
-
- return render_to_response('index.html', context)
-
-@login_required
-def learn_more(request, what):
- """ depending on what was asked for, we render different pages.
- """
-
- user = get_user(request.user)
- disp_template = about.get(what, None)
- if not disp_template:
- raise Http404
- else:
- return render_to_response(disp_template, {'user':user})
-
-@login_required
-def view_my_profile(request,uid=None):
- """ allows the user to view the profiles of users """
- user = get_user(request.user)
- request_user_profile = request.user.get_profile()
- request_user_privilege = True if request_user_profile.rights in ['AD','MG'] else False
- if uid == None:
- edit_profile = True
- profile = Profile.objects.get(user = request.user)
- return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user, 'privilege':request_user_privilege})
- edit_profile = True if request.user == User.objects.get(pk=uid) else False
- try:
- profile = Profile.objects.get(user = User.objects.get(pk=uid))
- except Profile.DoesNotExist:
- raise Http404
- return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user, 'privilege':request_user_privilege})
-
-@login_required
-def edit_my_profile(request):
- """ enables the user to edit his/her user profile """
-
- user = get_user(request.user)
- user_profile = user.get_profile()
-
- edit_profile_form = UserProfileEditForm(instance = user_profile)
- if request.method == 'POST':
-
- data = request.POST.copy()
- uploaded_photo = request.FILES.get('photo', None)
- data.__setitem__('photo', uploaded_photo)
-
- edit_profile_form = UserProfileEditForm(data, instance=user_profile)
- if edit_profile_form.is_valid():
- edit_profile_form.save()
- return redirect('/user/view/uid='+str(user.id))
- else:
- return render_to_response('user/edit_profile.html',{'user':user, 'edit_profile_form' : edit_profile_form})
- else:
- profile = user.get_profile()
- edit_profile_form = UserProfileEditForm(instance = profile)
- return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form, 'user':user})
-
-@login_required
-def browse_requests(request):
-
- user = get_user(request.user)
- active_reqs = user.request_sent_to.filter(is_replied=False).exclude(is_valid=False)
- reqs = active_reqs.order_by('creation_date').reverse()
-
- context = {
- 'user':user,
- 'reqs':reqs,
- }
-
- return render_to_response('user/browse_requests.html', context)
-
-@login_required
-def view_request(request, rid):
- """ please note that request variable in this method is that of django.
- our app request is called user_request.
- """
-
- user = get_user(request.user)
- user_rights = user.get_profile().rights
- newest, newer, user_request, older, oldest = get_request(rid, user)
- if not user_request:
- raise Http404
-
- user_request.is_read = True
- user_request.save()
-
- context = {
- 'user':user,
- 'req':user_request,
- 'sent_users':user_request.sent_to.all(),
- 'newest':newest,
- 'newer':newer,
- 'older':older,
- 'oldest':oldest,
- }
-
- return render_to_response('user/view_request.html', context)
-
-@login_required
-def process_request(request, rid, reply):
- """ check if the method is post and then update the request.
- if it is get, display a 404 error.
- """
-
- user = get_user(request.user)
- browse_request_url= '/user/requests'
- newest, newer, req_obj, older, oldest = get_request(rid, user)
-
- if not req_obj:
- return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests")
-
- if request.method=="POST":
- reply = True if reply == "yes" else False
- req_obj.remarks = request.POST.get('remarks', "")
- req_obj.save()
-
- reply_to_request(req_obj, reply, user)
-
- return redirect('/user/requests/')
- return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests")
- else:
- return show_msg(user, "You are not authorised to do this", browse_request_url, "view other requests")
-
-@login_required
-def browse_notifications(request):
- """ get the list of notifications that are not deleted and display in datetime order.
- """
-
- user = get_user(request.user)
-
- active_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date').reverse()
-
- context = {
- 'user':user,
- 'notifications':active_notifications,
- }
-
- return render_to_response('user/browse_notifications.html', context)
-
-@login_required
-def view_notification(request, nid):
- """ get the notification depending on nid.
- Display it.
- """
-
- user = get_user(request.user)
- newest, newer, notification, older, oldest = get_notification(nid, user)
- if not notification:
- raise Http404
-
- notification.is_read = True
- notification.save()
-
- context = {
- 'user':user,
- 'notification':notification,
- 'newest':newest,
- 'newer':newer,
- 'older':older,
- 'oldest':oldest,
- }
-
- return render_to_response('user/view_notification.html', context)
-
-@login_required
-def edit_notification(request, nid, action):
- """ if action is delete, set is_deleted.
- if it is unread, unset is_read.
- save the notification and redirect to browse_notifications.
- """
-
- user = get_user(request.user)
- newest, newer, notification, older, oldest = get_notification(nid, user)
-
- if not notification:
- raise Http404
-
- notifications_url = "/user/notifications/"
-
- if request.method == "POST":
- if action == "delete":
- notification.is_deleted = True
- elif action == "unread":
- notification.is_read = False
-
- notification.save()
- if older:
- return redirect('/user/notifications/nid=%s'%older.id)
- else:
- return redirect(notifications_url)
- else:
- return show_msg(user, 'This is wrong', notification_url, "view the notification")
-
-@login_required
-def change_rights(request, role):
- """ check if the current user has privileges to do this.
- """
-
- user = get_user(request.user)
- role = role.upper()
- user_profile = user.get_profile()
- user_rights = user_profile.rights
-
- user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["MG", "DV"] ) else False
-
- if user_can_view:
- if role == "DV":
- current_contributors = list(User.objects.filter(is_active=True,profile__rights="CT"))
- pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
- pending_dv_requests = pending_requests.filter(role="DV")
-
- ## one cannot make same request many times
- for req in pending_dv_requests:
- current_contributors.remove(req.sent_to.all()[0])
-
- choices = [ (_.id,_.username ) for _ in current_contributors ]
-
- elif role == "MG":
- active_users = User.objects.filter(is_active=True)
- dv_ct_users = list(active_users.filter(profile__rights="CT") | active_users.filter(profile__rights="DV"))
- pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
- pending_mg_requests = pending_requests.filter(role="MG")
-
- ## same logic here. you cannot make another request exactly the same.
- ## but iam still not decided whether someone who requests a user to be admin,
- ## can be given a chance to request the same user to be a manager or developer
- for req in pending_mg_requests:
- dv_ct_users.remove(req.sent_to.all()[0])
-
- choices = [ (_.id, _.username ) for _ in dv_ct_users ]
-
- elif role == "AD":
- active_users = User.objects.filter(is_active=True)
- non_ad_users = list(active_users.exclude(profile__rights="AD"))
- pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True)
- pending_ad_requests = pending_requests.filter(role="AD")
-
- ## we filter out users who have already been requested by the user to be an admin
- for req in pending_ad_requests:
- non_ad_users.remove(req.sent_to.all()[0])
-
- choices = [ (_.id,_.username ) for _ in non_ad_users ]
-
- form = UserChoiceForm(choices)
-
- context = {
- 'user':user,
- 'form':form,
- }
-
- if request.method=="POST":
- data = request.POST
- form = UserChoiceForm(choices, data)
- if form.is_valid():
- user_to_change = User.objects.get(id=form.cleaned_data['user'])
- create_request(sent_by=user, role=role, sent_to=user_to_change)
- return show_msg(user, "A request has been sent", "/", "return to home page")
- else:
- raise Http404
- else:
- return render_to_response('user/changerole.html', context)
- else:
- raise Http404
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-