app/soc/views/settings.py
changeset 512 aae25d2b4464
parent 500 44ea4620c5c0
child 513 3c1e16637ad7
equal deleted inserted replaced
511:52557918ec8f 512:aae25d2b4464
    92       help_text=soc.models.work.Work.partial_path.help_text)
    92       help_text=soc.models.work.Work.partial_path.help_text)
    93 
    93 
    94   # TODO(tlarsen): actually, using these two text fields to specify
    94   # TODO(tlarsen): actually, using these two text fields to specify
    95   #   the Document is pretty cheesy; this needs to be some much better
    95   #   the Document is pretty cheesy; this needs to be some much better
    96   #   Role-scoped Document selector that we don't have yet
    96   #   Role-scoped Document selector that we don't have yet
    97   doc_link_name = forms.CharField(required=False,
    97   doc_link_id = forms.CharField(required=False,
    98       label=soc.models.work.Work.link_name.verbose_name,
    98       label=soc.models.work.Work.link_id.verbose_name,
    99       help_text=soc.models.work.Work.link_name.help_text)
    99       help_text=soc.models.work.Work.link_id.help_text)
   100 
   100 
   101   class Meta:
   101   class Meta:
   102     model = None
   102     model = None
   103 
   103 
   104 
   104 
   105 DEF_HOME_EDIT_TMPL = 'soc/site_settings/edit.html'
   105 DEF_HOME_EDIT_TMPL = 'soc/site_settings/edit.html'
   106 
   106 
   107 @decorators.view
   107 @decorators.view
   108 def edit(request, page_name=None, partial_path=None, link_name=None, 
   108 def edit(request, page_name=None, partial_path=None, link_id=None, 
   109          logic=models.home_settings.logic,
   109          logic=models.home_settings.logic,
   110          settings_form_class=SettingsForm,
   110          settings_form_class=SettingsForm,
   111          template=DEF_HOME_EDIT_TMPL):
   111          template=DEF_HOME_EDIT_TMPL):
   112   """View for authorized User to edit contents of a home page.
   112   """View for authorized User to edit contents of a home page.
   113 
   113 
   149       for field in settings_form.cleaned_data:
   149       for field in settings_form.cleaned_data:
   150         value = settings_form.cleaned_data.get(field)
   150         value = settings_form.cleaned_data.get(field)
   151         fields[field] = value
   151         fields[field] = value
   152 
   152 
   153       doc_partial_path = doc_select_form.cleaned_data.get('doc_partial_path')
   153       doc_partial_path = doc_select_form.cleaned_data.get('doc_partial_path')
   154       doc_link_name = doc_select_form.cleaned_data.get('doc_link_name')
   154       doc_link_id = doc_select_form.cleaned_data.get('doc_link_id')
   155 
   155 
   156       home_doc = document.logic.getFromFields(
   156       home_doc = document.logic.getFromFields(
   157           partial_path=doc_partial_path, link_name=doc_link_name)
   157           partial_path=doc_partial_path, link_id=doc_link_id)
   158 
   158 
   159       if home_doc:
   159       if home_doc:
   160         fields['home'] = home_doc
   160         fields['home'] = home_doc
   161         context['notice'] = ugettext_lazy('Settings saved.')
   161         context['notice'] = ugettext_lazy('Settings saved.')
   162       else:
   162       else:
   170       if settings.home:
   170       if settings.home:
   171         home_doc = settings.home
   171         home_doc = settings.home
   172   else: # request.method == 'GET'
   172   else: # request.method == 'GET'
   173     # try to fetch HomeSettings entity by unique key_name
   173     # try to fetch HomeSettings entity by unique key_name
   174     settings = logic.getFromFields(partial_path=partial_path, 
   174     settings = logic.getFromFields(partial_path=partial_path, 
   175                                    link_name=link_name)
   175                                    link_id=link_id)
   176 
   176 
   177     if settings:
   177     if settings:
   178       # populate form with the existing HomeSettings entity
   178       # populate form with the existing HomeSettings entity
   179       settings_form = settings_form_class(instance=settings)
   179       settings_form = settings_form_class(instance=settings)
   180 
   180 
   185         pass
   185         pass
   186     
   186     
   187       if home_doc:
   187       if home_doc:
   188         doc_select_form = DocSelectForm(initial={
   188         doc_select_form = DocSelectForm(initial={
   189             'doc_partial_path': home_doc.partial_path,
   189             'doc_partial_path': home_doc.partial_path,
   190             'doc_link_name': home_doc.link_name})
   190             'doc_link_id': home_doc.link_id})
   191       else:
   191       else:
   192         doc_select_form = DocSelectForm()
   192         doc_select_form = DocSelectForm()
   193     else:
   193     else:
   194       # no SiteSettings entity exists for this key_name, so show a blank form
   194       # no SiteSettings entity exists for this key_name, so show a blank form
   195       settings_form = settings_form_class()
   195       settings_form = settings_form_class()