def take_punitive_actions(request, form, report, user): message_body = "" # The bulk of this action is running through all of the different # punitive actions that a moderator could take. if u"takeaway" in form.action_to_resolve.data: for privilege_name in form.take_away_privileges.data: take_away_privileges(user.username, privilege_name) form.resolution_content.data += _(u"\n{mod} took away {user}'s {privilege} privileges.").format( mod=request.user.username, user=user.username, privilege=privilege_name ) # If the moderator elects to ban the user, a new instance of user_ban # will be created. if u"userban" in form.action_to_resolve.data: user_ban = ban_user( form.targeted_user.data, expiration_date=form.user_banned_until.data, reason=form.why_user_was_banned.data ) Session.add(user_ban) form.resolution_content.data += _(u"\n{mod} banned user {user} {expiration_date}.").format( mod=request.user.username, user=user.username, expiration_date=( _("until {date}").format(date=form.user_banned_until.data) if form.user_banned_until.data else _("indefinitely") ), ) # If the moderator elects to send a warning message. An email will be # sent to the email address given at sign up if u"sendmessage" in form.action_to_resolve.data: message_body = form.message_to_user.data form.resolution_content.data += _(u"\n{mod} sent a warning email to the {user}.").format( mod=request.user.username, user=user.username ) if u"delete" in form.action_to_resolve.data and report.is_comment_report(): deleted_comment = report.obj() Session.delete(deleted_comment) form.resolution_content.data += _(u"\n{mod} deleted the comment.").format(mod=request.user.username) elif u"delete" in form.action_to_resolve.data and report.is_media_entry_report(): deleted_media = report.obj() deleted_media.delete() form.resolution_content.data += _(u"\n{mod} deleted the media entry.").format(mod=request.user.username) report.archive(resolver_id=request.user.id, resolved=datetime.now(), result=form.resolution_content.data) Session.add(report) Session.commit() if message_body: send_email( mg_globals.app_config["email_sender_address"], [user.email], _("Warning from") + "- {moderator} ".format(moderator=request.user.username), message_body, ) return redirect(request, "mediagoblin.moderation.users_detail", user=user.username)
def clean_orphan_tags(commit=True): """Search for unused MediaTags and delete them""" q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id == None) for t in q1: Session.delete(t) # The "let the db do all the work" version: # q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None) # q2 = Session.query(Tag).filter(Tag.id.in_(q1)) # q2.delete(synchronize_session = False) if commit: Session.commit()
def clean_orphan_tags(commit=True): """Search for unused MediaTags and delete them""" q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None) for t in q1: Session.delete(t) # The "let the db do all the work" version: # q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None) # q2 = Session.query(Tag).filter(Tag.id.in_(q1)) # q2.delete(synchronize_session = False) if commit: Session.commit()
def remove_collection_item(collection_item, commit=True): collection = collection_item.in_collection collection.items = collection.items - 1 Session.delete(collection_item) Session.add(collection) hook_runall('collection_remove_media', collection_item=collection_item) if commit: Session.commit()
def featured_media_panel(request): """ This is a new administrator panel to manage featured media. This is an entirely optional panel, as there are other ways to manage it, but this way gives the admin more control. """ form = archivalook_forms.FeaturedMediaList(request.form) if request.method == 'POST' and form.validate(): featured_media = split_featured_media_list(form.box_content.data) previous_features = FeaturedMedia.query.all() for index, (media_entry, display_type) in enumerate(featured_media): target = FeaturedMedia.query.filter( FeaturedMedia.media_entry == media_entry).first() # If this media was already featured, we don't have to create a new # feature, we just have to edit the old one's values if target is not None: target.order = index target.display_type = display_type previous_features.remove(target) Session.add(target) else: new_feature = FeaturedMedia( media_entry=media_entry, display_type=display_type, order=index) Session.add(new_feature) [Session.delete(feature) for feature in previous_features] Session.commit() form.box_content.data = create_featured_media_textbox() return render_to_response( request, 'archivalook/feature.html', {'form' : form})
def featured_media_panel(request): """ This is a new administrator panel to manage featured media. This is an entirely optional panel, as there are other ways to manage it, but this way gives the admin more control. """ form = archivalook_forms.FeaturedMediaList(request.form) if request.method == 'POST' and form.validate(): featured_media = split_featured_media_list(form.box_content.data) previous_features = FeaturedMedia.query.all() for index, (media_entry, display_type) in enumerate(featured_media): target = FeaturedMedia.query.filter( FeaturedMedia.media_entry == media_entry).first() # If this media was already featured, we don't have to create a new # feature, we just have to edit the old one's values if target is not None: target.order = index target.display_type = display_type previous_features.remove(target) Session.add(target) else: new_feature = FeaturedMedia(media_entry=media_entry, display_type=display_type, order=index) Session.add(new_feature) [Session.delete(feature) for feature in previous_features] Session.commit() form.box_content.data = create_featured_media_textbox() return render_to_response(request, 'archivalook/feature.html', {'form': form})
def take_punitive_actions(request, form, report, user): message_body = '' # The bulk of this action is running through all of the different # punitive actions that a moderator could take. if u'takeaway' in form.action_to_resolve.data: for privilege_name in form.take_away_privileges.data: take_away_privileges(user.username, privilege_name) form.resolution_content.data += \ u"\n{mod} took away {user}\'s {privilege} privileges.".format( mod=request.user.username, user=user.username, privilege=privilege_name) # If the moderator elects to ban the user, a new instance of user_ban # will be created. if u'userban' in form.action_to_resolve.data: user_ban = ban_user(form.targeted_user.data, expiration_date=form.user_banned_until.data, reason=form.why_user_was_banned.data) Session.add(user_ban) form.resolution_content.data += \ u"\n{mod} banned user {user} {expiration_date}.".format( mod=request.user.username, user=user.username, expiration_date = ( "until {date}".format(date=form.user_banned_until.data) if form.user_banned_until.data else "indefinitely" ) ) # If the moderator elects to send a warning message. An email will be # sent to the email address given at sign up if u'sendmessage' in form.action_to_resolve.data: message_body = form.message_to_user.data form.resolution_content.data += \ u"\n{mod} sent a warning email to the {user}.".format( mod=request.user.username, user=user.username) if u'delete' in form.action_to_resolve.data and \ report.is_comment_report(): deleted_comment = report.comment Session.delete(deleted_comment) form.resolution_content.data += \ u"\n{mod} deleted the comment.".format( mod=request.user.username) elif u'delete' in form.action_to_resolve.data and \ report.is_media_entry_report(): deleted_media = report.media_entry deleted_media.delete() form.resolution_content.data += \ u"\n{mod} deleted the media entry.".format( mod=request.user.username) report.archive(resolver_id=request.user.id, resolved=datetime.now(), result=form.resolution_content.data) Session.add(report) Session.commit() if message_body: send_email( mg_globals.app_config['email_sender_address'], [user.email], _('Warning from') + '- {moderator} '.format(moderator=request.user.username), message_body) return redirect(request, 'mediagoblin.moderation.users_detail', user=user.username)