Exemplo n.º 1
0
def section_save(section_key_us=None):
    form = SectionFormAdmin()

    # form validation
    if not form.validate_on_submit():
        return "VALIDATION_ERROR", 400

    # get and validate parent section
    if form.parent_section.data == '/':
        parent_section_key = None
    else:
        parent_section = ndb.Key(
            urlsafe=form.parent_section.data).get() or abort(404)
        parent_section_key = parent_section.key

    # section instance
    if section_key_us:
        # edit
        # print 'admin section save EDIT'
        section = ndb.Key(urlsafe=section_key_us).get() or abort(404)
    else:
        # new
        # print 'admin section save NEW'
        section = Section()

    # update data
    g.cache.clear()
    section.parent_section = parent_section_key
    section.set_name(form.name.data, g.language)
    section.put()
    return 'ok'
Exemplo n.º 2
0
    def post(self):
        item = None
        vals = {}
        try:
            # get all the incoming values
            path = self.request.get('path').strip()
            title = self.request.get('title').strip()
            description = self.request.get('description')
            type = self.request.get('type')
            layout = self.request.get('layout')
            attribute_raw = util.make_attr_raw_string(
                {
                    'sitemap-entry' : self.request.get('sitemap_entry'),
                    'contact-form'  : self.request.get('contact_form'),
                    'sitefeed'      : self.request.get('sitefeed'),
                    }
                ).strip()

            # some pre-processing of the input params
            description_html = util.render(description, type)

            if self.request.get('key'):
                item = Section.get( self.request.get('key') )
                item.path = path
                item.title = title
                item.description = description
                item.description_html = description_html
                item.type = type
                item.layout = layout
                item.attribute_raw = attribute_raw
            else:
                item = Section(
                    path = path,
                    title = title,
                    description = description,
                    description_html = description_html,
                    type = type,
                    layout = layout,
                    attribute_raw = attribute_raw,
                    )

            # update and save this section
            item.set_derivatives()
            item.put()
            # once saved, add the section to the two task queues
            item.regenerate()
            self.redirect('.')
        except Exception, err:
            vals['item'] = self.request.POST
            vals['err'] = err
            vals['types'] = models.type_choices
            vals['layouts'] = models.layout_choices
            self.template( 'section-form.html', vals, 'admin' );