# HG changeset patch # User nishanth # Date 1267180352 -19800 # Node ID 39ab7c460143f9632d9e0fb228f9e40eafa102f6 # Parent 5bbb29a07b87481d434181931a666d6ba49df2d7 did lots and now id field in task is a random key diff -r 5bbb29a07b87 -r 39ab7c460143 taskapp/events/task.py --- a/taskapp/events/task.py Fri Feb 26 15:15:16 2010 +0530 +++ b/taskapp/events/task.py Fri Feb 26 16:02:32 2010 +0530 @@ -1,6 +1,7 @@ from datetime import datetime from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map from pytask.taskapp.utilities.request import create_request +from pytask.taskapp.utilities.helper import get_key def publishTask(task, rem_mentors=True, rem_comments=True): """ set the task status to open """ @@ -95,18 +96,30 @@ task.mentors.add(mentor) task.save() - return task - + return task + + + def createTask(title,desc,created_by,credits): """ creates a bare minimum task with title, description and credits. the creator of the task will be assigned as a mentor 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.get(title__iexact=title) return None - except Task.DoesNotExist: + except: task = Task(title=title) + + task.id = id task.desc = desc task.created_by = created_by task.credits = credits diff -r 5bbb29a07b87 -r 39ab7c460143 taskapp/management/commands/seed_db.py --- a/taskapp/management/commands/seed_db.py Fri Feb 26 15:15:16 2010 +0530 +++ b/taskapp/management/commands/seed_db.py Fri Feb 26 16:02:32 2010 +0530 @@ -24,7 +24,7 @@ gender = "M" userEvents.createUser(username,email,password,dob,gender) - for i in range(1,21): + for i in range(1,6): title = "Task "+str(i) desc = "I am "+title diff -r 5bbb29a07b87 -r 39ab7c460143 taskapp/models.py --- a/taskapp/models.py Fri Feb 26 15:15:16 2010 +0530 +++ b/taskapp/models.py Fri Feb 26 16:02:32 2010 +0530 @@ -1,12 +1,14 @@ -import random -import string 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"), @@ -26,12 +28,6 @@ IMAGES_DIR = "./images" UPLOADS_DIR = "./uploads" -def get_key(): - """ generate a 10 character name with random alphabets and digits. - """ - - name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)]) - return name class CustomImageStorage(FileSystemStorage): @@ -60,7 +56,6 @@ credits = models.PositiveSmallIntegerField(default = 0) aboutme = models.TextField(blank = True) -# foss_comm = models.CharField(max_length = 80, blank = True, verbose_name = u"Foss Communities", help_text = u"Comma seperated list of foss communities you are involved in.") foss_comm = TagField() phonenum = models.CharField(max_length = 15, blank = True, verbose_name = u"Phone Number") homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog") @@ -76,10 +71,11 @@ 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, unique = True, 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 = models.CharField(max_length = 200, blank = True) tags_field = TagField() credits = models.PositiveSmallIntegerField() @@ -92,11 +88,6 @@ creation_datetime = models.DateTimeField() sub_type = models.CharField(max_length=1, choices = (('D','Dependency'),('S','Subtask')), default = 'D') - #is_claimable = models.BooleanField() - - ## not yet decided if attribs after this are to be included - ## tasktype = "" ## "bugfix"/"enhancement" - ## priority = "" ## "very urgent"/"urgent" def __unicode__(self): return unicode(self.title) @@ -145,12 +136,15 @@ 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) diff -r 5bbb29a07b87 -r 39ab7c460143 taskapp/utilities/helper.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskapp/utilities/helper.py Fri Feb 26 16:02:32 2010 +0530 @@ -0,0 +1,8 @@ +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)]) +