Esempio n. 1
0
def select_view(userid, rating, journalid, ignore=True, anyway=None):
    journal = _select_journal_and_check(userid,
                                        journalid,
                                        rating=rating,
                                        ignore=ignore,
                                        anyway=anyway == "true")

    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': journal['content'],
        '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),
    }
Esempio n. 2
0
def select_view(userid, charid, rating, ignore=True, anyway=None):
    query = _select_character_and_check(
        userid, charid, rating=rating, ignore=ignore, anyway=anyway == "true")

    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),
    }
Esempio n. 3
0
def render_form(request,
                scopes,
                credentials,
                mobile,
                error=None,
                username='',
                password='',
                remember_me=False,
                not_me=False):
    db = d.connect()
    client = db.query(orm.OAuthConsumer).get(credentials['client_id'])
    if request.userid:
        user = db.query(orm.Login).get(request.userid)
        user_media = media.get_user_media(request.userid)
    else:
        user = user_media = None
    credentials['scopes'] = scopes
    return d.render('oauth2/authorize.html', [
        scopes,
        credentials,
        client,
        user,
        user_media,
        mobile,
        error,
        username,
        password,
        remember_me,
        not_me,
    ])
Esempio n. 4
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)

    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(journal['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']),
    }
Esempio n. 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)

    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(journal['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']),
    }
Esempio n. 6
0
def twitter_card(userid):
    username, full_name, catchphrase, profile_text, config, twitter = d.execute(
        "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value "
        "FROM profile pr "
        "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' "
        "WHERE pr.userid = %i", [userid], ["single"])

    ret = {
        'card': 'summary',
        'url': d.absolutify_url('/~%s' % (username, )),
        'title': '%s on Weasyl' % (full_name, ),
    }

    if catchphrase:
        description = '"%s"' % (catchphrase, )
    elif profile_text:
        description = strip_html(profile_text)
    else:
        description = "[%s has an empty profile, but is eggcelent!]" % (
            full_name, )
    ret['description'] = d.summarize(description)

    media_items = media.get_user_media(userid)
    ret['image:src'] = d.absolutify_url(
        media_items['avatar'][0]['display_url'])

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'), )

    return ret
Esempio n. 7
0
def twitter_card(userid):
    username, full_name, catchphrase, profile_text, config, twitter = d.execute(
        "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value "
        "FROM profile pr "
        "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' "
        "WHERE pr.userid = %i",
        [userid],
        ["single"])

    ret = {
        'card': 'summary',
        'url': d.absolutify_url('/~%s' % (username,)),
        'title': '%s on Weasyl' % (full_name,),
    }

    if catchphrase:
        description = '"%s"' % (catchphrase,)
    elif profile_text:
        description = strip_html(profile_text)
    else:
        description = "[%s has an empty profile, but is eggcelent!]" % (full_name,)
    ret['description'] = d.summarize(description)

    media_items = media.get_user_media(userid)
    ret['image:src'] = d.absolutify_url(media_items['avatar'][0]['display_url'])

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'),)

    return ret
Esempio n. 8
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),
    }
Esempio n. 9
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))),
    }
Esempio n. 10
0
 def GET(self, name, link_type):
     userid = profile.resolve(None, None, name)
     media_items = media.get_user_media(userid)
     if not media_items.get(link_type):
         return web.notfound()
     web.header('X-Accel-Redirect', media_items[link_type][0]['file_url'])
     web.header('Cache-Control', 'max-age=0')
     return ''
Esempio n. 11
0
 def GET(self, name, link_type):
     userid = profile.resolve(None, None, name)
     media_items = media.get_user_media(userid)
     if not media_items.get(link_type):
         return web.notfound()
     web.header('X-Accel-Redirect', media_items[link_type][0]['file_url'])
     web.header('Cache-Control', 'max-age=0')
     return ''
Esempio n. 12
0
def page_header_info(userid):
    from weasyl import media
    sfw = get_current_request().cookies.get('sfwmode', 'nsfw')
    return {
        "welcome": _page_header_info(userid),
        "userid": userid,
        "username": get_display_name(userid),
        "user_media": media.get_user_media(userid),
        "sfw": sfw,
    }
Esempio n. 13
0
def page_header_info(userid):
    from weasyl import media
    sfw = web.cookies(sfwmode="nsfw").sfwmode
    return {
        "welcome": _page_header_info(userid),
        "userid": userid,
        "username": get_display_name(userid),
        "user_media": media.get_user_media(userid),
        "sfw": sfw,
    }
Esempio n. 14
0
def page_header_info(userid):
    from weasyl import media
    sfw = web.cookies(sfwmode="nsfw").sfwmode
    return {
        "welcome": _page_header_info(userid),
        "userid": userid,
        "username": get_display_name(userid),
        "user_media": media.get_user_media(userid),
        "sfw": sfw,
    }
