Exemple #1
0
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),
    }
Exemple #2
0
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']),
    }
Exemple #3
0
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))),
    }
Exemple #4
0
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),
    }
Exemple #5
0
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']),
    }
Exemple #6
0
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),
    }
Exemple #7
0
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,
    }
Exemple #8
0
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),
    }
Exemple #9
0
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),
    }
Exemple #10
0
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']))),
    }
Exemple #11
0
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),
    }
Exemple #12
0
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,
    }