taskapp/models.py
changeset 119 39ab7c460143
parent 118 5bbb29a07b87
child 123 a6b4234388c8
equal deleted inserted replaced
118:5bbb29a07b87 119:39ab7c460143
     1 import random
       
     2 import string
       
     3 import os
     1 import os
       
     2 
     4 from django.core.files.storage import FileSystemStorage
     3 from django.core.files.storage import FileSystemStorage
     5 from django.db import models
     4 from django.db import models
     6 from django.contrib.auth.models import User
     5 from django.contrib.auth.models import User
       
     6 
     7 import tagging
     7 import tagging
     8 from tagging.fields import TagField
     8 from tagging.fields import TagField
       
     9 
       
    10 from pytask.taskapp.utilities.helper import get_key
     9 
    11 
    10 GENDER_CHOICES = (( 'M', 'Male'), ('F', 'Female'))
    12 GENDER_CHOICES = (( 'M', 'Male'), ('F', 'Female'))
    11 RIGHTS_CHOICES = (
    13 RIGHTS_CHOICES = (
    12 	("AD", "Admin"),
    14 	("AD", "Admin"),
    13 	("MG", "Manager"),
    15 	("MG", "Manager"),
    24     ("CM", "Completed"))
    26     ("CM", "Completed"))
    25 
    27 
    26 IMAGES_DIR = "./images"
    28 IMAGES_DIR = "./images"
    27 UPLOADS_DIR = "./uploads"
    29 UPLOADS_DIR = "./uploads"
    28 
    30 
    29 def get_key():
       
    30     """ generate a 10 character name with random alphabets and digits.
       
    31     """
       
    32 
       
    33     name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])
       
    34     return name
       
    35 
    31 
    36 class CustomImageStorage(FileSystemStorage):
    32 class CustomImageStorage(FileSystemStorage):
    37 
    33 
    38     def path(self, name):
    34     def path(self, name):
    39         """ we return images directory path.
    35         """ we return images directory path.
    58     gender = models.CharField(max_length = 1, choices = GENDER_CHOICES)
    54     gender = models.CharField(max_length = 1, choices = GENDER_CHOICES)
    59     rights = models.CharField(max_length = 2, choices = RIGHTS_CHOICES, default = u"CT")
    55     rights = models.CharField(max_length = 2, choices = RIGHTS_CHOICES, default = u"CT")
    60     credits = models.PositiveSmallIntegerField(default = 0)
    56     credits = models.PositiveSmallIntegerField(default = 0)
    61     
    57     
    62     aboutme = models.TextField(blank = True)
    58     aboutme = models.TextField(blank = True)
    63 #    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.")
       
    64     foss_comm = TagField()
    59     foss_comm = TagField()
    65     phonenum = models.CharField(max_length = 15, blank = True, verbose_name = u"Phone Number")
    60     phonenum = models.CharField(max_length = 15, blank = True, verbose_name = u"Phone Number")
    66     homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog")
    61     homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog")
    67     street = models.CharField(max_length = 80, blank = True)
    62     street = models.CharField(max_length = 80, blank = True)
    68     city = models.CharField(max_length = 25, blank = True)
    63     city = models.CharField(max_length = 25, blank = True)
    74         return unicode(self.user.username)
    69         return unicode(self.user.username)
    75 
    70 
    76 
    71 
    77 class Task(models.Model):
    72 class Task(models.Model):
    78     
    73     
       
    74     prim_key = models.AutoField(primary_key = True)
       
    75     id = models.CharField(max_length = 10, unique = True)
    79     title = models.CharField(max_length = 100, unique = True, verbose_name = u"Title", help_text = u"Keep it simple and below 100 chars.")
    76     title = models.CharField(max_length = 100, unique = True, verbose_name = u"Title", help_text = u"Keep it simple and below 100 chars.")
    80     desc = models.TextField(verbose_name = u"Description")
    77     desc = models.TextField(verbose_name = u"Description")
    81     status = models.CharField(max_length = 2, choices = STATUS_CHOICES, default = "UP")
    78     status = models.CharField(max_length = 2, choices = STATUS_CHOICES, default = "UP")
    82 #    tags = models.CharField(max_length = 200, blank = True)
       
    83     tags_field = TagField()
    79     tags_field = TagField()
    84     
    80     
    85     credits = models.PositiveSmallIntegerField()
    81     credits = models.PositiveSmallIntegerField()
    86     progress = models.PositiveSmallIntegerField(default = 0)
    82     progress = models.PositiveSmallIntegerField(default = 0)
    87         
    83         
    90     claimed_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_claimed_users")
    86     claimed_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_claimed_users")
    91     assigned_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_assigned_users")
    87     assigned_users = models.ManyToManyField(User, blank = True, related_name = "%(class)s_assigned_users")
    92     
    88     
    93     creation_datetime = models.DateTimeField()
    89     creation_datetime = models.DateTimeField()
    94     sub_type = models.CharField(max_length=1, choices = (('D','Dependency'),('S','Subtask')), default = 'D')   
    90     sub_type = models.CharField(max_length=1, choices = (('D','Dependency'),('S','Subtask')), default = 'D')   
    95     #is_claimable = models.BooleanField()
       
    96     
       
    97     ## not yet decided if attribs after this are to be included
       
    98     ## tasktype = "" ## "bugfix"/"enhancement"
       
    99     ## priority = "" ## "very urgent"/"urgent"
       
   100     
    91     
   101     def __unicode__(self):
    92     def __unicode__(self):
   102         return unicode(self.title)
    93         return unicode(self.title)
   103 
    94 
   104 class Map(models.Model):
    95 class Map(models.Model):
   143     sent_to = models.ManyToManyField(User, related_name = "%(class)s_sent_to", blank = False)
   134     sent_to = models.ManyToManyField(User, related_name = "%(class)s_sent_to", blank = False)
   144     sent_by = models.ForeignKey(User, related_name = "%(class)s_sent_by", blank = False)
   135     sent_by = models.ForeignKey(User, related_name = "%(class)s_sent_by", blank = False)
   145     role = models.CharField(max_length = 2, blank = False)
   136     role = models.CharField(max_length = 2, blank = False)
   146     reply = models.BooleanField(default = False, blank = False)
   137     reply = models.BooleanField(default = False, blank = False)
   147     remarks = models.TextField(default = "",blank = True)
   138     remarks = models.TextField(default = "",blank = True)
       
   139     
   148     is_read = models.BooleanField(default = False, blank = False)
   140     is_read = models.BooleanField(default = False, blank = False)
   149     is_valid = models.BooleanField(default = True, blank = False)
   141     is_valid = models.BooleanField(default = True, blank = False)
       
   142     
   150     creation_date = models.DateTimeField()
   143     creation_date = models.DateTimeField()
   151     reply_date = models.DateTimeField()
   144     reply_date = models.DateTimeField()
   152     is_replied = models.BooleanField(default = False)
   145     is_replied = models.BooleanField(default = False)
   153     replied_by = models.ForeignKey(User, related_name = "%(class)s_replied_by", blank = True, null = True)
   146     replied_by = models.ForeignKey(User, related_name = "%(class)s_replied_by", blank = True, null = True)
       
   147     
   154     task = models.ForeignKey(Task,related_name = "%(class)s_task", blank = True, null = True)
   148     task = models.ForeignKey(Task,related_name = "%(class)s_task", blank = True, null = True)
   155     receiving_user = models.ForeignKey(User, related_name = "%(class)s_receiving_user", blank = True, null = True)
   149     receiving_user = models.ForeignKey(User, related_name = "%(class)s_receiving_user", blank = True, null = True)
   156     pynts = models.PositiveIntegerField(default=0)
   150     pynts = models.PositiveIntegerField(default=0)
   157 
   151 
   158     def __unicode__(self):
   152     def __unicode__(self):