def post(self, kind, key): obj = entity_or_404(key) form_class = self.admin.form_for(kind) form = form_class(self.request.POST, instance=obj) if form.is_valid(): # A short reference for form.cleaned_data data = form.cleaned_data # Get the form to update the object without saving it to the # datastore, so we can work around a bug below. obj = form.save(commit=False) # UGLY HACK: Due to App Engine SDK Issue 599, fields that should # be set to None on form.save() (e.g. setting a ReferenceProperty # to None using a dropdown) will not be updated. So we might have # to save them twice. More info: # http://code.google.com/p/googleappengine/issues/detail?id=599 for field, value in data.iteritems(): if value is None and getattr(obj, field) is not None: logging.info("Working around App Engine bug 599") setattr(obj, field, None) # Now, finally, save the object and run any hooks self.admin.pre_save(obj) obj.put() self.admin.post_save(obj) self.redirect(".") else: return self.get(kind, key, form, 400)
def post(self, kind, key): obj = entity_or_404(key) form_class = self.admin.form_for(kind) form = form_class(self.request.POST, instance=obj) if form.is_valid(): # A short reference for form.cleaned_data data = form.cleaned_data # Get the form to update the object without saving it to the # datastore, so we can work around a bug below. obj = form.save(commit=False) # UGLY HACK: Due to App Engine SDK Issue 599, fields that should # be set to None on form.save() (e.g. setting a ReferenceProperty # to None using a dropdown) will not be updated. So we might have # to save them twice. More info: # http://code.google.com/p/googleappengine/issues/detail?id=599 for field, value in data.iteritems(): if value is None and getattr(obj, field) is not None: logging.info('Working around App Engine bug 599') setattr(obj, field, None) # Now, finally, save the object and run any hooks self.admin.pre_save(obj) obj.put() self.admin.post_save(obj) self.redirect('.') else: return self.get(kind, key, form, 400)
def get(self, kind, key, form=None, status=200): obj = entity_or_404(key) form_class = self.admin.form_for(kind) if form is None: form = form_class(instance=obj) # Every item template gets the following context context = {"type": kind, "form": form, "obj": obj} # Add in any extra context for this item context.update(self.admin.extra_context(obj)) # Figure out which default item template we should use based on # whether this item can have children. if kind in self.admin.parents: item_template = "item_with_children" context["children"] = self.admin.get_children(obj) else: item_template = "item" # First try a custom template for the given item, fall back on the # generic item template templates = ("admin/%s.html" % kind.lower(), "admin/%s.html" % item_template) self.render(templates, context, status=status)
def get(self, kind, key, form=None, status=200): obj = entity_or_404(key) form_class = self.admin.form_for(kind) if form is None: form = form_class(instance=obj) # Every item template gets the following context context = { 'type': kind, 'form': form, 'obj': obj, } # Add in any extra context for this item context.update(self.admin.extra_context(obj)) # Figure out which default item template we should use based on # whether this item can have children. if kind in self.admin.parents: item_template = 'item_with_children' context['children'] = self.admin.get_children(obj) else: item_template = 'item' # First try a custom template for the given item, fall back on the # generic item template templates = ('admin/%s.html' % kind.lower(), 'admin/%s.html' % item_template) self.render(templates, context, status=status)