Python google.appengine.ext.webapp.template() Examples

The following are code examples for showing how to use google.appengine.ext.webapp.template(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: cocoslive   Author: ricardoquesada   File:    GNU General Public License v3.0 4 votes vote down vote up
def edit_instance(request, model_type, model_form_type,
                  edit_template, success_url, object_id, **kwargs):
  # pylint: disable-msg=R0913
  """Generic method to handle editing objects with Django forms.

    request: the http request
    model_type: the class of object being edited
    model_form_type: the form type to use for editing this object
    edit_template: the template to use for editing the object
    success_url: the URL to redirect the user to when the editing is succesful
    object_id: the ID of the object to edit, or None if creating a new object
    kwargs: additional data to be passed to the edit form

    A HTTP response, either a redirect to the success_url or the edit form.

  editing = False
  type_instance = None
  if object_id:
    editing = True
    type_instance = model_type.get_by_id(int(object_id))
    if type_instance is None:
      return http.HttpResponseNotFound('No object exists with key %r',

  form = model_form_type(data=request.POST or None, instance=type_instance)

  kwargs['form'] = form
  kwargs['type_instance'] = type_instance
  kwargs['editing'] = editing

  if not request.POST:
    return respond(request, edit_template, kwargs)

  errors = form.errors
  if not errors:
      type_instance =
    except ValueError, err:
      errors['__all__'] = unicode(err)