# HG changeset patch # User nishanth # Date 1264773446 -19800 # Node ID aea7e764c033284eb258ff29882922f318970ca1 # Parent a9c458c7782aba1547f0c6a015356c3849a369d1 created views and templates for homepage,browse_task and added actions. diff -r a9c458c7782a -r aea7e764c033 pytask/settings.py --- a/pytask/settings.py Thu Jan 28 21:39:35 2010 +0530 +++ b/pytask/settings.py Fri Jan 29 19:27:26 2010 +0530 @@ -81,4 +81,4 @@ 'pytask.taskapp', ) -AUTH_PROFILE_MODULE = 'taskapp.models.Profile' +AUTH_PROFILE_MODULE = 'taskapp.Profile' diff -r a9c458c7782a -r aea7e764c033 pytask/taskapp/events/__init__.py diff -r a9c458c7782a -r aea7e764c033 pytask/taskapp/events/user.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/taskapp/events/user.py Fri Jan 29 19:27:26 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 a9c458c7782a -r aea7e764c033 pytask/taskapp/forms/__init__.py diff -r a9c458c7782a -r aea7e764c033 pytask/taskapp/forms/task.py diff -r a9c458c7782a -r aea7e764c033 pytask/taskapp/forms/user.py diff -r a9c458c7782a -r aea7e764c033 pytask/taskapp/models.py --- a/pytask/taskapp/models.py Thu Jan 28 21:39:35 2010 +0530 +++ b/pytask/taskapp/models.py Fri Jan 29 19:27:26 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 a9c458c7782a -r aea7e764c033 pytask/taskapp/views/tasks.py --- a/pytask/taskapp/views/tasks.py Thu Jan 28 21:39:35 2010 +0530 +++ b/pytask/taskapp/views/tasks.py Fri Jan 29 19:27:26 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 a9c458c7782a -r aea7e764c033 pytask/taskapp/views/users.py --- a/pytask/taskapp/views/users.py Thu Jan 28 21:39:35 2010 +0530 +++ b/pytask/taskapp/views/users.py Fri Jan 29 19:27:26 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 a9c458c7782a -r aea7e764c033 pytask/templates/base.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/base.html Fri Jan 29 19:27:26 2010 +0530 @@ -0,0 +1,7 @@ + + + {% block title %}PyTasks{% endblock %} + + +

PyTasks


{% block content %}This is the default content{% endblock %} + diff -r a9c458c7782a -r aea7e764c033 pytask/templates/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/index.html Fri Jan 29 19:27:26 2010 +0530 @@ -0,0 +1,22 @@ +{% extends 'base.html' %} +{% block content %} + {% if is_guest %} + Welcome Guest
+ Register + Login

+ Recent Tasks:
+ {% for task in task_list %} + {{ task.title }}
+ {% endfor %} + {% else %} + Welcome {{ user.username }}
+ logout
+
+ Tasks
+ Users
+ My Profile
+ {% endif %} + {% if can_create_task %} + Create a task
+ {% endif %} +{% endblock %} diff -r a9c458c7782a -r aea7e764c033 pytask/templates/task/browse.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/browse.html Fri Jan 29 19:27:26 2010 +0530 @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% block content %} + List of all the tasks:
+ {% for task in task_list %} + {{ task.title }}
+ {% endfor %} +{% endblock %} diff -r a9c458c7782a -r aea7e764c033 pytask/templates/task/create.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/create.html Fri Jan 29 19:27:26 2010 +0530 @@ -0,0 +1,2 @@ +{% extends 'base.html' %} +{% endblock %} diff -r a9c458c7782a -r aea7e764c033 pytask/templates/task/view.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/view.html Fri Jan 29 19:27:26 2010 +0530 @@ -0,0 +1,28 @@ +{% extends 'base.html' %} +{% block title %} + {{task.title}} +{% endblock %} +{% block content %} + Browse tasks +

{{ task.title }}


+ + created by {{ task.created_by.username }} on {{ task.creation_datetime.ctime }}
+
Description:
+
{{ task.desc }}
+ {% if comments %} +
comments:
+ {% for comment in comments %} +
{{ comment.created_by.username }} at {{ comment.creation_datetime.ctime }} wrote:
+ {{ comment.data }}
+ {% endfor %} + {% endif %} + + {% if not is_guest %} +
Add comment:
+
+ +
+ +
+ {% endif %} +{% endblock %} diff -r a9c458c7782a -r aea7e764c033 pytask/urls.py --- a/pytask/urls.py Thu Jan 28 21:39:35 2010 +0530 +++ b/pytask/urls.py Fri Jan 29 19:27:26 2010 +0530 @@ -4,6 +4,9 @@ from django.contrib import admin admin.autodiscover() +from pytask.taskapp.views.users import redirect_to_homepage, homepage +from pytask.taskapp.views.tasks import browse_tasks, view_task + urlpatterns = patterns('', # Example: # (r'^pytask/', include('pytask.foo.urls')), @@ -12,6 +15,10 @@ # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + (r'^$', homepage), + (r'^task/browse/$', browse_tasks), + (r'^task/view/tid=(\d+)', view_task), + (r'^admin/', include(admin.site.urls)), )