Changeset f468e6d for treasury/vouchers/models.py
- Timestamp:
- Jan 6, 2010, 3:04:46 AM (16 years ago)
- Branches:
- master, client
- Children:
- b26026c
- Parents:
- 6027277
- git-author:
- Alex Dehnert <adehnert@…> (01/06/10 03:04:46)
- git-committer:
- Alex Dehnert <adehnert@…> (01/06/10 03:04:46)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
treasury/vouchers/models.py
r6027277 rf468e6d 1 1 from django.db import models 2 import treebeard.mp_tree3 2 import settings 4 5 6 class BudgetArea(treebeard.mp_tree.MP_Node): 7 name = models.CharField(max_length=50) 8 comment = models.TextField(blank=True) 9 always = models.BooleanField(blank=True, default=False) 10 11 # Contact / ACL information 12 # If not specified, inherit from parent 13 owner = models.EmailField(help_text = 'Email address of the officer responsible for the area', blank=True) # owner of the budget area 14 interested = models.EmailField(help_text='Email address of parties interested in the area', blank=True) # interested parties (ie, whole committee) 15 use_owner = models.BooleanField(default=False, blank=True) 16 17 def contact_address(self,): 18 address = '' 19 if self.use_owner: 20 address = self.owner or self.interested 21 else: 22 address = self.interested or self.owner 23 return address or self.get_parent().contact_address() 24 25 def mark_used(self, term, comment=""): 26 BudgetAreaTerm.objects.get_or_create( 27 budget_area=self, 28 budget_term=term, 29 defaults={'comment':comment} 30 ) 31 32 @classmethod 33 def get_by_path(cls, path): 34 root = BudgetArea.objects.get(name=path[0], depth=1) 35 node = root 36 for name in path[1:]: 37 node = node.get_children().filter(name=name)[0] 38 return node 39 40 def dump_to_html(self): 41 struct = self.dump_bulk() 42 return self.struct_to_html(struct, depth=0) 43 44 def struct_to_html(self, struct, depth=0): 45 def format_data(data): 46 return "<em>"+data['name']+"</em> "+unicode(data) 47 prefix = "\t"*depth 48 html = prefix+"<ul>\n" 49 html = html + "\n".join( 50 [("%(prefix)s\t<li>%(data)s\n%(children)s\t%(prefix)s</li>\n" % { 51 'prefix':prefix, 52 'data':format_data(elem['data']), 53 'children':('children' in elem and self.struct_to_html(elem['children'], depth+1) or '') 54 }) for elem in struct]) 55 html = html + prefix + "</ul>\n" 56 return html 57 58 def __unicode__(self,): 59 return u"%s [%s] (%s)" % (self.name, self.contact_address(), self.always, ) 60 61 62 class BudgetTerm(models.Model): 63 name = models.CharField(max_length=20) 64 slug = models.SlugField(max_length=20) 65 start_date = models.DateField() 66 end_date = models.DateField() 67 submit_deadline = models.DateField() 68 69 def __unicode__(self,): 70 return "%s (%s to %s [due %s])" % (self.name, self.start_date, self.end_date, self.submit_deadline, ) 71 72 73 class BudgetAreaTerm(models.Model): 74 budget_area = models.ForeignKey(BudgetArea) 75 budget_term = models.ForeignKey(BudgetTerm) 76 comment = models.TextField(blank=True, ) 77 78 def __unicode__(self,): 79 return "%s during %s" % (self.budget_area, self.budget_term, ) 3 from finance_core.models import BudgetArea, BudgetTerm 80 4 81 5 … … 88 12 budget_area = models.ForeignKey(BudgetArea) 89 13 budget_term = models.ForeignKey(BudgetTerm) 90 91 def coerce_full_email(email):92 if '@' in email: return email93 else: return email + '@' + settings.DEFAULT_DOMAIN
Note: See TracChangeset
for help on using the changeset viewer.