diff options
author | nishanth | 2010-02-04 22:12:48 +0530 |
---|---|---|
committer | nishanth | 2010-02-04 22:12:48 +0530 |
commit | 6abcf4483cdfed7da478c626f48d22bee8448047 (patch) | |
tree | 505dc76ec291e7cf3c4e23add3ec1cca44f334c0 | |
parent | 3ed1f252c1d278fe306f533742d4016f5d3ba49e (diff) | |
download | pytask-6abcf4483cdfed7da478c626f48d22bee8448047.tar.gz pytask-6abcf4483cdfed7da478c626f48d22bee8448047.tar.bz2 pytask-6abcf4483cdfed7da478c626f48d22bee8448047.zip |
created forms, views, templates, actions for home_page, browse_task.
-rw-r--r-- | settings.py | 2 | ||||
-rw-r--r-- | taskapp/events/__init__.py | 0 | ||||
-rw-r--r-- | taskapp/events/user.py | 43 | ||||
-rw-r--r-- | taskapp/forms/__init__.py | 0 | ||||
-rw-r--r-- | taskapp/forms/task.py | 0 | ||||
-rw-r--r-- | taskapp/forms/user.py | 0 | ||||
-rw-r--r-- | taskapp/models.py | 10 | ||||
-rw-r--r-- | taskapp/views/tasks.py | 52 | ||||
-rw-r--r-- | taskapp/views/users.py | 40 | ||||
-rw-r--r-- | templates/base.html | 7 | ||||
-rw-r--r-- | templates/index.html | 22 | ||||
-rw-r--r-- | templates/task/browse.html | 7 | ||||
-rw-r--r-- | templates/task/create.html | 2 | ||||
-rw-r--r-- | templates/task/view.html | 28 | ||||
-rw-r--r-- | urls.py | 7 |
15 files changed, 215 insertions, 5 deletions
diff --git a/settings.py b/settings.py index 329f129..5ecaa27 100644 --- a/settings.py +++ b/settings.py @@ -81,4 +81,4 @@ INSTALLED_APPS = ( 'pytask.taskapp', ) -AUTH_PROFILE_MODULE = 'taskapp.models.Profile' +AUTH_PROFILE_MODULE = 'taskapp.Profile' 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) + diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..7ed337f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,7 @@ +<html> +<head> + <title>{% block title %}PyTasks{% endblock %}</title> +</head> +<body> +<h2><a href="/">PyTasks</a></h2><br />{% block content %}This is the default content{% endblock %}</body> +</html> diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..3154221 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} +{% block content %} + {% if is_guest %} + Welcome Guest<br> + <a href="/accounts/register/">Register</a> + <a href="/accounts/login/">Login</a><br /><br /> + Recent Tasks:<br /> + {% for task in task_list %} + <a href="/task/view/tid={{ task.id }}">{{ task.title }}</a><br /> + {% endfor %} + {% else %} + Welcome {{ user.username }} <br /> + <a href="/accounts/logout/">logout</a><br /> + <br /> + <a href="/task/browse/">Tasks</a><br /> + <a href="/user/browse/">Users</a><br /> + <a href="/user/view/uid={{user.id}}">My Profile</a><br /> + {% endif %} + {% if can_create_task %} + <a href="/task/create/">Create a task</a><br /> + {% endif %} +{% endblock %} diff --git a/templates/task/browse.html b/templates/task/browse.html new file mode 100644 index 0000000..cd0103d --- /dev/null +++ b/templates/task/browse.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% block content %} + List of all the tasks:<br /> + {% for task in task_list %} + <a href="/task/view/tid={{ task.id }}">{{ task.title }}</a><br /> + {% endfor %} +{% endblock %} diff --git a/templates/task/create.html b/templates/task/create.html new file mode 100644 index 0000000..5fddb17 --- /dev/null +++ b/templates/task/create.html @@ -0,0 +1,2 @@ +{% extends 'base.html' %} +{% endblock %} diff --git a/templates/task/view.html b/templates/task/view.html new file mode 100644 index 0000000..62393dd --- /dev/null +++ b/templates/task/view.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} +{% block title %} + {{task.title}} +{% endblock %} +{% block content %} + <a href="/task/browse/pg=1">Browse tasks</a> + <h3>{{ task.title }}</h3><br /> + <!-- we have to write our own datetime.strftime filter and use in the next line --> + created by <a href="/user/view/uid={{ task.created_by.id }}">{{ task.created_by.username }}</a> on {{ task.creation_datetime.ctime }}<br /> + <br />Description:<br /> + <br />{{ task.desc }}<br /> + {% if comments %} + <br/>comments:<br /> + {% for comment in comments %} + <br /><a href="/user/view/uid={{comment.created_by.id}}">{{ comment.created_by.username }}</a> at {{ comment.creation_datetime.ctime }} wrote:<br /> + {{ comment.data }}<br /> + {% endfor %} + {% endif %} + + {% if not is_guest %} + <br />Add comment:<br /> + <form action="" method="post"> + <!-- we might even want to use forms here --> + <textarea name="data"></textarea><br /> + <input type="submit" value="Submit"> + </form> + {% endif %} +{% endblock %} @@ -4,6 +4,9 @@ from django.conf.urls.defaults import * 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 @@ urlpatterns = patterns('', # 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)), ) |