summaryrefslogtreecommitdiff
path: root/taskapp
diff options
context:
space:
mode:
Diffstat (limited to 'taskapp')
-rw-r--r--taskapp/events/__init__.py0
-rw-r--r--taskapp/events/user.py43
-rw-r--r--taskapp/forms/__init__.py0
-rw-r--r--taskapp/forms/task.py0
-rw-r--r--taskapp/forms/user.py0
-rw-r--r--taskapp/models.py10
-rw-r--r--taskapp/views/tasks.py52
-rw-r--r--taskapp/views/users.py40
8 files changed, 141 insertions, 4 deletions
diff --git a/taskapp/events/__init__.py b/taskapp/events/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/taskapp/events/__init__.py
diff --git a/taskapp/events/user.py b/taskapp/events/user.py
new file mode 100644
index 0000000..9f7d934
--- /dev/null
+++ b/taskapp/events/user.py
@@ -0,0 +1,43 @@
+from django.contrib.auth.models import User
+from pytask.taskapp.models import Profile, Task, Comment, Credit
+
+""" 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'
+ """
+
+ 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,**properties):
+ """ create user using createUser method and set the is_superuser flag """
+
+ su_user = createUser(username,email,password,**properties)
+ su_user.is_staff = True
+ su_user.is_superuser = True
+ su_user.save()
diff --git a/taskapp/forms/__init__.py b/taskapp/forms/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/taskapp/forms/__init__.py
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/taskapp/forms/task.py
diff --git a/taskapp/forms/user.py b/taskapp/forms/user.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/taskapp/forms/user.py
diff --git a/taskapp/models.py b/taskapp/models.py
index 845a686..a23308e 100644
--- a/taskapp/models.py
+++ b/taskapp/models.py
@@ -24,12 +24,12 @@ UPLOADS_DIR = "./uploads"
class Profile(models.Model):
user = models.ForeignKey(User, unique = True)
- aboutme = models.TextField()
- dob = models.DateField()
+ dob = models.DateField(help_text = "YYYY-MM-DD")
gender = models.CharField(max_length = 1, choices = GENDER_CHOICES)
- rights = models.CharField(max_length = 2, choices = RIGHTS_CHOICES)
- credits = models.PositiveSmallIntegerField()
+ rights = models.CharField(max_length = 2, choices = RIGHTS_CHOICES, default = u"CT")
+ credits = models.PositiveSmallIntegerField(default = 0)
+ aboutme = models.TextField(blank = True)
foss_comm = models.CharField(max_length = 80, blank = True)
phonenum = models.CharField(max_length = 15, blank = True)
homepage = models.URLField(blank = True)
@@ -63,6 +63,8 @@ class Task(models.Model):
creation_datetime = models.DateTimeField()
+ #is_claimable = models.BooleanField()
+
## not yet decided if attribs after this are to be included
## tasktype = "" ## "bugfix"/"enhancement"
## priority = "" ## "very urgent"/"urgent"
diff --git a/taskapp/views/tasks.py b/taskapp/views/tasks.py
index e69de29..a8fec95 100644
--- a/taskapp/views/tasks.py
+++ b/taskapp/views/tasks.py
@@ -0,0 +1,52 @@
+from datetime import datetime
+
+from django.http import HttpResponse
+from django.shortcuts import render_to_response, redirect
+from pytask.taskapp.models import Task, Comment
+
+def browse_tasks(request):
+ """ display all the tasks """
+
+ user = request.user
+ task_list = Task.objects.order_by('id').reverse()
+
+ context = {'user':user,
+ 'task_list':task_list,
+ }
+ return render_to_response('task/browse.html', context)
+
+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 = request.user
+ task = Task.objects.get(id=tid)
+ comments = Comment.objects.filter(task=task)
+ errors = []
+
+ is_guest = True if not user.is_authenticated() else False
+ is_mentor = True if user in task.mentors.all() else False
+
+ context = {'user':user,
+ 'task':task,
+ 'comments':comments,
+ 'is_guest':is_guest,
+ 'is_mentor':is_mentor,
+ 'errors':errors,
+ }
+
+ if request.method == 'POST':
+ if not is_guest:
+ data = request.POST["data"]
+ task = Task.objects.get(id=tid)
+ 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)
diff --git a/taskapp/views/users.py b/taskapp/views/users.py
index 8b13789..d99adfb 100644
--- a/taskapp/views/users.py
+++ b/taskapp/views/users.py
@@ -1 +1,41 @@
+from django.http import HttpResponse
+from django.shortcuts import redirect, render_to_response
+from pytask.taskapp.models import Task
+
+def redirect_to_homepage(request):
+ """ simply redirect to homepage """
+
+ return redirect('/')
+
+def homepage(request):
+ """ check for authentication and display accordingly. """
+
+ user = request.user
+ is_guest = False
+ is_mentor = False
+ can_create_task = False
+ task_list = []
+
+ if not user.is_authenticated():
+ is_guest = True
+ disp_num = 10
+ tasks_count = Task.objects.count()
+ if tasks_count <= disp_num:
+ task_list = Task.objects.order_by('id').reverse()
+ else:
+ task_list = Task.objects.order_by('id').reverse()[:10]
+ else:
+ user_profile = user.get_profile()
+ is_mentor = True if user.task_mentors.all() else False
+ can_create_task = False if user_profile.rights == u"CT" else True
+
+ context = {'user':user,
+ 'is_guest':is_guest,
+ 'is_mentor':is_mentor,
+ 'task_list':task_list,
+ 'can_create_task':can_create_task,
+ }
+
+ return render_to_response('index.html', context)
+