app/soc/views/models/base.py
changeset 410 2af7f84f4fc7
parent 409 9d24850db88f
child 418 e035f31d131e
equal deleted inserted replaced
409:9d24850db88f 410:2af7f84f4fc7
   131         that combines a Django view with sidebar menu info
   131         that combines a Django view with sidebar menu info
   132       kwargs: not used for create()
   132       kwargs: not used for create()
   133     """
   133     """
   134 
   134 
   135     # Create page is an edit page with no key fields
   135     # Create page is an edit page with no key fields
   136     kwargs = self._logic.getEmptyKeyFields()
   136     kwargs = {}
       
   137     fields = self._logic.getKeyFieldNames()
       
   138     for field in fields:
       
   139       kwargs[field] = None
       
   140 
   137     return self.edit(request, page=page, **kwargs)
   141     return self.edit(request, page=page, **kwargs)
   138 
   142 
   139   def edit(self, request, page=None, **kwargs):
   143   def edit(self, request, page=None, **kwargs):
   140     """Displays the public page for the entity specified by **kwargs
   144     """Displays the public page for the entity specified by **kwargs
   141 
   145 
   185 
   189 
   186     fields = self.collectCleanedFields(form)
   190     fields = self.collectCleanedFields(form)
   187 
   191 
   188     self._editPost(request, entity, fields)
   192     self._editPost(request, entity, fields)
   189 
   193 
   190     keys = self._logic.extractKeyFields(fields)
   194     keys = self._logic.getKeyFieldNames()
   191     entity = self._logic.updateOrCreateFromFields(fields, **keys)
   195     values = self._logic.getKeyValuesFromFields(fields)
       
   196     kwargs = dicts.zip(keys, values)
       
   197     entity = self._logic.updateOrCreateFromFields(fields, **kwargs)
   192 
   198 
   193     if not entity:
   199     if not entity:
   194       return http.HttpResponseRedirect('/')
   200       return http.HttpResponseRedirect('/')
   195 
   201 
   196     params = self._params['edit_params']
   202     params = self._params['edit_params']
   197     suffix = self._logic.constructKeyNameSuffix(entity)
   203     suffix = self._logic.getKeySuffix(entity)
   198 
   204 
   199     # redirect to (possibly new) location of the entity
   205     # redirect to (possibly new) location of the entity
   200     # (causes 'Profile saved' message to be displayed)
   206     # (causes 'Profile saved' message to be displayed)
   201     return helper.responses.redirectToChangedSuffix(
   207     return helper.responses.redirectToChangedSuffix(
   202         request, suffix, suffix,
   208         request, suffix, suffix,
   204 
   210 
   205   def editGet(self, request, entity, context):
   211   def editGet(self, request, entity, context):
   206     """Same as edit, but on GET
   212     """Same as edit, but on GET
   207     """
   213     """
   208 
   214 
   209     suffix = self._logic.constructKeyNameSuffix(entity)
   215     suffix = self._logic.getKeySuffix(entity)
   210 
   216 
   211     # Remove the params from the request, this is relevant only if
   217     # Remove the params from the request, this is relevant only if
   212     # someone bookmarked a POST page.
   218     # someone bookmarked a POST page.
   213     is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
   219     is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
   214     if request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME):
   220     if request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME):
   351       entity: the entity that is used
   357       entity: the entity that is used
   352       context: the context to be used
   358       context: the context to be used
   353       form: the form that will be used
   359       form: the form that will be used
   354     """
   360     """
   355 
   361 
   356     suffix = self._logic.constructKeyNameSuffix(entity)
   362     suffix = self._logic.getKeySuffix(entity)
   357 
   363 
   358     context['form'] = form
   364     context['form'] = form
   359     context['entity'] = entity
   365     context['entity'] = entity
   360     context['entity_suffix'] = suffix
   366     context['entity_suffix'] = suffix
   361     context['entity_type'] = self._params['name']
   367     context['entity_type'] = self._params['name']