def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CLASSIFIER).validated(data, update=True) classifier = self.model if 'name' in data: from mini_fiction.models import Classifier exist_classifier = Classifier.get(name=data['name']) if exist_classifier and exist_classifier.id != classifier.id: raise ValidationError( {'name': [lazy_gettext('Classifier already exists')]}) changed_fields = set() for key, value in data.items(): if getattr(classifier, key) != value: setattr(classifier, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=classifier, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return classifier
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(STATIC_PAGE).validated(data, update=True) staticpage = self.model if not author.is_superuser and (staticpage.is_template or data.get('is_template')): raise ValidationError({'is_template': [lazy_gettext('Access denied')]}) if ('name' in data and data['name'] != staticpage.name) or ('lang' in data and data['lang'] != staticpage.lang): raise ValidationError({ 'name': [lazy_gettext('Cannot change primary key')], 'lang': [lazy_gettext('Cannot change primary key')], }) if data.get('is_template', staticpage.is_template) and 'content' in data: self.check_renderability(author, data.get('name', staticpage.name), data['content']) changed_fields = set() for key, value in data.items(): if getattr(staticpage, key) != value: setattr(staticpage, key, value) changed_fields |= {key,} if changed_fields: AdminLog.bl.create( user=author, obj=staticpage, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return staticpage
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(LOGOPIC_FOR_UPDATE).validated(data, update=True) logopic = self.model changed_fields = set() for key, value in data.items(): if key == 'picture': if value: self.set_picture_data(value) changed_fields |= {'picture',} else: if key == 'original_link_label': value = value.replace('\r', '') if getattr(logopic, key) != value: setattr(logopic, key, value) changed_fields |= {key,} if changed_fields: logopic.updated_at = datetime.utcnow() current_app.cache.delete('logopics') AdminLog.bl.create( user=author, obj=logopic, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return logopic
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(TAG_CATEGORY).validated(data, update=True) tag_category = self.model if 'name' in data: from mini_fiction.models import TagCategory exist_tag_category = TagCategory.get(name=data['name']) if exist_tag_category and exist_tag_category.id != tag_category.id: raise ValidationError( {'name': [lazy_gettext('Tag category already exists')]}) changed_fields = set() for key, value in data.items(): if getattr(tag_category, key) != value: setattr(tag_category, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=tag_category, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return tag_category
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CATEGORY).validated(data, update=True) category = self.model if 'name' in data: from mini_fiction.models import Category exist_category = Category.get(name=data['name']) if exist_category and exist_category.id != category.id: raise ValidationError({'name': [lazy_gettext('Category already exists')]}) changed_fields = set() for key, value in data.items(): if getattr(category, key) != value: setattr(category, key, value) changed_fields |= {key,} if changed_fields: AdminLog.bl.create( user=author, obj=category, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return category
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CHARACTER_GROUP).validated(data, update=True) group = self.model if 'name' in data: from mini_fiction.models import CharacterGroup exist_group = CharacterGroup.get(name=data['name']) if exist_group and exist_group.id != group.id: raise ValidationError( {'name': [lazy_gettext('Group already exists')]}) changed_fields = set() for key, value in data.items(): if getattr(group, key) != value: setattr(group, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=group, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return group
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CHARACTER_GROUP).validated(data, update=True) group = self.model if 'name' in data: from mini_fiction.models import CharacterGroup exist_group = CharacterGroup.get(name=data['name']) if exist_group and exist_group.id != group.id: raise ValidationError({'name': [lazy_gettext('Group already exists')]}) changed_fields = set() for key, value in data.items(): if getattr(group, key) != value: setattr(group, key, value) changed_fields |= {key,} if changed_fields: AdminLog.bl.create( user=author, obj=group, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return group
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CHARACTER_FOR_UPDATE).validated(data, update=True) character = self.model errors = {} if 'name' in data: from mini_fiction.models import Character exist_character = Character.get(name=data['name']) if exist_character and exist_character.id != character.id: errors['name'] = [lazy_gettext('Character already exists')] if 'group' in data: from mini_fiction.models import CharacterGroup group = CharacterGroup.get(id=data['group']) if not group: errors['group'] = [lazy_gettext('Group not found')] else: group = None if errors: raise ValidationError(errors) changed_fields = set() if data.get('picture'): picture = self.validate_and_get_picture_data(data['picture']) else: picture = None for key, value in data.items(): if key == 'picture': if picture is not None: self.set_picture_data(picture) changed_fields |= {'picture',} elif key == 'group': if character.group.id != value: setattr(character, key, value) changed_fields |= {key,} elif getattr(character, key) != value: setattr(character, key, value) changed_fields |= {key,} if changed_fields: AdminLog.bl.create( user=author, obj=character, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return character
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(NEWS_ITEM).validated(data, update=True) newsitem = self.model if not author.is_superuser and (newsitem.is_template or data.get('is_template')): raise ValidationError( {'is_template': [lazy_gettext('Access denied')]}) if 'name' in data: from mini_fiction.models import NewsItem exist_newsitem = NewsItem.get(name=data['name']) if exist_newsitem and exist_newsitem.id != newsitem.id: raise ValidationError( {'name': [lazy_gettext('Page already exists')]}) if data.get('is_template', newsitem.is_template) and 'content' in data: self.check_renderability(author, data.get('name', newsitem.name), data['content']) if data.get('show') and not newsitem.show: self.hide_shown_newsitem() changed_fields = set() for key, value in data.items(): if getattr(newsitem, key) != value: setattr(newsitem, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=newsitem, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return newsitem
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(STATIC_PAGE).validated(data, update=True) staticpage = self.model if not author.is_superuser and (staticpage.is_template or data.get('is_template')): raise ValidationError( {'is_template': [lazy_gettext('Access denied')]}) if ('name' in data and data['name'] != staticpage.name) or ( 'lang' in data and data['lang'] != staticpage.lang): raise ValidationError({ 'name': [lazy_gettext('Cannot change primary key')], 'lang': [lazy_gettext('Cannot change primary key')], }) if data.get('is_template', staticpage.is_template) and 'content' in data: self.check_renderability(author, data.get('name', staticpage.name), data['content']) changed_fields = set() for key, value in data.items(): if getattr(staticpage, key) != value: setattr(staticpage, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=staticpage, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return staticpage
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(HTML_BLOCK).validated(data, update=True) htmlblock = self.model if not author.is_superuser and (htmlblock.is_template or data.get('is_template')): raise ValidationError({'is_template': [lazy_gettext('Access denied')]}) if ('name' in data and data['name'] != htmlblock.name) or ('lang' in data and data['lang'] != htmlblock.lang): raise ValidationError({ 'name': [lazy_gettext('Cannot change primary key')], 'lang': [lazy_gettext('Cannot change primary key')], }) if data.get('is_template', htmlblock.is_template) and 'content' in data: self.check_renderability(author, data.get('name', htmlblock.name), data['content']) changed_fields = set() old_name = htmlblock.name for key, value in data.items(): if getattr(htmlblock, key) != value: setattr(htmlblock, key, value) changed_fields |= {key,} later(self.clear_cache, old_name) if htmlblock.name != old_name: later(self.clear_cache, htmlblock.name) if changed_fields: AdminLog.bl.create( user=author, obj=htmlblock, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return htmlblock
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(LOGOPIC_FOR_UPDATE).validated(data, update=True) logopic = self.model changed_fields = set() for key, value in data.items(): if key == 'picture': if value: self.set_picture_data(value) changed_fields |= { 'picture', } else: if key == 'original_link_label': value = value.replace('\r', '') if getattr(logopic, key) != value: setattr(logopic, key, value) changed_fields |= { key, } if changed_fields: logopic.updated_at = datetime.utcnow() current_app.cache.delete('logopics') AdminLog.bl.create( user=author, obj=logopic, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return logopic
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(NEWS_ITEM).validated(data, update=True) newsitem = self.model if not author.is_superuser and (newsitem.is_template or data.get('is_template')): raise ValidationError({'is_template': [lazy_gettext('Access denied')]}) if 'name' in data: from mini_fiction.models import NewsItem exist_newsitem = NewsItem.get(name=data['name']) if exist_newsitem and exist_newsitem.id != newsitem.id: raise ValidationError({'name': [lazy_gettext('Page already exists')]}) if data.get('is_template', newsitem.is_template) and 'content' in data: self.check_renderability(author, data.get('name', newsitem.name), data['content']) if data.get('show') and not newsitem.show: self.hide_shown_newsitem() changed_fields = set() for key, value in data.items(): if getattr(newsitem, key) != value: setattr(newsitem, key, value) changed_fields |= {key,} if changed_fields: AdminLog.bl.create( user=author, obj=newsitem, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return newsitem
def update(self, author, data): from mini_fiction.models import AdminLog data = Validator(CHARACTER_FOR_UPDATE).validated(data, update=True) character = self.model errors = {} if 'name' in data: from mini_fiction.models import Character exist_character = Character.get(name=data['name']) if exist_character and exist_character.id != character.id: errors['name'] = [lazy_gettext('Character already exists')] if 'group' in data: from mini_fiction.models import CharacterGroup group = CharacterGroup.get(id=data['group']) if not group: errors['group'] = [lazy_gettext('Group not found')] else: group = None if errors: raise ValidationError(errors) changed_fields = set() if data.get('picture'): picture = self.validate_and_get_picture_data(data['picture']) else: picture = None for key, value in data.items(): if key == 'picture': if picture is not None: self.set_picture_data(picture) changed_fields |= { 'picture', } elif key == 'group': if character.group.id != value: setattr(character, key, value) changed_fields |= { key, } elif getattr(character, key) != value: setattr(character, key, value) changed_fields |= { key, } if changed_fields: AdminLog.bl.create( user=author, obj=character, action=AdminLog.CHANGE, fields=sorted(changed_fields), ) return character