Esempio n. 15
0
def page_header_info(userid):
    from weasyl import media
    sfw = get_current_request().cookies.get('sfwmode', 'nsfw')
    return {
        "welcome": _page_header_info(userid),
        "userid": userid,
        "username": get_display_name(userid),
        "user_media": media.get_user_media(userid),
        "sfw": sfw,
    }
Esempio n. 16
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),
    }
Esempio n. 17
0
def profile_media_(request):
    name = request.matchdict['name']
    link_type = request.matchdict['link_type']
    userid = profile.resolve(None, None, name)
    media_items = media.get_user_media(userid)
    if not media_items.get(link_type):
        raise httpexceptions.HTTPNotFound()
    return Response(headerlist=[
        ('X-Accel-Redirect', str(media_items[link_type][0]['file_url']),),
        ('Cache-Control', 'max-age=0',),
    ])
Esempio n. 18
0
def api_useravatar_(request):
    form = request.web_input(username="")
    userid = profile.resolve_by_login(d.get_sysname(form.username))

    if userid:
        media_items = media.get_user_media(userid)
        return {
            "avatar": d.absolutify_url(media_items['avatar'][0]['display_url']),
        }

    raise WeasylError('userRecordMissing')
Esempio n. 19
0
def profile_media_(request):
    name = request.matchdict['name']
    link_type = request.matchdict['link_type']
    userid = profile.resolve(None, None, name)
    media_items = media.get_user_media(userid)
    if not media_items.get(link_type):
        raise httpexceptions.HTTPNotFound()
    return Response(headerlist=[
        ('X-Accel-Redirect', str(media_items[link_type][0]['file_url']),),
        ('Cache-Control', 'max-age=0',),
    ])
Esempio n. 20
0
File: api.py Progetto: Weasyl/weasyl
def api_useravatar_(request):
    form = request.web_input(username="")
    userid = profile.resolve_by_login(form.username)

    if userid:
        media_items = media.get_user_media(userid)
        return {
            "avatar": d.absolutify_url(media_items['avatar'][0]['display_url']),
        }

    raise WeasylError('userRecordMissing')
Esempio n. 21
0
def select_myself(userid):
    if not userid:
        return None

    return {
        "userid": userid,
        "username": d.get_display_name(userid),
        "is_mod": userid in staff.MODS,
        "is_verified": d.is_vouched_for(userid),
        "user_media": media.get_user_media(userid),
    }
Esempio n. 22
0
def select_myself(userid):
    if not userid:
        return

    query = d.execute("SELECT username, config FROM profile WHERE userid = %i", [userid], ["single"])

    return {
        "userid": userid,
        "username": query[0],
        "is_mod": userid in staff.MODS,
        "user_media": media.get_user_media(userid),
    }
Esempio n. 23
0
def select_myself(userid):
    if not userid:
        return

    query = d.execute("SELECT username, config FROM profile WHERE userid = %i", [userid], ["single"])

    return {
        "userid": userid,
        "username": query[0],
        "is_mod": userid in staff.MODS,
        "user_media": media.get_user_media(userid),
    }
Esempio n. 24
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,
    }
Esempio n. 25
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,
    }
Esempio n. 26
0
    def POST(self):
        # Retrieve form data
        form = web.input(username="")
        userid = profile.resolve_by_login(form.username)

        # Return JSON response
        if userid:
            media_items = media.get_user_media(userid)
            return json.dumps({
                "avatar": d.absolutify_url(media_items['avatar'][0]['display_url']),
            })

        raise WeasylError('userRecordMissing')
Esempio n. 27
0
def select_last():
    last = d.engine.execute("""
        SELECT up.updateid, up.userid, pr.username, up.title, up.content, up.unixtime
        FROM siteupdate up
            INNER JOIN profile pr USING (userid)
        ORDER BY updateid DESC
        LIMIT 1
    """).first()

    if not last:
        return None

    return dict(last, user_media=media.get_user_media(last.userid))
Esempio n. 28
0
 def render_form(self, scopes, credentials, mobile, error=None,
                 username='', password='', remember_me=False, not_me=False):
     db = d.connect()
     client = db.query(orm.OAuthConsumer).get(credentials['client_id'])
     if self.user_id:
         user = db.query(orm.Login).get(self.user_id)
         user_media = media.get_user_media(self.user_id)
     else:
         user = user_media = None
     credentials['scopes'] = scopes
     return d.render('oauth2/authorize.html', [
         scopes, credentials, client, user, user_media, mobile, error,
         username, password, remember_me, not_me,
     ])
