def save_changes(self): """Save the changes back to the database. This also adds a redirect if the slug changes. """ old_slug = self.category.slug forms.set_fields(self.category, self.data, 'name', 'description') if self.data['slug']: self.category.slug = self.data['slug'] elif not self.category.slug: self.category.set_auto_slug() if old_slug != self.category.slug: register_redirect(old_slug, self.category.slug)
def _set_common_attributes(self, user): forms.set_fields(user, self.data, 'www', 'real_name', 'description', 'display_name', 'is_author') bind_privileges(user.own_privileges, self.data['privileges']) bound_groups = set(g.name for g in user.groups) choosen_groups = set(self.data['groups']) group_mapping = dict((g.name, g) for g in Group.query.all()) # delete groups for group in (bound_groups - choosen_groups): user.groups.remove(group_mapping[group]) # and add new groups for group in (choosen_groups - bound_groups): user.groups.append(group_mapping[group])
def save_changes(self): """Save the changes back to the database.""" old_parser = self.comment.parser forms.set_fields(self.comment, self.data, 'pub_date', 'parser', 'blocked_msg') if (self.data['text'] != self.comment.text or self.data['parser'] != old_parser): self.comment.text = self.data['text'] # update status if self.data['blocked']: if not self.comment.blocked: self.comment.status = COMMENT_BLOCKED_USER else: self.comment.status = COMMENT_MODERATED # only apply these if the comment is not anonymous if self.comment.anonymous: forms.set_fields(self.comment, self.data, 'author', 'email', 'www')
def save_changes(self): """Save the changes back to the database. This also adds a redirect if the slug changes. """ if not self.data['pub_date']: # If user deleted publication timestamp, make a new one. self.data['pub_date'] = datetime.utcnow() old_slug = self.post.slug old_parser = self.post.parser forms.set_fields(self.post, self.data, 'title', 'author', 'parser') if (self.data['text'] != self.post.text or self.data['parser'] != old_parser): self.post.text = self.data['text'] add_redirect = self.post.is_published and old_slug != self.post.slug self.post.touch_times(self.data['pub_date']) self.post.bind_slug(self.data['slug']) self._set_common_attributes(self.post) if add_redirect: register_redirect(old_slug, self.post.slug)
def _set_common_attributes(self, group): forms.set_fields(group, self.data) bind_privileges(group.privileges, self.data['privileges'])
def _set_common_attributes(self, post): forms.set_fields(post, self.data, 'comments_enabled', 'pings_enabled', 'status') post.bind_categories(self.data['categories']) post.bind_tags(self.data['tags'])