Changeset 13a23ce
- Timestamp:
- Jan 5, 2010, 4:53:12 AM (16 years ago)
- Branches:
- master, client
- Children:
- 7874f6a
- Parents:
- 719e4bb
- git-author:
- Alex Dehnert <adehnert@…> (01/05/10 04:53:12)
- git-committer:
- Alex Dehnert <adehnert@…> (01/05/10 04:53:12)
- Location:
- treasury
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
treasury/settings.py
r719e4bb r13a23ce 1 1 # Django settings for treasury project. 2 import os 3 4 APP_ROOT = os.path.dirname(__file__) 5 DEFAULT_DOMAIN = 'mit.edu' 2 6 3 7 DEBUG = True … … 5 9 6 10 ADMINS = ( 7 # ('Your Name', 'your_email@domain.com'),11 ('Alex Dehnert', 'adehnert@mit.edu'), 8 12 ) 9 13 10 14 MANAGERS = ADMINS 11 15 12 DATABASE_ENGINE = ' ' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.13 DATABASE_NAME = ' ' # Or path to database file if using sqlite3.16 DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 17 DATABASE_NAME = 'treasury.sqlite' # Or path to database file if using sqlite3. 14 18 DATABASE_USER = '' # Not used with sqlite3. 15 19 DATABASE_PASSWORD = '' # Not used with sqlite3. … … 70 74 # Always use forward slashes, even on Windows. 71 75 # Don't forget to use absolute paths, not relative paths. 76 APP_ROOT + '/templates/', 72 77 ) 73 78 74 79 INSTALLED_APPS = ( 80 'django.contrib.admin', 81 'django.contrib.admindocs', 75 82 'django.contrib.auth', 76 83 'django.contrib.contenttypes', 77 84 'django.contrib.sessions', 78 85 'django.contrib.sites', 86 'treebeard', 87 'vouchers', 79 88 ) -
treasury/urls.py
r719e4bb r13a23ce 2 2 3 3 # Uncomment the next two lines to enable the admin: 4 #from django.contrib import admin5 #admin.autodiscover()4 from django.contrib import admin 5 admin.autodiscover() 6 6 7 7 urlpatterns = patterns('', 8 8 # Example: 9 # (r'^treasury/', include('treasury.foo.urls')),9 (r'^vouchers/', include('treasury.vouchers.urls')), 10 10 11 11 # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 12 12 # to INSTALLED_APPS to enable admin documentation: 13 #(r'^admin/doc/', include('django.contrib.admindocs.urls')),13 (r'^admin/doc/', include('django.contrib.admindocs.urls')), 14 14 15 15 # Uncomment the next line to enable the admin: 16 #(r'^admin/(.*)', admin.site.root),16 (r'^admin/(.*)', admin.site.root), 17 17 ) -
treasury/vouchers/models.py
r719e4bb r13a23ce 1 1 from django.db import models 2 import treebeard.mp_tree 3 import settings 2 4 3 # Create your models here. 5 class BudgetArea(treebeard.mp_tree.MP_Node): 6 name = models.CharField(max_length=50) 7 comment = models.TextField(blank=True) 8 always = models.BooleanField(blank=True, default=False) 9 10 # Contact / ACL information 11 # If not specified, inherit from parent 12 owner = models.EmailField(help_text = 'Email address of the officer responsible for the area', blank=True) # owner of the budget area 13 interested = models.EmailField(help_text='Email address of parties interested in the area', blank=True) # interested parties (ie, whole committee) 14 use_owner = models.BooleanField(default=False, blank=True) 15 16 def contact_address(self,): 17 address = '' 18 if self.use_owner: 19 address = self.owner or self.interested 20 else: 21 address = self.interested or self.owner 22 return address or self.get_parent().contact_address() 23 24 def mark_used(self, term, comment=""): 25 BudgetAreaTerm.objects.get_or_create( 26 budget_area=self, 27 budget_term=term, 28 defaults={'comment':comment} 29 ) 30 31 @classmethod 32 def get_by_path(cls, path): 33 root = BudgetArea.objects.get(name=path[0], depth=1) 34 node = root 35 for name in path[1:]: 36 node = node.get_children().filter(name=name)[0] 37 return node 38 39 def dump_to_html(self): 40 struct = self.dump_bulk() 41 return self.struct_to_html(struct, depth=0) 42 43 def struct_to_html(self, struct, depth=0): 44 def format_data(data): 45 return "<em>"+data['name']+"</em> "+unicode(data) 46 prefix = "\t"*depth 47 html = prefix+"<ul>\n" 48 html = html + "\n".join( 49 [("%(prefix)s\t<li>%(data)s\n%(children)s\t%(prefix)s</li>\n" % { 50 'prefix':prefix, 51 'data':format_data(elem['data']), 52 'children':('children' in elem and self.struct_to_html(elem['children'], depth+1) or '') 53 }) for elem in struct]) 54 html = html + prefix + "</ul>\n" 55 return html 56 57 def __unicode__(self,): 58 return u"%s [%s] (%s)" % (self.name, self.contact_address(), self.always, ) 59 60 class BudgetTerm(models.Model): 61 name = models.CharField(max_length=20) 62 start_date = models.DateField() 63 end_date = models.DateField() 64 submit_deadline = models.DateField() 65 66 class BudgetAreaTerm(models.Model): 67 budget_area = models.ForeignKey(BudgetArea) 68 budget_term = models.ForeignKey(BudgetTerm) 69 comment = models.TextField(blank=True, ) 70 71 class ReimbursementRequest(models.Model): 72 submitter = models.CharField(max_length=10) # MIT username of submitter 73 check_to_name = models.CharField(max_length=50) 74 check_to_email = models.EmailField() 75 check_to_addr = models.TextField(blank=True) 76 amount = models.DecimalField(max_digits=7, decimal_places=2) 77 budget_area = models.ForeignKey(BudgetArea) 78 budget_term = models.ForeignKey(BudgetTerm) 79 80 def coerce_full_email(email): 81 if '@' in email: return email 82 else: return email + '@' + settings.DEFAULT_DOMAIN -
treasury/vouchers/views.py
r719e4bb r13a23ce 1 # Create your views here. 1 from django.http import HttpResponse 2 import treasury.vouchers.models 3 4 def display_tree(request): 5 root = treasury.vouchers.models.BudgetArea.get_by_path(['Accounts']) 6 return HttpResponse(root.dump_to_html())
Note: See TracChangeset
for help on using the changeset viewer.