Esempio n. 29
0
def select_last():
    last = d.engine.execute("""
        SELECT
            up.updateid, pr.userid, pr.username, up.title, up.content, up.unixtime,
            (SELECT count(*) FROM siteupdatecomment c WHERE c.targetid = up.updateid) AS comment_count
        FROM siteupdate up
            LEFT JOIN profile pr ON pr.userid = CASE WHEN up.wesley THEN %(wesley)s ELSE up.userid END
        ORDER BY updateid DESC
        LIMIT 1
    """, wesley=staff.WESLEY).first()

    if not last:
        return None

    return dict(last, user_media=media.get_user_media(last.userid))
Esempio n. 30
0
def select_last():
    last = d.engine.execute("""
        SELECT
            up.updateid, pr.userid, pr.username, up.title, up.content, up.unixtime,
            (SELECT count(*) FROM siteupdatecomment c WHERE c.targetid = up.updateid) AS comment_count
        FROM siteupdate up
            LEFT JOIN profile pr ON pr.userid = CASE WHEN up.wesley THEN %(wesley)s ELSE up.userid END
        ORDER BY updateid DESC
        LIMIT 1
    """,
                            wesley=staff.WESLEY).first()

    if not last:
        return None

    return dict(last, user_media=media.get_user_media(last.userid))
Esempio n. 31
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),
    }
Esempio n. 32
0
def select_by_id(updateid):
    su = d.meta.tables['siteupdate']
    pr = d.meta.tables['profile']
    q = (
        sa.select([
            pr.c.userid, pr.c.username, su.c.title, su.c.content, su.c.unixtime,
        ])
        .select_from(su.join(pr, su.c.userid == pr.c.userid))
        .where(su.c.updateid == updateid))
    db = d.connect()
    results = db.execute(q).fetchall()
    if not results:
        raise WeasylError('RecordMissing')
    results = dict(results[0])
    results['user_media'] = media.get_user_media(results['userid'])
    results['timestamp'] = results['unixtime'].timestamp + UNIXTIME_OFFSET
    return results
Esempio n. 33
0
def select_profile(userid,
                   avatar=False,
                   banner=False,
                   propic=False,
                   images=False,
                   commish=True,
                   viewer=None):
    query = d.execute(
        """
        SELECT pr.username, pr.full_name, pr.catchphrase, pr.unixtime, pr.profile_text,
            pr.settings, pr.stream_url, pr.config, pr.stream_text, lo.settings, us.end_time
        FROM profile pr
            INNER JOIN login lo USING (userid)
            LEFT JOIN user_streams us USING (userid)
        WHERE userid = %i
    """, [userid], ["single"])

    if not query:
        raise WeasylError('RecordMissing')

    streaming_status = "stopped"
    if query[6]:  # profile.stream_url
        if query[10] > d.get_time():  # user_streams.end_time
            streaming_status = "started"
        elif 'l' in query[5]:
            streaming_status = "later"

    return {
        "userid": userid,
        "user_media": media.get_user_media(userid),
        "username": query[0],
        "full_name": query[1],
        "catchphrase": query[2],
        "unixtime": query[3],
        "profile_text": query[4],
        "settings": query[5],
        "stream_url": query[6],
        "stream_text": query[8],
        "config": query[7],
        "show_favorites_bar": "u" not in query[7] and "v" not in query[7],
        "show_favorites_tab": userid == viewer or "v" not in query[7],
        "commish_slots": 0,
        "banned": "b" in query[9],
        "suspended": "s" in query[9],
        "streaming_status": streaming_status,
    }
Esempio n. 34
0
def select_profile(userid, viewer=None):
    query = d.engine.execute("""
        SELECT pr.username, pr.full_name, pr.catchphrase, pr.created_at, pr.profile_text,
            pr.settings, pr.stream_url, pr.config, pr.stream_text, us.end_time
        FROM profile pr
            INNER JOIN login lo USING (userid)
            LEFT JOIN user_streams us USING (userid)
        WHERE userid = %(user)s
    """,
                             user=userid).first()

    if not query:
        raise WeasylError('userRecordMissing')

    is_banned, is_suspended = d.get_login_settings(userid)

    streaming_status = "stopped"
    if query[6]:  # profile.stream_url
        if 'l' in query[5]:
            streaming_status = "later"
        elif query[9] is not None and query[9] > d.get_time(
        ):  # user_streams.end_time
            streaming_status = "started"

    return {
        "userid": userid,
        "user_media": media.get_user_media(userid),
        "username": query[0],
        "full_name": query[1],
        "catchphrase": query[2],
        "unixtime": query[3],
        "profile_text": query[4],
        "settings": query[5],
        "stream_url": query[6],
        "stream_text": query[8],
        "config": query[7],
        "show_favorites_bar": "u" not in query[7] and "v" not in query[7],
        "show_favorites_tab": userid == viewer or "v" not in query[7],
        "commish_slots": 0,
        "banned": is_banned,
        "suspended": is_suspended,
        "streaming_status": streaming_status,
    }
