<s> import uuid <EOL> from django . db import models <EOL> from django . contrib . auth . models import User , Group <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from djtracker . utils import check_perms <EOL> class UserProfile ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> instant_messanger = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> user = models . OneToOneField ( User , unique = True , verbose_name = _ ( "<STR_LIT:user>" ) ) <EOL> uuid = models . CharField ( max_length = <NUM_LIT> ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . user . username <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT:username>' : self . user . username } ) <EOL> def save ( self ) : <EOL> if not self . uuid : <EOL> temp_uuid = str ( uuid . uuid1 ( ) ) <EOL> temp_uuid = temp_uuid . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> self . uuid = temp_uuid <EOL> super ( UserProfile , self ) . save ( ) <EOL> def get_allowed_project_ids ( request , user = None , permission = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> project_ids = [ ] <EOL> perm_index = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] . index ( permission ) <EOL> for project in models . get_model ( '<STR_LIT>' , '<STR_LIT>' ) . objects . all ( ) : <EOL> perms = check_perms ( request , project , user ) <EOL> if perms [ perm_index ] : <EOL> project_ids . append ( project . id ) <EOL> return project_ids <EOL> class PermissionFilterManager ( models . Manager ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , by = '<STR_LIT>' , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . _by = by <EOL> super ( PermissionFilterManager , self ) . __init__ ( * args , ** kwargs ) <EOL> def filter_allowed ( self , request , permission = '<STR_LIT>' ) : <EOL> project_ids = get_allowed_project_ids ( request , permission ) <EOL> if self . _by : <EOL> return self . filter ( ** { self . _by : project_ids } ) <EOL> class Project ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> description = models . TextField ( _ ( "<STR_LIT:description>" ) , blank = True , null = True ) <EOL> git_repo_path = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> git_repo_commit = models . TextField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> svn_repo_url = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> svn_repo_commit = models . TextField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> svn_repo_username = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> svn_repo_password = models . TextField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True <EOL> ) <EOL> allow_anon_viewing = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> allow_anon_editing = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> allow_anon_comment = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> allow_authed_viewing = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> allow_authed_editing = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> allow_authed_comment = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> groups_can_view = models . ManyToManyField ( Group , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> groups_can_edit = models . ManyToManyField ( Group , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> groups_can_comment = models . ManyToManyField ( Group , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> users_can_view = models . ManyToManyField ( User , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> users_can_edit = models . ManyToManyField ( User , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> users_can_comment = models . ManyToManyField ( User , <EOL> blank = True , <EOL> null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> watched_by = models . ManyToManyField ( UserProfile , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> active = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . slug } ) <EOL> objects = PermissionFilterManager ( by = '<STR_LIT>' ) <EOL> class Milestone ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> project = models . ForeignKey ( Project , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> description = models . TextField ( _ ( "<STR_LIT:description>" ) , blank = True , null = True ) <EOL> goal_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> active = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> objects = PermissionFilterManager ( ) <EOL> class Component ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> project = models . ForeignKey ( Project , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> active = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> objects = PermissionFilterManager ( ) <EOL> class Version ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> project = models . ForeignKey ( Project , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> active = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> objects = PermissionFilterManager ( ) <EOL> class Status ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> class Priority ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> class Meta : <EOL> verbose_name_plural = "<STR_LIT>" <EOL> class IssueType ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . slug } ) <EOL> class Issue ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> project = models . ForeignKey ( Project , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> component = models . ForeignKey ( Component , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> version = models . ForeignKey ( Version , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT:version>" ) <EOL> ) <EOL> milestone = models . ForeignKey ( Milestone , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> status = models . ForeignKey ( Status , <EOL> verbose_name = _ ( "<STR_LIT:status>" ) <EOL> ) <EOL> priority = models . ForeignKey ( Priority , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> issue_type = models . ForeignKey ( IssueType , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> description = models . TextField ( _ ( "<STR_LIT:description>" ) ) <EOL> created_by = models . ForeignKey ( UserProfile , <EOL> blank = True , <EOL> null = True , <EOL> related_name = "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) <EOL> assigned_to = models . ForeignKey ( UserProfile , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> watched_by = models . ManyToManyField ( UserProfile , <EOL> blank = True , <EOL> null = True , <EOL> related_name = "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) <EOL> active = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . project . slug , <EOL> '<STR_LIT>' : self . id } ) <EOL> objects = PermissionFilterManager ( ) <EOL> class FileUpload ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> file = models . FileField ( _ ( "<STR_LIT:file>" ) , upload_to = '<STR_LIT>' ) <EOL> issue = models . ForeignKey ( Issue , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> created_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> modified_date = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( "<STR_LIT>" , ( ) , { '<STR_LIT>' : self . issue . project . slug , <EOL> '<STR_LIT>' : self . id } ) <EOL> objects = PermissionFilterManager ( by = '<STR_LIT>' ) <EOL> class IssueFilter ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> project = models . ForeignKey ( Project , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> user = models . ForeignKey ( UserProfile , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT:user>" ) <EOL> ) <EOL> name = models . CharField ( _ ( "<STR_LIT:name>" ) , max_length = <NUM_LIT> ) <EOL> component = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) <EOL> version = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT:version>" ) <EOL> ) <EOL> milestone = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> status = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT:status>" ) <EOL> ) <EOL> type = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT:type>" ) <EOL> ) <EOL> priority = models . CharField ( max_length = <NUM_LIT> , <EOL> blank = True , <EOL> null = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . user , self . name ) <EOL> def get_filtered_url ( self ) : <EOL> base_url = reverse ( "<STR_LIT>" , kwargs = { '<STR_LIT>' : self . project . slug } ) <EOL> get_vars = "<STR_LIT>" % ( <EOL> self . component , self . version , self . milestone , self . status , self . type , <EOL> self . priority ) <EOL> final_url = base_url + get_vars <EOL> return final_url </s>
