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'
def user_delete(user_key_us): user = ndb.Key(urlsafe=user_key_us).get() or abort(404) if user == current_user: return jsonify(result='ko', error='Cannot delete yourself!!') user.key.delete() return jsonify(result='ok')
def load_page_by_key(key_us): """ Load a page object starting from a key urlsafe string. """ # print 'load page by key' key = ndb.Key(urlsafe=key_us) r = Route.query(Route.page_key == key).get() or abort(404) p = Template(r.template_id).load_page(r.page_key) return p
def tree(): lang = request.args.get('lang', g.language) menu_tree = ndb.Key('MenuTree', lang).get() if menu_tree is None: menu_tree = {} else: menu_tree = menu_tree.tree return jsonify(results=menu_tree)
def tree(): lang = request.args.get('lang', g.language) sections_tree_entity = ndb.Key('SectionTree', lang).get() if sections_tree_entity: sections_tree = sections_tree_entity.tree else: sections_tree = {} return jsonify(results=sections_tree)
def weak_load_page_by_key(key_us): """ Load a page object starting from a key urlsafe string. Return None if page not found. """ # print 'weak load page by key' key = ndb.Key(urlsafe=key_us) r = Route.query(Route.page_key == key).get() if r is None: return r return Template(r.template_id).load_page(r.page_key)
def menu_switch(menu_key_us, menu_key_us_target): # target is 0, source is + 1 menu = ndb.Key(urlsafe=menu_key_us).get() or abort(404) menu_target = ndb.Key(urlsafe=menu_key_us_target).get() or abort(404) g.cache.clear() if menu.order == menu_target.order: menu_target.order += 1 menu_target.put() else: t = menu_target.order menu_target.order = menu.order menu.order = t menu.put() menu_target.put() deferred.defer(_menu_generate_tree, _countdown=3) return 'OK'
def menu_save(menu_key_us=None): form = MenuFormAdmin() # form validation if not form.validate_on_submit(): return "VALIDATION_ERROR", 400 # get and validate parent menu if form.parent_menu.data == '/': parent_menu_key = None else: parent_menu = ndb.Key( urlsafe=form.parent_menu.data).get() or abort(404) parent_menu_key = parent_menu.key # get and validate linked page if form.linked_page.data == '': # print 'LINKED NONE!' linked_page = None else: # pass linked_page = load_page_by_key(form.linked_page.data) # menu instance if menu_key_us: # edit menu = ndb.Key(urlsafe=menu_key_us).get() or abort(404) else: # new menu = Menu() # update data g.cache.clear() menu.parent_menu = parent_menu_key menu.set_linked_page(linked_page) menu.set_name(form.name.data, form.lang.data) menu.set_description(form.description.data, form.lang.data) menu.put() flash(_('Menu salvato con successo')) return 'ok'
def item_do(id): key = ndb.Key('Item', id) if request.method == 'DELETE': key.delete() return render({'deleted': id}) if request.method == 'GET': item = key.get() return render([item]) if request.method == 'PATCH': return item_create(key)
def menu_language_save(menu_key_us=None): form = MenuLangFormAdmin() if not form.validate_on_submit(): return "VALIDATION_ERROR", 400 menu = ndb.Key(urlsafe=menu_key_us).get() or abort(404) # update data g.cache.clear() menu.set_name(form.name.data, form.language.data) menu.set_description(form.description.data, form.language.data) menu.put() return 'ok'
def post(self, post_id): text = self.request.get('text', '') if len(text): Comment(text=text, post=ndb.Key(Post, int(post_id))).put() self.redirect('/post/' + post_id)
def section_get(section_key_us): s = ndb.Key(urlsafe=section_key_us).get() or abort(404) return jsonify(s.to_dict())
def section_delete(section_key_us): g.cache.clear() section = ndb.Key(urlsafe=section_key_us).get() or abort(404) section.key.delete() return 'ok'
def menu_get(menu_key_us): m = ndb.Key(urlsafe=menu_key_us).get() or abort(404) return jsonify(m.to_dict())
def users_delete(userkey): ndb.Key(urlsafe=userkey).delete() return 'OK'