Esempio n. 35
0
def select_by_id(updateid):
    su = d.meta.tables['siteupdate']
    pr = d.meta.tables['profile']
    q = (sa.select([
        pr.c.userid,
        pr.c.username,
        su.c.title,
        su.c.content,
        su.c.unixtime,
    ]).select_from(su.join(
        pr, su.c.userid == pr.c.userid)).where(su.c.updateid == updateid))
    db = d.connect()
    results = db.execute(q).fetchall()
    if not results:
        raise WeasylError('RecordMissing')
    results = dict(results[0])
    results['user_media'] = media.get_user_media(results['userid'])
    results['timestamp'] = results['unixtime'].timestamp + UNIXTIME_OFFSET
    return results
Esempio n. 36
0
def manageuser(userid, form):
    if userid not in staff.MODS:
        raise WeasylError("Unexpected")

    query = d.execute(
        "SELECT userid, username, config, profile_text, catchphrase FROM profile"
        " WHERE userid = (SELECT userid FROM login WHERE login_name = '%s')",
        [d.get_sysname(form.name)], ["single"])

    if not query:
        raise WeasylError("noUser")

    return {
        "userid": query[0],
        "username": query[1],
        "config": query[2],
        "profile_text": query[3],
        "catchphrase": query[4],
        "user_media": media.get_user_media(query[0]),
        "staff_notes": shout.count(query[0], staffnotes=True),
    }
Esempio n. 37
0
def manageuser(userid, form):
    if userid not in staff.MODS:
        raise WeasylError("Unexpected")

    query = d.execute(
        "SELECT userid, username, config, profile_text, catchphrase FROM profile"
        " WHERE userid = (SELECT userid FROM login WHERE login_name = '%s')",
        [d.get_sysname(form.name)], ["single"])

    if not query:
        raise WeasylError("noUser")

    return {
        "userid": query[0],
        "username": query[1],
        "config": query[2],
        "profile_text": query[3],
        "catchphrase": query[4],
        "user_media": media.get_user_media(query[0]),
        "staff_notes": shout.count(query[0], staffnotes=True),
    }
Esempio n. 38
0
def select_profile(userid, avatar=False, banner=False, propic=False, images=False, commish=True, viewer=None):
    query = d.execute("""
        SELECT pr.username, pr.full_name, pr.catchphrase, pr.unixtime, pr.profile_text,
            pr.settings, pr.stream_url, pr.config, pr.stream_text, lo.settings, us.end_time
        FROM profile pr
            INNER JOIN login lo USING (userid)
            LEFT JOIN user_streams us USING (userid)
        WHERE userid = %i
    """, [userid], ["single"])

    if not query:
        raise WeasylError('RecordMissing')

    streaming_status = "stopped"
    if query[6]:  # profile.stream_url
        if query[10] > d.get_time():  # user_streams.end_time
            streaming_status = "started"
        elif 'l' in query[5]:
            streaming_status = "later"

    return {
        "userid": userid,
        "user_media": media.get_user_media(userid),
        "username": query[0],
        "full_name": query[1],
        "catchphrase": query[2],
        "unixtime": query[3],
        "profile_text": query[4],
        "settings": query[5],
        "stream_url": query[6],
        "stream_text": query[8],
        "config": query[7],
        "show_favorites_bar": "u" not in query[7] and "v" not in query[7],
        "show_favorites_tab": userid == viewer or "v" not in query[7],
        "commish_slots": 0,
        "banned": "b" in query[9],
        "suspended": "s" in query[9],
        "streaming_status": streaming_status,
    }
Esempio n. 39
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),
    }
Esempio n. 40
0
def select_view(userid, rating, journalid, ignore=True, anyway=None):
    journal = _select_journal_and_check(
        userid, journalid, rating=rating, ignore=ignore, anyway=anyway == "true")

    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': journal['content'],
        '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),
    }
Esempio n. 41
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']))),
    }
Esempio n. 42
0
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),
    }
Esempio n. 43
0
def avatar_source(userid):
    media_items = media.get_user_media(userid)
    if media_items.get('avatar-source'):
        return media_items['avatar-source'][0]
    else:
        raise WeasylError('noImageSource')
Esempio n. 44
0
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),
    }
Esempio n. 45
0
def avatar_source(userid):
    media_items = media.get_user_media(userid)
    if media_items.get('avatar-source'):
        return media_items['avatar-source'][0]
    else:
        raise WeasylError('noImageSource')