# HG changeset patch # User nishanth # Date 1265301768 -19800 # Node ID a93eebabfeb1fb520eda50168d67e474d409f15e # Parent 7c9fea7e28c8aed5634ea46fb9c5aa00c9921210 created forms, views, templates, actions for home_page, browse_task. diff -r 7c9fea7e28c8 -r a93eebabfeb1 settings.py --- a/settings.py Thu Feb 04 22:06:22 2010 +0530 +++ b/settings.py Thu Feb 04 22:12:48 2010 +0530 @@ -81,4 +81,4 @@ 'pytask.taskapp', ) -AUTH_PROFILE_MODULE = 'taskapp.models.Profile' +AUTH_PROFILE_MODULE = 'taskapp.Profile' diff -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/events/__init__.py diff -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/events/user.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskapp/events/user.py Thu Feb 04 22:12:48 2010 +0530 @@ -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 -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/forms/__init__.py diff -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/forms/task.py diff -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/forms/user.py diff -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/models.py --- a/taskapp/models.py Thu Feb 04 22:06:22 2010 +0530 +++ b/taskapp/models.py Thu Feb 04 22:12:48 2010 +0530 @@ -24,12 +24,12 @@ 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 @@ 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 -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/views/tasks.py --- a/taskapp/views/tasks.py Thu Feb 04 22:06:22 2010 +0530 +++ b/taskapp/views/tasks.py Thu Feb 04 22:12:48 2010 +0530 @@ -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 -r 7c9fea7e28c8 -r a93eebabfeb1 taskapp/views/users.py --- a/taskapp/views/users.py Thu Feb 04 22:06:22 2010 +0530 +++ b/taskapp/views/users.py Thu Feb 04 22:12:48 2010 +0530 @@ -1,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) + + diff -r 7c9fea7e28c8 -r a93eebabfeb1 templates/base.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/base.html Thu Feb 04 22:12:48 2010 +0530 @@ -0,0 +1,7 @@ + +
+