def setParent(self, page_id, parent_id): page_id = int(page_id) parent_id = int(parent_id) if parent_id == 0: parent_id = None current_page = Model.Pages.getPageById(page_id) if parent_id: parent_page = Model.Pages.getPageById(parent_id) #Make sure the current page isn't a parent for that parent parents = parent_page.getParentList() for pa in parents: if pa.id == page_id: raise amiweb.AppError( "You can't changes a parents child to be a parent of the parent... I.e. recursion problem!" ) old_parent = current_page.getParent() Model.Pages.setParent(page_id, parent_id) #Expire havoc AmiCache.expireCache(page_id) if old_parent: AmiCache.expireCache(old_parent.id) if parent_id: AmiCache.expireCache(parent_id) return "ok"
def labelAdd(self, ident, name): blog = BlogModel.getBlogByIdent(ident) if not blog: blog = BlogModel.addBlog(ident) try: return BlogLabelModel.add(blog.id, name).toJSON() except IntegrityError: raise amiweb.AppError('A label is already found with the same name.')
def diffRevisions(self, page_id, rev1, rev2): obj_rev1 = Model.PageLogs.getLogByRev(page_id, rev1) obj_rev2 = Model.PageLogs.getLogByRev(page_id, rev2) if obj_rev1 and obj_rev2: result = diff.textDiff(obj_rev1.text, obj_rev2.text) result = result.replace("<", "<").replace(">", ">") result = re.sub("<(/?(ins|del).*?)>", r"<\1>", result) return result #result.replace('\n', '<br />') else: errors = [] if not obj_rev1: errors.append("Revision %s not found" % rev1) if not obj_rev2: errors.append("Revision %s not found" % rev2) raise amiweb.AppError("\n".join(errors))
def checkCurrentPagePermissions(self): page_id = getCurrentPage() if not self.checkPagePremission(page_id): raise amiweb.AppError("You don't have permissions for this!")
def add(self, name, order, menu_id): item = Model.MenuItems.add(name, order, menu_id) try: return item.toJSON() except: raise amiweb.AppError("Error encoutered")
def checkAdminPermission(self): if not Users.isAdmin(): raise amiweb.AppError("You don't have admin privilege.")
def add(self, username, password, type): try: item = UserModel.Users.add(username, password, type) return item.toJSON() except amidb.IntegrityError: raise amiweb.AppError("The item was already added.")
def add(self, name): try: item = UserModel.Groups.add(name) return item.toJSON() except amidb.IntegrityError: raise amiweb.AppError("The item was already added.")
def labelUpdate(self, id, name): AmiCache.expireCurrentPage() try: return BlogLabelModel.update(id, name).toJSON() except IntegrityError: raise amiweb.AppError('A label is already found with the same name.')