source: treasury/finance_core/models.py @ b26026c

client
Last change on this file since b26026c was b26026c, checked in by Alex Dehnert <adehnert@…>, 16 years ago

Fix unknown indent_str variable

  • Property mode set to 100644
File size: 3.0 KB
Line 
1from django.db import models
2import settings
3import treebeard.mp_tree
4
5
6class BudgetArea(treebeard.mp_tree.MP_Node):
7    indent_str = u"\u00A0\u00A0"
8
9    name = models.CharField(max_length=50)
10    comment = models.TextField(blank=True)
11    always = models.BooleanField(blank=True, default=False)
12
13    # Contact / ACL information
14    # If not specified, inherit from parent
15    owner = models.EmailField(help_text = 'Email address of the officer responsible for the area', blank=True) # owner of the budget area
16    interested = models.EmailField(help_text='Email address of parties interested in the area', blank=True) # interested parties (ie, whole committee)
17    use_owner = models.BooleanField(default=False, blank=True)
18
19    def contact_address(self,):
20        address = ''
21        if self.use_owner:
22            address = self.owner or self.interested
23        else:
24            address = self.interested or self.owner
25        return address or self.get_parent().contact_address()
26
27    def mark_used(self, term, comment=""):
28        BudgetAreaTerm.objects.get_or_create(
29            budget_area=self,
30            budget_term=term,
31            defaults={'comment':comment}
32        )
33
34    @classmethod
35    def get_by_path(cls, path):
36        root = BudgetArea.objects.get(name=path[0], depth=1)
37        node = root
38        for name in path[1:]:
39            node = node.get_children().filter(name=name)[0]
40        return node
41
42    def dump_to_html(self):
43        struct = self.dump_bulk()
44        return self.struct_to_html(struct, depth=0)
45
46    def struct_to_html(self, struct, depth=0):
47        def format_data(data):
48            return "<em>"+data['name']+"</em> "+unicode(data)
49        prefix = "\t"*depth
50        html = prefix+"<ul>\n"
51        html = html + "\n".join(
52            [("%(prefix)s\t<li>%(data)s\n%(children)s\t%(prefix)s</li>\n" % {
53                'prefix':prefix,
54                'data':format_data(elem['data']),
55                'children':('children' in elem and self.struct_to_html(elem['children'], depth+1) or '')
56            }) for elem in struct])
57        html = html + prefix + "</ul>\n"
58        return html
59
60    def indented_name(self):
61        return self.indent_str*self.depth + unicode(self)
62
63    def __unicode__(self,):
64        return u"%s [%s] (%s)" % (self.name, self.contact_address(), self.always, )
65
66
67class BudgetTerm(models.Model):
68    name = models.CharField(max_length=20)
69    slug = models.SlugField(max_length=20)
70    start_date = models.DateField()
71    end_date = models.DateField()
72    submit_deadline = models.DateField()
73
74    def __unicode__(self,):
75        return "%s (%s to %s [due %s])" % (self.name, self.start_date, self.end_date, self.submit_deadline, )
76
77
78class BudgetAreaTerm(models.Model):
79    budget_area = models.ForeignKey(BudgetArea)
80    budget_term = models.ForeignKey(BudgetTerm)
81    comment = models.TextField(blank=True, )
82
83    def __unicode__(self,):
84        return "%s during %s" % (self.budget_area, self.budget_term, )
85
86
87def coerce_full_email(email):
88    if '@' in email: return email
89    else: return email + '@' + settings.DEFAULT_DOMAIN
Note: See TracBrowser for help on using the repository browser.