22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
23 '"Pawel Solyga" <pawel.solyga@gmail.com>', |
23 '"Pawel Solyga" <pawel.solyga@gmail.com>', |
24 ] |
24 ] |
25 |
25 |
26 |
26 |
27 from google.appengine.api import users |
|
28 |
|
29 from django import forms |
|
30 |
|
31 from soc.logic import dicts |
27 from soc.logic import dicts |
32 from soc.views import helper |
28 from soc.views.models import group |
33 from soc.views.models import base |
|
34 |
29 |
35 import soc.models.sponsor |
30 import soc.models.sponsor |
36 import soc.logic.models.sponsor |
31 import soc.logic.models.sponsor |
37 import soc.logic.dicts |
32 import soc.logic.dicts |
38 import soc.views.helper |
|
39 import soc.views.helper.widgets |
|
40 |
33 |
41 |
34 |
42 class View(base.View): |
35 class View(group.View): |
43 """View methods for the Sponsor model. |
36 """View methods for the Sponsor model. |
44 """ |
37 """ |
45 |
38 |
46 def __init__(self, params=None): |
39 def __init__(self, params=None): |
47 """Defines the fields and methods required for the base View class |
40 """Defines the fields and methods required for the base View class |
61 # from name. Make that work for all other Views too. Hopefully |
54 # from name. Make that work for all other Views too. Hopefully |
62 # solution that will be implemented in base View. |
55 # solution that will be implemented in base View. |
63 new_params['url_name'] = "sponsor" |
56 new_params['url_name'] = "sponsor" |
64 new_params['module_name'] = "sponsor" |
57 new_params['module_name'] = "sponsor" |
65 |
58 |
66 new_params['extra_dynaexclude'] = ['founder', 'home'] |
|
67 new_params['edit_extra_dynafields'] = { |
|
68 'founded_by': forms.CharField(widget=helper.widgets.ReadOnlyInput(), |
|
69 required=False), |
|
70 } |
|
71 |
|
72 # TODO(tlarsen): Add support for Django style template lookup |
|
73 new_params['public_template'] = 'soc/group/public.html' |
|
74 |
|
75 new_params['list_row'] = 'soc/group/list/row.html' |
|
76 new_params['list_heading'] = 'soc/group/list/heading.html' |
|
77 |
|
78 params = dicts.merge(params, new_params) |
59 params = dicts.merge(params, new_params) |
79 |
60 |
80 super(View, self).__init__(params=params) |
61 super(View, self).__init__(params=params) |
81 |
|
82 def _editGet(self, request, entity, form): |
|
83 """See base.View._editGet(). |
|
84 """ |
|
85 |
|
86 # fill in the founded_by with data from the entity |
|
87 form.fields['founded_by'].initial = entity.founder.name |
|
88 |
|
89 def _editPost(self, request, entity, fields): |
|
90 """See base.View._editPost(). |
|
91 """ |
|
92 |
|
93 account = users.get_current_user() |
|
94 user = soc.logic.models.user.logic.getForFields({'account': account}, |
|
95 unique=True) |
|
96 if not entity: |
|
97 # only if we are creating a new entity we should fill in founder |
|
98 fields['founder'] = user |
|
99 |
62 |
100 |
63 |
101 view = View() |
64 view = View() |
102 |
65 |
103 create = view.create |
66 create = view.create |