def select_view_api(userid, journalid, anyway=False, increment_views=False): rating = d.get_rating(userid) journal = _select_journal_and_check( userid, journalid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) content = files.read(files.make_resource(userid, journalid, 'journal/submit')) return { 'journalid': journalid, 'title': journal['title'], 'owner': journal['username'], 'owner_login': d.get_sysname(journal['username']), 'owner_media': api.tidy_all_media( media.get_user_media(journal['userid'])), 'content': text.markdown(content), 'tags': searchtag.select(journalid=journalid), 'link': d.absolutify_url('/journal/%d/%s' % (journalid, text.slug_for(journal['title']))), 'type': 'journal', 'rating': ratings.CODE_TO_NAME[journal['rating']], 'views': journal['page_views'], 'favorites': favorite.count(journalid, 'journal'), 'comments': comment.count(journalid, 'journal'), 'favorited': favorite.check(userid, journalid=journalid), 'friends_only': 'f' in journal['settings'], 'posted_at': d.iso8601(journal['unixtime']), }
def select_view_api(userid, charid, anyway=False, increment_views=False): rating = define.get_rating(userid) query = _select_character_and_check( userid, charid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) login = define.get_sysname(query.username) return { 'charid': charid, 'owner': query.username, 'owner_login': login, 'owner_media': api.tidy_all_media(media.get_user_media(query.userid)), 'posted_at': define.iso8601(query.unixtime), 'title': query.char_name, 'age': query.age, 'gender': query.gender, 'height': query.height, 'weight': query.weight, 'species': query.species, 'content': text.markdown(query.content), 'rating': ratings.CODE_TO_NAME[query.rating], 'favorited': favorite.check(userid, charid=charid), 'views': query.page_views, 'friends_only': 'f' in query.settings, 'favorites': favorite.count(charid, 'character'), 'comments': comment.count(charid, 'character'), 'media': fake_media_items(charid, query.userid, login, query.settings, absolutify=True), 'tags': searchtag.select(charid=charid), 'type': 'character', 'link': define.absolutify_url('/character/%d/%s' % (charid, text.slug_for(query.char_name))), }
def select_view(userid, charid, rating, ignore=True, anyway=None): query = _select_character_and_check( userid, charid, rating=rating, ignore=ignore, anyway=anyway == 'anyway') login = define.get_sysname(query['username']) return { 'charid': charid, 'userid': query['userid'], 'username': query['username'], 'user_media': media.get_user_media(query['userid']), 'mine': userid == query['userid'], 'unixtime': query['unixtime'], 'title': query['char_name'], 'age': query['age'], 'gender': query['gender'], 'height': query['height'], 'weight': query['weight'], 'species': query['species'], 'content': query['content'], 'rating': query['rating'], 'settings': query['settings'], 'reported': report.check(charid=charid), 'favorited': favorite.check(userid, charid=charid), 'page_views': query['page_views'], 'friends_only': 'f' in query['settings'], 'hidden_submission': 'h' in query['settings'], 'fave_count': favorite.count(charid, 'character'), 'comments': comment.select(userid, charid=charid), 'sub_media': fake_media_items( charid, query['userid'], login, query['settings']), 'tags': searchtag.select(charid=charid), }
def select_view(userid, charid, rating, ignore=True, anyway=None): query = _select_character_and_check( userid, charid, rating=rating, ignore=ignore, anyway=anyway=='anyway') login = define.get_sysname(query.username) return { 'charid': charid, 'userid': query.userid, 'username': query.username, 'user_media': media.get_user_media(query.userid), 'mine': userid == query.userid, 'unixtime': query.unixtime, 'title': query.char_name, 'age': query.age, 'gender': query.gender, 'height': query.height, 'weight': query.weight, 'species': query.species, 'content': query.content, 'rating': query.rating, 'settings': query.settings, 'reported': report.check(charid=charid), 'favorited': favorite.check(userid, charid=charid), 'page_views': query.page_views, 'friends_only': 'f' in query.settings, 'hidden_submission': 'h' in query.settings, 'fave_count': favorite.count(charid, 'character'), 'comments': comment.select(userid, charid=charid), 'sub_media': fake_media_items(charid, query.userid, login, query.settings), 'tags': searchtag.select(charid=charid), }
def select_view(userid, charid, rating, ignore=True, anyway=None): query = define.execute(""" SELECT ch.userid, pr.username, ch.unixtime, ch.char_name, ch.age, ch.gender, ch.height, ch.weight, ch.species, ch.content, ch.rating, ch.settings, ch.page_views, pr.config FROM character ch INNER JOIN profile pr USING (userid) WHERE ch.charid = %i """, [charid], options=["single", "list"]) if query and userid in staff.MODS and anyway == "true": pass elif not query or "h" in query[11]: raise WeasylError("characterRecordMissing") elif query[10] > rating and ((userid != query[0] and userid not in staff.MODS) or define.is_sfw_mode()): raise WeasylError("RatingExceeded") elif "f" in query[11] and not frienduser.check(userid, query[0]): raise WeasylError("FriendsOnly") elif ignore and ignoreuser.check(userid, query[0]): raise WeasylError("UserIgnored") elif ignore and blocktag.check(userid, charid=charid): raise WeasylError("TagBlocked") if define.common_view_content(userid, charid, "char"): query[12] += 1 login = define.get_sysname(query[1]) return { "charid": charid, "userid": query[0], "username": query[1], "user_media": media.get_user_media(query[0]), "mine": userid == query[0], "unixtime": query[2], "title": query[3], "age": query[4], "gender": query[5], "height": query[6], "weight": query[7], "species": query[8], "content": query[9], "rating": query[10], "settings": query[11], "reported": report.check(charid=charid), "favorited": favorite.check(userid, charid=charid), "page_views": query[12], "friends_only": "f" in query[11], "hidden_submission": "h" in query[11], # todo "fave_count": define.execute("SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 'f')", [charid], ["element"]), "comments": comment.select(userid, charid=charid), "sub_media": fake_media_items(charid, query[0], login, query[11]), "tags": searchtag.select(charid=charid), }
def select_view_api(userid, submitid, anyway=False, increment_views=False): rating = d.get_rating(userid) db = d.connect() sub = db.query(orm.Submission).get(submitid) if sub is None or 'hidden' in sub.settings: raise WeasylError("submissionRecordMissing") sub_rating = sub.rating.code if 'friends-only' in sub.settings and not frienduser.check(userid, sub.userid): raise WeasylError("submissionRecordMissing") elif sub_rating > rating and userid != sub.userid: raise WeasylError("RatingExceeded") elif not anyway and ignoreuser.check(userid, sub.userid): raise WeasylError("UserIgnored") elif not anyway and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") description = sub.content embedlink = None if 'embedded-content' in sub.settings: embedlink, _, description = description.partition('\n') elif 'gdocs-embed' in sub.settings: embedlink = sub.google_doc_embed.embed_url views = sub.page_views if increment_views and d.common_view_content(userid, submitid, 'submit'): views += 1 return { 'submitid': submitid, 'title': sub.title, 'owner': sub.owner.profile.username, 'owner_login': sub.owner.login_name, 'owner_media': api.tidy_all_media(media.get_user_media(sub.userid)), 'media': api.tidy_all_media(media.get_submission_media(submitid)), 'description': text.markdown(description), 'embedlink': embedlink, 'folderid': sub.folderid, 'folder_name': sub.folder.title if sub.folderid else None, 'posted_at': d.iso8601(sub.unixtime), 'tags': searchtag.select(submitid=submitid), 'link': d.absolutify_url("/submission/%d/%s" % (submitid, text.slug_for(sub.title))), 'type': 'submission', 'subtype': m.CATEGORY_PARSABLE_MAP[sub.subtype // 1000 * 1000], 'rating': sub.rating.name, 'views': views, 'favorites': favorite.count(submitid), 'comments': comment.count(submitid), 'favorited': favorite.check(userid, submitid=submitid), 'friends_only': 'friends-only' in sub.settings, }
def select_view(userid, rating, journalid, ignore=True, anyway=None): journal = d.engine.execute(""" SELECT jo.userid, pr.username, jo.unixtime, jo.title, jo.rating, jo.settings, jo.page_views, pr.config FROM journal jo JOIN profile pr ON jo.userid = pr.userid WHERE jo.journalid = %(id)s """, id=journalid).fetchone() if journal and userid in staff.MODS and anyway == "true": pass elif not journal or "h" in journal.settings: raise WeasylError("journalRecordMissing") elif journal.rating > rating and ((userid != journal[0] and userid not in staff.MODS) or d.is_sfw_mode()): raise WeasylError("RatingExceeded") elif "f" in journal.settings and not frienduser.check(userid, journal.userid): raise WeasylError("FriendsOnly") elif ignore and ignoreuser.check(userid, journal.userid): raise WeasylError("UserIgnored") elif ignore and blocktag.check(userid, journalid=journalid): raise WeasylError("TagBlocked") page_views = journal.page_views if d.common_view_content(userid, journalid, "journal"): page_views += 1 return { "journalid": journalid, "userid": journal.userid, "username": journal.username, "user_media": media.get_user_media(journal.userid), "mine": userid == journal.userid, "unixtime": journal.unixtime, "title": journal.title, "content": files.read(files.make_resource(userid, journalid, "journal/submit")), "rating": journal.rating, "settings": journal.settings, "page_views": page_views, "reported": report.check(journalid=journalid), "favorited": favorite.check(userid, journalid=journalid), "friends_only": "f" in journal.settings, "hidden_submission": "h" in journal.settings, # todo "fave_count": d.execute("SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 'j')", [journalid], ["element"]), "tags": searchtag.select(journalid=journalid), "comments": comment.select(userid, journalid=journalid), }
def select_view(userid, rating, journalid, ignore=True, anyway=None): journal = _select_journal_and_check( userid, journalid, rating=rating, ignore=ignore, anyway=anyway == 'anyway') return { 'journalid': journalid, 'userid': journal['userid'], 'username': journal['username'], 'user_media': media.get_user_media(journal['userid']), 'mine': userid == journal['userid'], 'unixtime': journal['unixtime'], 'title': journal['title'], 'content': files.read(files.make_resource(userid, journalid, 'journal/submit')), 'rating': journal['rating'], 'settings': journal['settings'], 'page_views': journal['page_views'], 'reported': report.check(journalid=journalid), 'favorited': favorite.check(userid, journalid=journalid), 'friends_only': 'f' in journal['settings'], 'hidden_submission': 'h' in journal['settings'], 'fave_count': favorite.count(journalid, 'journal'), 'tags': searchtag.select(journalid=journalid), 'comments': comment.select(userid, journalid=journalid), }
def select_view_api(userid, charid, anyway=False, increment_views=False): rating = define.get_rating(userid) query = _select_character_and_check( userid, charid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) login = define.get_sysname(query['username']) return { 'charid': charid, 'owner': query['username'], 'owner_login': login, 'owner_media': api.tidy_all_media( media.get_user_media(query['userid'])), 'posted_at': define.iso8601(query['unixtime']), 'title': query['char_name'], 'age': query['age'], 'gender': query['gender'], 'height': query['height'], 'weight': query['weight'], 'species': query['species'], 'content': text.markdown(query['content']), 'rating': ratings.CODE_TO_NAME[query['rating']], 'favorited': favorite.check(userid, charid=charid), 'views': query['page_views'], 'friends_only': 'f' in query['settings'], 'favorites': favorite.count(charid, 'character'), 'comments': comment.count(charid, 'character'), 'media': api.tidy_all_media(fake_media_items( charid, query['userid'], login, query['settings'])), 'tags': searchtag.select(charid=charid), 'type': 'character', 'link': define.absolutify_url( '/character/%d/%s' % (charid, text.slug_for(query['char_name']))), }
def select_view_api(userid, submitid, anyway=False, increment_views=False): rating = d.get_rating(userid) db = d.connect() sub = db.query(orm.Submission).get(submitid) if sub is None or 'hidden' in sub.settings: raise WeasylError("submissionRecordMissing") sub_rating = sub.rating.code if 'friends-only' in sub.settings and not frienduser.check( userid, sub.userid): raise WeasylError("submissionRecordMissing") elif sub_rating > rating and userid != sub.userid: raise WeasylError("RatingExceeded") elif not anyway and ignoreuser.check(userid, sub.userid): raise WeasylError("UserIgnored") elif not anyway and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") description = sub.content embedlink = None if 'embedded-content' in sub.settings: embedlink, _, description = description.partition('\n') elif 'gdocs-embed' in sub.settings: embedlink = sub.google_doc_embed.embed_url views = sub.page_views if increment_views and d.common_view_content(userid, submitid, 'submit'): views += 1 return { 'submitid': submitid, 'title': sub.title, 'owner': sub.owner.profile.username, 'owner_login': sub.owner.login_name, 'owner_media': api.tidy_all_media(media.get_user_media(sub.userid)), 'media': api.tidy_all_media(media.get_submission_media(submitid)), 'description': text.markdown(description), 'embedlink': embedlink, 'folderid': sub.folderid, 'folder_name': sub.folder.title if sub.folderid else None, 'posted_at': d.iso8601(sub.unixtime), 'tags': searchtag.select(submitid=submitid), 'link': d.absolutify_url("/submission/%d/%s" % (submitid, text.slug_for(sub.title))), 'type': 'submission', 'subtype': m.CATEGORY_PARSABLE_MAP[sub.subtype // 1000 * 1000], 'rating': sub.rating.name, 'views': views, 'favorites': favorite.count(submitid), 'comments': comment.count(submitid), 'favorited': favorite.check(userid, submitid=submitid), 'friends_only': 'friends-only' in sub.settings, }
def select_view(userid, submitid, rating, ignore=True, anyway=None): query = d.execute(""" SELECT su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings, su.page_views, su.sorttime, pr.config, fd.title FROM submission su INNER JOIN profile pr USING (userid) LEFT JOIN folder fd USING (folderid) WHERE su.submitid = %i """, [submitid], options=["single", "list"]) # Sanity check if query and userid in staff.MODS and anyway == "true": pass elif not query or "h" in query[8]: raise WeasylError("submissionRecordMissing") elif query[7] > rating and ( (userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()): raise WeasylError("RatingExceeded") elif "f" in query[8] and not frienduser.check(userid, query[0]): raise WeasylError("FriendsOnly") elif ignore and ignoreuser.check(userid, query[0]): raise WeasylError("UserIgnored") elif ignore and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") # Get submission filename submitfile = media.get_submission_media(submitid).get( 'submission', [None])[0] # Get submission text if submitfile and submitfile['file_type'] in ['txt', 'htm']: submittext = files.read(submitfile['full_file_path']) else: submittext = None embedlink = d.text_first_line(query[5]) if "v" in query[8] else None google_doc_embed = None if 'D' in query[8]: db = d.connect() gde = d.meta.tables['google_doc_embeds'] q = (sa.select([gde.c.embed_url]).where(gde.c.submitid == submitid)) results = db.execute(q).fetchall() if not results: raise WeasylError("can't find embed information") google_doc_embed = results[0] tags, artist_tags = searchtag.select_with_artist_tags(submitid) settings = d.get_profile_settings(query[0]) return { "submitid": submitid, "userid": query[0], "username": query[1], "folderid": query[2], "unixtime": query[3], "title": query[4], "content": (d.text_first_line(query[5], strip=True) if "v" in query[8] else query[5]), "subtype": query[6], "rating": query[7], "settings": query[8], "page_views": (query[9] + 1 if d.common_view_content( userid, 0 if anyway == "true" else submitid, "submit") else query[9]), "fave_count": d.execute( "SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 's')", [submitid], ["element"]), "mine": userid == query[0], "reported": report.check(submitid=submitid), "favorited": favorite.check(userid, submitid=submitid), "friends_only": "f" in query[8], "hidden_submission": "h" in query[8], "collectors": collection.find_owners(submitid), "no_request": not settings.allow_collection_requests, "text": submittext, "sub_media": media.get_submission_media(submitid), "user_media": media.get_user_media(query[0]), "submit": submitfile, "embedlink": embedlink, "embed": embed.html(embedlink) if embedlink is not None else None, "google_doc_embed": google_doc_embed, "tags": tags, "artist_tags": artist_tags, "removable_tags": searchtag.removable_tags(userid, query[0], tags, artist_tags), "can_remove_tags": searchtag.can_remove_tags(userid, query[0]), "folder_more": select_near(userid, rating, 1, query[0], query[2], submitid), "folder_title": query[12] if query[12] else "Root", "comments": comment.select(userid, submitid=submitid), }
def select_view(userid, submitid, rating, ignore=True, anyway=None): query = d.execute(""" SELECT su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings, su.page_views, su.sorttime, pr.config, fd.title FROM submission su INNER JOIN profile pr USING (userid) LEFT JOIN folder fd USING (folderid) WHERE su.submitid = %i """, [submitid], options=["single", "list"]) # Sanity check if query and userid in staff.MODS and anyway == "true": pass elif not query or "h" in query[8]: raise WeasylError("submissionRecordMissing") elif query[7] > rating and ((userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()): raise WeasylError("RatingExceeded") elif "f" in query[8] and not frienduser.check(userid, query[0]): raise WeasylError("FriendsOnly") elif ignore and ignoreuser.check(userid, query[0]): raise WeasylError("UserIgnored") elif ignore and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") # Get submission filename submitfile = media.get_submission_media(submitid).get('submission', [None])[0] # Get submission text if submitfile and submitfile['file_type'] in ['txt', 'htm']: submittext = files.read(submitfile['full_file_path']) else: submittext = None embedlink = d.text_first_line(query[5]) if "v" in query[8] else None google_doc_embed = None if 'D' in query[8]: db = d.connect() gde = d.meta.tables['google_doc_embeds'] q = (sa.select([gde.c.embed_url]) .where(gde.c.submitid == submitid)) results = db.execute(q).fetchall() if not results: raise WeasylError("can't find embed information") google_doc_embed = results[0] tags, artist_tags = searchtag.select_with_artist_tags(submitid) settings = d.get_profile_settings(query[0]) return { "submitid": submitid, "userid": query[0], "username": query[1], "folderid": query[2], "unixtime": query[3], "title": query[4], "content": (d.text_first_line(query[5], strip=True) if "v" in query[8] else query[5]), "subtype": query[6], "rating": query[7], "settings": query[8], "page_views": ( query[9] + 1 if d.common_view_content(userid, 0 if anyway == "true" else submitid, "submit") else query[9]), "fave_count": d.execute( "SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 's')", [submitid], ["element"]), "mine": userid == query[0], "reported": report.check(submitid=submitid), "favorited": favorite.check(userid, submitid=submitid), "friends_only": "f" in query[8], "hidden_submission": "h" in query[8], "collectors": collection.find_owners(submitid), "no_request": not settings.allow_collection_requests, "text": submittext, "sub_media": media.get_submission_media(submitid), "user_media": media.get_user_media(query[0]), "submit": submitfile, "embedlink": embedlink, "embed": embed.html(embedlink) if embedlink is not None else None, "google_doc_embed": google_doc_embed, "tags": tags, "artist_tags": artist_tags, "removable_tags": searchtag.removable_tags(userid, query[0], tags, artist_tags), "can_remove_tags": searchtag.can_remove_tags(userid, query[0]), "folder_more": select_near(userid, rating, 1, query[0], query[2], submitid), "folder_title": query[12] if query[12] else "Root", "comments": comment.select(userid, submitid=submitid), }