app/soc/views/models/program.py
changeset 777 16dcdb8f3357
parent 771 0b1beae179f5
child 778 bc13cd968946
equal deleted inserted replaced
776:f86a76f52bf4 777:16dcdb8f3357
    25 
    25 
    26 from django import forms
    26 from django import forms
    27 
    27 
    28 from soc.logic import cleaning
    28 from soc.logic import cleaning
    29 from soc.logic import dicts
    29 from soc.logic import dicts
    30 from soc.logic.models import timeline as timeline_logic
       
    31 from soc.views import helper
    30 from soc.views import helper
    32 from soc.views.helper import access
    31 from soc.views.helper import access
    33 from soc.views.helper import redirects
    32 from soc.views.helper import redirects
    34 from soc.views.models import base
    33 from soc.views.models import base
    35 from soc.views.models import document as document_view
    34 from soc.views.models import document as document_view
    69     new_params['name_short'] = "Program"
    68     new_params['name_short'] = "Program"
    70     new_params['name_plural'] = "Programs"
    69     new_params['name_plural'] = "Programs"
    71     new_params['url_name'] = "program"
    70     new_params['url_name'] = "program"
    72     new_params['module_name'] = "program"
    71     new_params['module_name'] = "program"
    73 
    72 
       
    73     new_params['edit_template'] = 'soc/program/edit.html'
       
    74 
    74     new_params['extra_dynaexclude'] = ['home', 'timeline']
    75     new_params['extra_dynaexclude'] = ['home', 'timeline']
    75     new_params['create_extra_dynafields'] = {
    76     new_params['create_extra_dynafields'] = {
    76         'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
    77         'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
    77             attrs={'rows':10, 'cols':40})),
    78             attrs={'rows':10, 'cols':40})),
    78         'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
    79         'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
    82         }
    83         }
    83 
    84 
    84     params = dicts.merge(params, new_params)
    85     params = dicts.merge(params, new_params)
    85 
    86 
    86     super(View, self).__init__(params=params)
    87     super(View, self).__init__(params=params)
    87   
    88 
    88   def _editPost(self, request, entity, fields):
    89   def _editPost(self, request, entity, fields):
    89     """See base._editPost().
    90     """See base._editPost().
    90     """
    91     """
    91     
    92 
    92     if not entity:
    93     if not entity:
    93       # there is no existing entity so create a new timeline
    94       # there is no existing entity so create a new timeline
    94       fields['timeline'] = self._createTimelineForType(fields['workflow'])
    95       fields['timeline'] = self._createTimelineForType(fields)
    95     else:
    96     else:
    96       # use the timeline from the entity
    97       # use the timeline from the entity
    97       fields['timeline'] = entity.timeline
    98       fields['timeline'] = entity.timeline
    98     
    99 
    99   def _createTimelineForType(self, type):
   100   def _createTimelineForType(self, fields):
   100     """Creates and stores a timeline model for the given type of program.
   101     """Creates and stores a timeline model for the given type of program.
   101     """
   102     """
   102     
   103 
   103     timelines = {'gsoc' : gsoc.models.timeline.Timeline(),
   104     timelines = {'gsoc' : gsoc.logic.models.timeline.logic,
   104                  'ghop' : soc.models.timeline.Timeline()}
   105                  'ghop' : soc.logic.models.timeline.logic,}
   105         
   106 
   106     return timelines[type].put()
   107     workflow = fields['workflow']
       
   108 
       
   109     timeline_logic = timelines[workflow]
       
   110 
       
   111     key_fields = self._logic.getKeyFieldsFromDict(fields)
       
   112     key_name = self._logic.getKeyNameForFields(key_fields)
       
   113 
       
   114     properties = {'scope_path': key_name}
       
   115 
       
   116     timeline = timeline_logic.updateOrCreateFromFields(properties, properties)
       
   117     return timeline
   107 
   118 
   108   def getExtraMenus(self, request, params=None):
   119   def getExtraMenus(self, request, params=None):
   109     """Returns the extra menu's for this view.
   120     """Returns the extra menu's for this view.
   110 
   121 
   111     A menu item is generated for each program that is currently
   122     A menu item is generated for each program that is currently