from django.db import models import settings import treebeard.mp_tree class BudgetArea(treebeard.mp_tree.MP_Node): indent_str = u"\u00A0\u00A0" name = models.CharField(max_length=50) comment = models.TextField(blank=True) always = models.BooleanField(blank=True, default=False) # Contact / ACL information # If not specified, inherit from parent owner = models.EmailField(help_text = 'Email address of the officer responsible for the area', blank=True) # owner of the budget area interested = models.EmailField(help_text='Email address of parties interested in the area', blank=True) # interested parties (ie, whole committee) use_owner = models.BooleanField(default=False, blank=True) def contact_address(self,): address = '' if self.use_owner: address = self.owner or self.interested else: address = self.interested or self.owner return address or self.get_parent().contact_address() def mark_used(self, term, comment=""): BudgetAreaTerm.objects.get_or_create( budget_area=self, budget_term=term, defaults={'comment':comment} ) @classmethod def get_by_path(cls, path): root = BudgetArea.objects.get(name=path[0], depth=1) node = root for name in path[1:]: node = node.get_children().filter(name=name)[0] return node def dump_to_html(self): struct = self.dump_bulk() return self.struct_to_html(struct, depth=0) def struct_to_html(self, struct, depth=0): def format_data(data): return ""+data['name']+" "+unicode(data) prefix = "\t"*depth html = prefix+"