def remove(userid, charid): ownerid = define.get_ownerid(charid=charid) if userid not in staff.MODS and userid != ownerid: raise WeasylError("InsufficientPermissions") query = define.execute("UPDATE character SET settings = settings || 'h'" " WHERE charid = %i AND settings !~ 'h'" " RETURNING charid", [charid]) if query: welcome.character_remove(charid) return ownerid
def edit(userid, character, friends_only): query = define.execute( "SELECT userid, settings FROM character WHERE charid = %i", [character.charid], options="single") if not query or "h" in query[1]: raise WeasylError("Unexpected") elif userid != query[0] and userid not in staff.MODS: raise WeasylError("InsufficientPermissions") elif not character.char_name: raise WeasylError("characterNameInvalid") elif not character.rating: raise WeasylError("Unexpected") profile.check_user_rating_allowed(userid, character.rating) # Assign settings settings = [query[1].replace("f", "")] settings.append("f" if friends_only else "") settings = "".join(settings) if "f" in settings: welcome.character_remove(character.charid) define.execute( """ UPDATE character SET (char_name, age, gender, height, weight, species, content, rating, settings) = ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, '%s') WHERE charid = %i """, [ character.char_name, character.age, character.gender, character.height, character.weight, character.species, character.content, character.rating.code, settings, character.charid ]) if userid != query[0]: from weasyl import moderation moderation.note_about( userid, query[0], 'The following character was edited:', '- ' + text.markdown_link( character.char_name, '/character/%s?anyway=true' % (character.charid, )))
def edit(userid, character, friends_only): query = define.engine.execute("SELECT userid, settings FROM character WHERE charid = %(id)s", id=character.charid).first() if not query or "h" in query[1]: raise WeasylError("Unexpected") elif userid != query[0] and userid not in staff.MODS: raise WeasylError("InsufficientPermissions") elif not character.char_name: raise WeasylError("characterNameInvalid") elif not character.rating: raise WeasylError("Unexpected") profile.check_user_rating_allowed(userid, character.rating) # Assign settings settings = query[1].replace("f", "") if friends_only: settings += "f" welcome.character_remove(character.charid) ch = define.meta.tables["character"] define.engine.execute( ch.update() .where(ch.c.charid == character.charid) .values({ 'char_name': character.char_name, 'age': character.age, 'gender': character.gender, 'height': character.height, 'weight': character.weight, 'species': character.species, 'content': character.content, 'rating': character.rating, 'settings': settings, }) ) if userid != query[0]: from weasyl import moderation moderation.note_about( userid, query[0], 'The following character was edited:', '- ' + text.markdown_link(character.char_name, '/character/%s?anyway=true' % (character.charid,)))
def edit(userid, character, friends_only): query = define.execute("SELECT userid, settings FROM character WHERE charid = %i", [character.charid], options="single") if not query or "h" in query[1]: raise WeasylError("Unexpected") elif userid != query[0] and userid not in staff.MODS: raise WeasylError("InsufficientPermissions") elif not character.char_name: raise WeasylError("characterNameInvalid") elif not character.rating: raise WeasylError("Unexpected") profile.check_user_rating_allowed(userid, character.rating) # Assign settings settings = [query[1].replace("f", "")] settings.append("f" if friends_only else "") settings = "".join(settings) if "f" in settings: welcome.character_remove(character.charid) define.execute( """ UPDATE character SET (char_name, age, gender, height, weight, species, content, rating, settings) = ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, '%s') WHERE charid = %i """, [character.char_name, character.age, character.gender, character.height, character.weight, character.species, character.content, character.rating.code, settings, character.charid]) if userid != query[0]: from weasyl import moderation moderation.note_about( userid, query[0], 'The following character was edited:', '- ' + text.markdown_link(character.char_name, '/character/%s?anyway=true' % (character.charid,)))
def hidecharacter(charid): d.execute("UPDATE character SET settings = settings || 'h' WHERE charid = %i AND settings !~ 'h'", [charid]) welcome.character_remove(charid)