app/soc/views/models/base.py
changeset 435 829fe8302a8b
parent 429 e50e18936f06
child 438 af082c92ddda
equal deleted inserted replaced
434:a4fc430fefac 435:829fe8302a8b
    24 
    24 
    25 from django import http
    25 from django import http
    26 from django.utils.translation import ugettext_lazy
    26 from django.utils.translation import ugettext_lazy
    27 
    27 
    28 import soc.logic
    28 import soc.logic
    29 import soc.logic.dicts
       
    30 import soc.logic.out_of_band
    29 import soc.logic.out_of_band
    31 import soc.views.helper.lists
    30 import soc.views.helper.lists
    32 import soc.views.helper.responses
    31 import soc.views.helper.responses
    33 import soc.views.out_of_band
    32 import soc.views.out_of_band
    34 
    33 
   104     context = helper.responses.getUniversalContext(request)
   103     context = helper.responses.getUniversalContext(request)
   105     context['page'] = page
   104     context['page'] = page
   106     entity = None
   105     entity = None
   107 
   106 
   108     try:
   107     try:
   109       entity = self._logic.getIfFields(**kwargs)
   108       key_fields = self._logic.getKeyFieldsFromDict(kwargs)
       
   109       entity = self._logic.getIfFields(key_fields)
   110     except soc.logic.out_of_band.ErrorResponse, error:
   110     except soc.logic.out_of_band.ErrorResponse, error:
   111       template = self._params['public_template']
   111       template = self._params['public_template']
   112       return simple.errorResponse(request, page, error, template, context)
   112       return simple.errorResponse(request, page, error, template, context)
   113 
   113 
   114     if not entity:
   114     if not entity:
   158     context = helper.responses.getUniversalContext(request)
   158     context = helper.responses.getUniversalContext(request)
   159     context['page'] = page
   159     context['page'] = page
   160     entity = None
   160     entity = None
   161 
   161 
   162     try:
   162     try:
   163       entity = self._logic.getIfFields(**kwargs)
   163       key_fields = self._logic.getKeyFieldsFromDict(kwargs)
       
   164       entity = self._logic.getIfFields(key_fields)
   164     except soc.logic.out_of_band.ErrorResponse, error:
   165     except soc.logic.out_of_band.ErrorResponse, error:
   165       template = self._params['public_template']
   166       template = self._params['public_template']
   166       error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
   167       error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
   167           'entity_type_lower' : self._params['name'].lower(),
   168           'entity_type_lower' : self._params['name'].lower(),
   168           'entity_type' : self._params['name'],
   169           'entity_type' : self._params['name'],
   189 
   190 
   190     fields = self.collectCleanedFields(form)
   191     fields = self.collectCleanedFields(form)
   191 
   192 
   192     self._editPost(request, entity, fields)
   193     self._editPost(request, entity, fields)
   193 
   194 
   194     keys = self._logic.getKeyFieldNames()
   195     key_fields = self._logic.getKeyFieldsFromDict(fields)
   195     values = self._logic.getKeyValuesFromFields(fields)
   196     entity = self._logic.updateOrCreateFromFields(fields, key_fields)
   196     kwargs = dicts.zip(keys, values)
       
   197     entity = self._logic.updateOrCreateFromFields(fields, **kwargs)
       
   198 
   197 
   199     if not entity:
   198     if not entity:
   200       return http.HttpResponseRedirect('/')
   199       return http.HttpResponseRedirect('/')
   201 
   200 
   202     params = self._params['edit_params']
   201     params = self._params['edit_params']
   291     context = helper.responses.getUniversalContext(request)
   290     context = helper.responses.getUniversalContext(request)
   292     context['page'] = page
   291     context['page'] = page
   293     entity = None
   292     entity = None
   294 
   293 
   295     try:
   294     try:
   296       entity = self._logic.getIfFields(**kwargs)
   295       key_fields = self._logic.getKeyFieldsFromKwargs(kwargs)
       
   296       entity = self._logic.getIfFields(key_fields)
   297     except soc.logic.out_of_band.ErrorResponse, error:
   297     except soc.logic.out_of_band.ErrorResponse, error:
   298       template = self._params['edit_template']
   298       template = self._params['edit_template']
   299       error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
   299       error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
   300           'entity_type_lower' : self._params['name'].lower(),
   300           'entity_type_lower' : self._params['name'].lower(),
   301           'entity_type' : self._params['name'],
   301           'entity_type' : self._params['name'],