Esempio n. 1
0
    def GET(self, a="", b=None):
        if b is None:
            username, submitid = None, a
        else:
            username, submitid = a, b
        now = time.time()

        form = web.input(submitid="", ignore="", anyway="")

        rating = define.get_rating(self.user_id)
        submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid)

        extras = {
            "pdf": True,
        }

        if define.user_is_twitterbot():
            extras['twitter_card'] = submission.twitter_card(submitid)

        try:
            item = submission.select_view(
                self.user_id, submitid, rating,
                ignore=define.text_bool(form.ignore, True), anyway=form.anyway
            )
        except WeasylError as we:
            we.errorpage_kwargs = extras
            if 'twitter_card' in extras:
                extras['options'] = ['nocache']
            if we.value in ("UserIgnored", "TagBlocked"):
                extras['links'] = [
                    ("View Submission", "?ignore=false"),
                    ("Return to the Home Page", "/index"),
                ]
            raise

        login = define.get_sysname(item['username'])
        if username is not None and login != username:
            raise web.seeother('/~%s/post/%s/%s' % (login, submitid, slug_for(item["title"])))
        extras["canonical_url"] = "/submission/%d/%s" % (submitid, slug_for(item["title"]))
        extras["title"] = item["title"]

        page = define.common_page_start(self.user_id, options=["mediaplayer"], **extras)
        page.append(define.render('detail/submission.html', [
            # Myself
            profile.select_myself(self.user_id),
            # Submission detail
            item,
            # Subtypes
            macro.MACRO_SUBCAT_LIST,
            # Violations
            [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000],
        ]))

        return define.common_page_end(self.user_id, page, now=now)
Esempio n. 2
0
    def POST(self):
        form = web.input(charid="",
                         title="",
                         age="",
                         gender="",
                         height="",
                         weight="",
                         species="",
                         rating="",
                         content="",
                         friends="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        c = orm.Character()
        c.charid = define.get_int(form.charid)
        c.age = form.age
        c.gender = form.gender
        c.height = form.height
        c.weight = form.weight
        c.species = form.species
        c.char_name = form.title
        c.content = form.content
        c.rating = rating

        character.edit(self.user_id, c, friends_only=form.friends)
        raise web.seeother(
            "/character/%i/%s%s" %
            (define.get_int(form.charid), slug_for(form.title),
             ("?anyway=true" if self.user_id in staff.MODS else '')))
Esempio n. 3
0
    def POST(self):
        form = web.input(submitid="",
                         title="",
                         folderid="",
                         subtype="",
                         rating="",
                         content="",
                         friends="",
                         critique="",
                         embedlink="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        s = orm.Submission()
        s.submitid = define.get_int(form.submitid)
        s.title = form.title
        s.rating = rating
        s.content = form.content
        s.folderid = define.get_int(form.folderid) or None
        s.subtype = define.get_int(form.subtype)

        submission.edit(self.user_id,
                        s,
                        embedlink=form.embedlink,
                        friends_only=form.friends,
                        critique=form.critique)
        raise web.seeother(
            "/submission/%i/%s%s" %
            (define.get_int(form.submitid), slug_for(form.title),
             "?anyway=true" if self.user_id in staff.MODS else ''))
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 edit_character_post_(request):
    form = request.web_input(charid="", title="", age="", gender="", height="",
                             weight="", species="", rating="", content="", friends="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    c = orm.Character()
    c.charid = define.get_int(form.charid)
    c.age = form.age
    c.gender = form.gender
    c.height = form.height
    c.weight = form.weight
    c.species = form.species
    c.char_name = form.title
    c.content = form.content
    c.rating = rating

    character.edit(request.userid, c, friends_only=form.friends)
    raise HTTPSeeOther(location="/character/%i/%s%s" % (
        define.get_int(form.charid),
        slug_for(form.title),
        ("?anyway=true" if request.userid in staff.MODS else '')
    ))
Esempio n. 6
0
def submit_literary_post_(request):
    form = request.web_input(submitfile="", coverfile="boop", thumbfile="", title="",
                             folderid="", subtype="", rating="", friends="", critique="",
                             content="", tags="", embedlink="")

    tags = searchtag.parse_tags(form.tags)

    if not define.config_read_bool("allow_submit"):
        raise WeasylError("FeatureDisabled")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    s = orm.Submission()
    s.title = form.title
    s.rating = rating
    s.content = form.content
    s.folderid = define.get_int(form.folderid) or None
    s.subtype = define.get_int(form.subtype)

    submitid, thumb = submission.create_literary(
        request.userid, s, embedlink=form.embedlink, friends_only=form.friends, tags=tags,
        coverfile=form.coverfile, thumbfile=form.thumbfile, submitfile=form.submitfile,
        critique=form.critique, create_notifications=('nonotification' not in form))
    if thumb:
        raise HTTPSeeOther(location="/manage/thumbnail?submitid=%i" % (submitid,))
    else:
        raise HTTPSeeOther(location="/submission/%i/%s" % (submitid, slug_for(form.title)))
Esempio n. 7
0
    def GET(self, journalid=""):
        form = web.input(journalid="", ignore="", anyway="")

        rating = define.get_rating(self.user_id)
        journalid = define.get_int(journalid) if journalid else define.get_int(form.journalid)

        try:
            item = journal.select_view(
                self.user_id, rating, journalid,
                ignore=define.text_bool(form.ignore, True), anyway=form.anyway
            )
        except WeasylError as we:
            if we.value in ("UserIgnored", "TagBlocked"):
                we.errorpage_kwargs['links'] = [
                    ("View Journal", "?ignore=false"),
                    ("Return to the Home Page", "/index"),
                ]
            raise

        canonical_url = "/journal/%d/%s" % (journalid, slug_for(item["title"]))

        page = define.common_page_start(self.user_id, options=["pager"], canonical_url=canonical_url, title=item["title"])
        page.append(define.render(template.detail_journal, [
            # Myself
            profile.select_myself(self.user_id),
            # Journal detail
            item,
            # Violations
            [i for i in macro.MACRO_REPORT_VIOLATION if 3000 <= i[0] < 4000],
        ]))

        return define.common_page_end(self.user_id, page)
Esempio n. 8
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. 9
0
def journal_(request):
    form = request.web_input(journalid="", ignore="", anyway="")

    rating = define.get_rating(request.userid)
    journalid = define.get_int(request.matchdict.get('journalid', form.journalid))

    try:
        item = journal.select_view(
            request.userid, rating, journalid,
            ignore=define.text_bool(form.ignore, True), anyway=form.anyway
        )
    except WeasylError as we:
        if we.value in ("UserIgnored", "TagBlocked"):
            we.errorpage_kwargs['links'] = [
                ("View Journal", "?ignore=false"),
                ("Return to the Home Page", "/index"),
            ]
        raise

    canonical_url = "/journal/%d/%s" % (journalid, slug_for(item["title"]))

    page = define.common_page_start(request.userid, canonical_url=canonical_url, title=item["title"])
    page.append(define.render('detail/journal.html', [
        # Myself
        profile.select_myself(request.userid),
        # Journal detail
        item,
        # Violations
        [i for i in macro.MACRO_REPORT_VIOLATION if 3000 <= i[0] < 4000],
    ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 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': 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. 11
0
def edit_submission_post_(request):
    form = request.web_input(submitid="",
                             title="",
                             folderid="",
                             subtype="",
                             rating="",
                             content="",
                             friends="",
                             critique="",
                             embedlink="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    s = orm.Submission()
    s.submitid = define.get_int(form.submitid)
    s.title = form.title
    s.rating = rating
    s.content = form.content
    s.folderid = define.get_int(form.folderid) or None
    s.subtype = define.get_int(form.subtype)

    submission.edit(request.userid,
                    s,
                    embedlink=form.embedlink,
                    friends_only=form.friends,
                    critique=form.critique)
    raise HTTPSeeOther(
        location="/submission/%i/%s%s" %
        (define.get_int(form.submitid), slug_for(form.title),
         "?anyway=true" if request.userid in staff.MODS else ''))
Esempio n. 12
0
def edit_character_post_(request):
    form = request.web_input(charid="",
                             title="",
                             age="",
                             gender="",
                             height="",
                             weight="",
                             species="",
                             rating="",
                             content="",
                             friends="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    c = orm.Character()
    c.charid = define.get_int(form.charid)
    c.age = form.age
    c.gender = form.gender
    c.height = form.height
    c.weight = form.weight
    c.species = form.species
    c.char_name = form.title
    c.content = form.content
    c.rating = rating

    character.edit(request.userid, c, friends_only=form.friends)
    raise HTTPSeeOther(
        location="/character/%i/%s%s" %
        (define.get_int(form.charid), slug_for(form.title),
         ("?anyway=true" if request.userid in staff.MODS else '')))
Esempio n. 13
0
def character_(request):
    form = request.web_input(charid="", ignore="", anyway="")

    rating = define.get_rating(request.userid)
    charid = define.get_int(request.matchdict.get('charid', form.charid))

    try:
        item = character.select_view(
            request.userid, charid, rating,
            ignore=form.ignore != 'false', anyway=form.anyway
        )
    except WeasylError as we:
        if we.value in ("UserIgnored", "TagBlocked"):
            we.errorpage_kwargs['links'] = [
                ("View Character", "?ignore=false"),
                ("Return to the Home Page", "/index"),
            ]
        raise

    canonical_url = "/character/%d/%s" % (charid, slug_for(item["title"]))

    page = define.common_page_start(request.userid, canonical_url=canonical_url, title=item["title"])
    page.append(define.render('detail/character.html', [
        # Profile
        profile.select_myself(request.userid),
        # Character detail
        item,
        # Violations
        [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000],
    ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 14
0
File: api.py Progetto: 0x15/weasyl
def tidy_submission(submission):
    submission['posted_at'] = d.iso8601(submission.pop('unixtime'))
    submission['sub_media'] = api.tidy_all_media(submission['sub_media'])
    if 'user_media' in submission:
        submission['owner_media'] = api.tidy_all_media(submission.pop('user_media'))
    submission.pop('userid', None)
    subtype = submission.pop('subtype', None)
    if subtype:
        submission['subtype'] = m.CATEGORY_PARSABLE_MAP[subtype // 1000 * 1000]
    contype = submission.pop('contype', None)
    if contype:
        submission['type'] = m.CONTYPE_PARSABLE_MAP[contype]
    submission['rating'] = ratings.CODE_TO_NAME[submission['rating']]
    submission['owner'] = submission.pop('username')
    submission['owner_login'] = d.get_sysname(submission['owner'])
    submission['media'] = submission.pop('sub_media')
    submitid = 0
    if 'submitid' in submission:
        submitid = submission['submitid']
    if 'charid' in submission:
        submitid = submission['charid']
    if submitid > 0:
        if submission['type'] == "usercollect":
            linktype = "submission"
        else:
            linktype = submission['type']
        submission['link'] = d.absolutify_url(
            "/%s/%d/%s" % (linktype, submitid, slug_for(submission['title'])))
    return submission
Esempio n. 15
0
    def POST(self):
        form = web.input(submitfile="", thumbfile="", title="", folderid="",
                         subtype="", rating="", friends="", critique="", content="",
                         tags="", imageURL="")

        tags = searchtag.parse_tags(form.tags)

        if not define.config_read_bool("allow_submit"):
            raise WeasylError("FeatureDisabled")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        s = orm.Submission()
        s.title = form.title
        s.rating = rating
        s.content = form.content
        s.folderid = define.get_int(form.folderid) or None
        s.subtype = define.get_int(form.subtype)

        submitid = submission.create_visual(
            self.user_id, s, friends_only=form.friends, tags=tags,
            imageURL=form.imageURL, thumbfile=form.thumbfile, submitfile=form.submitfile,
            critique=form.critique, create_notifications=('nonotification' not in form))

        if 'customthumb' in form:
            raise web.seeother("/manage/thumbnail?submitid=%i" % (submitid,))
        else:
            raise web.seeother("/submission/%i/%s" % (submitid, slug_for(form.title)))
Esempio n. 16
0
    def POST(self):
        form = web.input(submitfile="", coverfile="", thumbfile="", embedlink="",
                         title="", folderid="", subtype="", rating="", friends="",
                         critique="", content="", tags="")

        tags = searchtag.parse_tags(form.tags)

        if not define.config_read_bool("allow_submit"):
            raise WeasylError("FeatureDisabled")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        s = orm.Submission()
        s.title = form.title
        s.rating = rating
        s.content = form.content
        s.folderid = define.get_int(form.folderid) or None
        s.subtype = define.get_int(form.subtype)

        autothumb = ('noautothumb' not in form)

        submitid, thumb = submission.create_multimedia(
            self.user_id, s, embedlink=form.embedlink, friends_only=form.friends, tags=tags,
            coverfile=form.coverfile, thumbfile=form.thumbfile, submitfile=form.submitfile,
            critique=form.critique, create_notifications=('nonotification' not in form),
            auto_thumb=autothumb)
        if thumb and not autothumb:
            raise web.seeother("/manage/thumbnail?submitid=%i" % (submitid,))
        else:
            raise web.seeother("/submission/%i/%s" % (submitid, slug_for(form.title)))
Esempio n. 17
0
def tidy_submission(submission):
    submission['posted_at'] = d.iso8601(submission.pop('unixtime'))
    submission['sub_media'] = api.tidy_all_media(submission['sub_media'])
    if 'user_media' in submission:
        submission['owner_media'] = api.tidy_all_media(
            submission.pop('user_media'))
    submission.pop('userid', None)
    subtype = submission.pop('subtype', None)
    if subtype:
        submission['subtype'] = m.CATEGORY_PARSABLE_MAP[subtype // 1000 * 1000]
    contype = submission.pop('contype', None)
    if contype:
        submission['type'] = m.CONTYPE_PARSABLE_MAP[contype]
    submission['rating'] = ratings.CODE_TO_NAME[submission['rating']]
    submission['owner'] = submission.pop('username')
    submission['owner_login'] = d.get_sysname(submission['owner'])
    submission['media'] = submission.pop('sub_media')
    submitid = 0
    if 'submitid' in submission:
        submitid = submission['submitid']
    if 'charid' in submission:
        submitid = submission['charid']
    if submitid > 0:
        if submission['type'] == "usercollect":
            linktype = "submission"
        else:
            linktype = submission['type']
        submission['link'] = d.absolutify_url(
            "/%s/%d/%s" % (linktype, submitid, slug_for(submission['title'])))
Esempio n. 18
0
    def POST(self):
        form = web.input(title="",
                         rating="",
                         friends="",
                         members="",
                         content="",
                         tags="")

        tags = searchtag.parse_tags(form.tags)

        if not define.config_read_bool("allow_submit"):
            raise WeasylError("FeatureDisabled")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        j = orm.Journal()
        j.title = form.title
        j.rating = rating
        j.content = form.content
        journalid = journal.create(self.user_id,
                                   j,
                                   friends_only=form.friends,
                                   tags=tags)
        raise web.seeother("/journal/%i/%s" %
                           (journalid, slug_for(form.title)))
Esempio n. 19
0
    def GET(self, charid=""):
        form = web.input(charid="", ignore="", anyway="")

        rating = define.get_rating(self.user_id)
        charid = define.get_int(charid) if charid else define.get_int(form.charid)

        try:
            item = character.select_view(
                self.user_id, charid, rating,
                ignore=define.text_bool(form.ignore, True), anyway=form.anyway
            )
        except WeasylError as we:
            if we.value in ("UserIgnored", "TagBlocked"):
                we.errorpage_kwargs['links'] = [
                    ("View Character", "?ignore=false"),
                    ("Return to the Home Page", "/index"),
                ]
            raise

        canonical_url = "/character/%d/%s" % (charid, slug_for(item["title"]))

        page = define.common_page_start(self.user_id, canonical_url=canonical_url, title=item["title"])
        page.append(define.render('detail/character.html', [
            # Profile
            profile.select_myself(self.user_id),
            # Character detail
            item,
            # Violations
            [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000],
        ]))

        return define.common_page_end(self.user_id, page)
Esempio n. 20
0
def submit_journal_post_(request):
    form = request.web_input(title="",
                             rating="",
                             friends="",
                             members="",
                             content="",
                             tags="")

    tags = searchtag.parse_tags(form.tags)

    if not define.config_read_bool("allow_submit"):
        raise WeasylError("FeatureDisabled")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    j = orm.Journal()
    j.title = form.title
    j.rating = rating
    j.content = form.content
    journalid = journal.create(request.userid,
                               j,
                               friends_only=form.friends,
                               tags=tags)
    raise HTTPSeeOther(location="/journal/%i/%s" %
                       (journalid, slug_for(form.title)))
Esempio n. 21
0
def submit_visual_post_(request):
    form = request.web_input(submitfile="", thumbfile="", title="", folderid="",
                             subtype="", rating="", friends="", critique="", content="",
                             tags="", imageURL="")

    tags = searchtag.parse_tags(form.tags)

    if not define.config_read_bool("allow_submit"):
        raise WeasylError("FeatureDisabled")

    if not define.is_vouched_for(request.userid):
        raise WeasylError("vouchRequired")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    s = orm.Submission()
    s.title = form.title
    s.rating = rating
    s.content = form.content
    s.folderid = define.get_int(form.folderid) or None
    s.subtype = define.get_int(form.subtype)
    s.submitter_ip_address = request.client_addr
    s.submitter_user_agent_id = get_user_agent_id(ua_string=request.user_agent)

    submitid = submission.create_visual(
        request.userid, s, friends_only=form.friends, tags=tags,
        imageURL=form.imageURL, thumbfile=form.thumbfile, submitfile=form.submitfile,
        critique=form.critique, create_notifications=('nonotification' not in form))

    if 'customthumb' in form:
        raise HTTPSeeOther(location="/manage/thumbnail?submitid=%i" % (submitid,))
    else:
        raise HTTPSeeOther(location="/submission/%i/%s" % (submitid, slug_for(form.title)))
Esempio n. 22
0
def twitter_card(submitid):
    query = d.execute(
        """
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url':
        d.absolutify_url('/submission/%s/%s' %
                         (submitid, text.slug_for(title))),
    }

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

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(
            media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get(
            'thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret
Esempio n. 23
0
 def canonical_path(self, request, operation='view', with_slug=None, mod=False):
     if with_slug is None:
         with_slug = operation == 'view'
     parts = ['submissions', str(self.submitid), operation]
     if mod:
         parts.insert(2, 'mod')
     if with_slug:
         parts.append(slug_for(self.title))
     return request.resource_path(None, *parts)
Esempio n. 24
0
def twitter_card(submitid):
    query = d.execute("""
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url': d.absolutify_url(
            '/submission/%s/%s' % (submitid, text.slug_for(title))),
    }

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

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get('thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret
Esempio n. 25
0
def format_media_link(media, link):
    request = get_current_request()
    if link.link_type == 'submission':
        login_name = link.submission.owner.login_name
        return request.resource_path(
            None, '~' + login_name, 'submissions', str(link.submitid), 'media', 'submission',
            '%s-%s-%s.%s' % (
                login_name, slug_for(link.submission.title), media.mediaid,
                media.file_type))
    else:
        return None
Esempio n. 26
0
def format_media_link(media, link):
    request = get_current_request()
    if link.link_type == 'submission':
        login_name = link.submission.owner.login_name
        return request.resource_path(
            None, '~' + login_name, 'submissions', str(link.submitid), 'media',
            'submission',
            '%s-%s-%s.%s' % (login_name, slug_for(
                link.submission.title), media.mediaid, media.file_type))
    else:
        return None
Esempio n. 27
0
def format_media_link(media, link):
    if link.link_type == 'submission':
        login_name = link.submission.owner.login_name
        formatted_url = '/~%s/submissions/%s/%s/%s-%s.%s' % (
            login_name, link.submitid, media.sha256, login_name,
            slug_for(link.submission.title), media.file_type)
        return define.cdnify_url(formatted_url)
    elif link.link_type in ['cover', 'thumbnail-custom', 'thumbnail-legacy',
                            'thumbnail-generated', 'avatar', 'banner']:
        return define.cdnify_url(media.display_url)
    else:
        return None
Esempio n. 28
0
def format_media_link(media, link):
    if link.link_type == 'submission':
        login_name = link.submission.owner.login_name
        formatted_url = '/~%s/submissions/%s/%s/%s-%s.%s' % (
            login_name, link.submitid, media.sha256, login_name,
            slug_for(link.submission.title), media.file_type)
        return define.cdnify_url(formatted_url)
    elif link.link_type in ['cover', 'thumbnail-custom', 'thumbnail-legacy',
                            'thumbnail-generated', 'avatar', 'banner']:
        return define.cdnify_url(media.display_url)
    else:
        return None
Esempio n. 29
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. 30
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. 31
0
 def canonical_path(self,
                    request,
                    operation='view',
                    with_slug=None,
                    mod=False):
     if with_slug is None:
         with_slug = operation == 'view'
     parts = ['submissions', str(self.submitid), operation]
     if mod:
         parts.insert(2, 'mod')
     if with_slug:
         parts.append(slug_for(self.title))
     return request.resource_path(None, *parts)
Esempio n. 32
0
def submit_multimedia_post_(request):
    form = request.web_input(submitfile="",
                             coverfile="",
                             thumbfile="",
                             embedlink="",
                             title="",
                             folderid="",
                             subtype="",
                             rating="",
                             friends="",
                             critique="",
                             content="",
                             tags="")

    tags = searchtag.parse_tags(form.tags)

    if not define.config_read_bool("allow_submit"):
        raise WeasylError("FeatureDisabled")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    s = orm.Submission()
    s.title = form.title
    s.rating = rating
    s.content = form.content
    s.folderid = define.get_int(form.folderid) or None
    s.subtype = define.get_int(form.subtype)

    autothumb = ('noautothumb' not in form)

    submitid, thumb = submission.create_multimedia(
        request.userid,
        s,
        embedlink=form.embedlink,
        friends_only=form.friends,
        tags=tags,
        coverfile=form.coverfile,
        thumbfile=form.thumbfile,
        submitfile=form.submitfile,
        critique=form.critique,
        create_notifications=('nonotification' not in form),
        auto_thumb=autothumb)
    if thumb and not autothumb:
        raise HTTPSeeOther(location="/manage/thumbnail?submitid=%i" %
                           (submitid, ))
    else:
        raise HTTPSeeOther(location="/submission/%i/%s" %
                           (submitid, slug_for(form.title)))
Esempio n. 33
0
    def legacy_path(self, mod=False):
        """
        Create the weasyl-old relative URL for a submission.

        Parameters:
            mod (bool): Whether or not to suffix ``?anyway=true`` on the URL for
                moderators.

        Returns:
            The relative URL.
        """
        ret = '/submission/%d/%s' % (self.submitid, slug_for(self.title))
        if mod:
            ret += '?anyway=true'
        return ret
Esempio n. 34
0
    def legacy_path(self, mod=False):
        """
        Create the weasyl-old relative URL for a submission.

        Parameters:
            mod (bool): Whether or not to suffix ``?anyway=true`` on the URL for
                moderators.

        Returns:
            The relative URL.
        """
        ret = '/submission/%d/%s' % (self.submitid, slug_for(self.title))
        if mod:
            ret += '?anyway=true'
        return ret
Esempio n. 35
0
    def POST(self):
        form = web.input(journalid="", title="", rating="", friends="", content="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        j = orm.Journal()
        j.journalid = define.get_int(form.journalid)
        j.title = form.title
        j.rating = rating
        j.content = form.content
        journal.edit(self.user_id, j, friends_only=form.friends)
        raise web.seeother("/journal/%i/%s%s" % (define.get_int(form.journalid),
                                                 slug_for(form.title),
                                                 ("?anyway=true" if self.user_id in staff.MODS else '')))
Esempio n. 36
0
    def POST(self):
        form = web.input(submitfile="",
                         coverfile="boop",
                         thumbfile="",
                         title="",
                         folderid="",
                         subtype="",
                         rating="",
                         friends="",
                         critique="",
                         content="",
                         tags="",
                         embedlink="")

        tags = searchtag.parse_tags(form.tags)

        if not define.config_read_bool("allow_submit"):
            raise WeasylError("FeatureDisabled")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        s = orm.Submission()
        s.title = form.title
        s.rating = rating
        s.content = form.content
        s.folderid = define.get_int(form.folderid) or None
        s.subtype = define.get_int(form.subtype)

        submitid, thumb = submission.create_literary(
            self.user_id,
            s,
            embedlink=form.embedlink,
            friends_only=form.friends,
            tags=tags,
            coverfile=form.coverfile,
            thumbfile=form.thumbfile,
            submitfile=form.submitfile,
            critique=form.critique,
            create_notifications=('nonotification' not in form))
        if thumb:
            raise web.seeother("/manage/thumbnail?submitid=%i" % (submitid, ))
        else:
            raise web.seeother("/submission/%i/%s" %
                               (submitid, slug_for(form.title)))
Esempio n. 37
0
def edit_journal_post_(request):
    form = request.web_input(journalid="", title="", rating="", friends="", content="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    j = orm.Journal()
    j.journalid = define.get_int(form.journalid)
    j.title = form.title
    j.rating = rating
    j.content = form.content
    journal.edit(request.userid, j, friends_only=form.friends)
    raise HTTPSeeOther(location="/journal/%i/%s%s" % (
        define.get_int(form.journalid),
        slug_for(form.title),
        ("?anyway=true" if request.userid in staff.MODS else '')
    ))
Esempio n. 38
0
def edit_journal_post_(request):
    form = request.web_input(journalid="", title="", rating="", friends="", content="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    j = orm.Journal()
    j.journalid = define.get_int(form.journalid)
    j.title = form.title
    j.rating = rating
    j.content = form.content
    journal.edit(request.userid, j, friends_only=form.friends)
    raise HTTPSeeOther(location="/journal/%i/%s%s" % (
        define.get_int(form.journalid),
        slug_for(form.title),
        ("?anyway=true" if request.userid in staff.MODS else '')
    ))
Esempio n. 39
0
    def GET(self, journalid=""):
        form = web.input(journalid="", ignore="", anyway="")

        rating = define.get_rating(self.user_id)
        journalid = define.get_int(journalid) if journalid else define.get_int(
            form.journalid)

        try:
            item = journal.select_view(self.user_id,
                                       rating,
                                       journalid,
                                       ignore=define.text_bool(
                                           form.ignore, True),
                                       anyway=form.anyway)
        except WeasylError as we:
            if we.value in ("UserIgnored", "TagBlocked"):
                we.errorpage_kwargs['links'] = [
                    ("View Journal", "?ignore=false"),
                    ("Return to the Home Page", "/index"),
                ]
            raise

        canonical_url = "/journal/%d/%s" % (journalid, slug_for(item["title"]))

        page = define.common_page_start(self.user_id,
                                        options=["pager"],
                                        canonical_url=canonical_url,
                                        title=item["title"])
        page.append(
            define.render(
                template.detail_journal,
                [
                    # Myself
                    profile.select_myself(self.user_id),
                    # Journal detail
                    item,
                    # Violations
                    [
                        i for i in macro.MACRO_REPORT_VIOLATION
                        if 3000 <= i[0] < 4000
                    ],
                ]))

        return define.common_page_end(self.user_id, page)
Esempio n. 40
0
    def POST(self):
        form = web.input(title="", rating="", friends="", members="", content="", tags="")

        tags = searchtag.parse_tags(form.tags)

        if not define.config_read_bool("allow_submit"):
            raise WeasylError("FeatureDisabled")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        j = orm.Journal()
        j.title = form.title
        j.rating = rating
        j.content = form.content
        journalid = journal.create(self.user_id, j, friends_only=form.friends,
                                   tags=tags)
        raise web.seeother("/journal/%i/%s" % (journalid, slug_for(form.title)))
Esempio n. 41
0
def submit_journal_post_(request):
    form = request.web_input(title="", rating="", friends="", members="", content="", tags="")

    tags = searchtag.parse_tags(form.tags)

    if not define.config_read_bool("allow_submit"):
        raise WeasylError("FeatureDisabled")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    j = orm.Journal()
    j.title = form.title
    j.rating = rating
    j.content = form.content
    journalid = journal.create(request.userid, j, friends_only=form.friends,
                               tags=tags)
    raise HTTPSeeOther(location="/journal/%i/%s" % (journalid, slug_for(form.title)))
Esempio n. 42
0
    def POST(self):
        form = web.input(journalid="",
                         title="",
                         rating="",
                         friends="",
                         content="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        j = orm.Journal()
        j.journalid = define.get_int(form.journalid)
        j.title = form.title
        j.rating = rating
        j.content = form.content
        journal.edit(self.user_id, j, friends_only=form.friends)
        raise web.seeother(
            "/journal/%i/%s%s" %
            (define.get_int(form.journalid), slug_for(form.title),
             ("?anyway=true" if self.user_id in staff.MODS else '')))
Esempio n. 43
0
    def POST(self):
        form = web.input(submitid="", title="", folderid="", subtype="", rating="",
                         content="", friends="", critique="", embedlink="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        s = orm.Submission()
        s.submitid = define.get_int(form.submitid)
        s.title = form.title
        s.rating = rating
        s.content = form.content
        s.folderid = define.get_int(form.folderid) or None
        s.subtype = define.get_int(form.subtype)

        submission.edit(self.user_id, s, embedlink=form.embedlink,
                        friends_only=form.friends, critique=form.critique)
        raise web.seeother("/submission/%i/%s%s" % (define.get_int(form.submitid),
                                                    slug_for(form.title),
                                                    "?anyway=true" if self.user_id in staff.MODS else ''))
Esempio n. 44
0
    def POST(self):
        form = web.input(charid="", title="", age="", gender="", height="",
                         weight="", species="", rating="", content="", friends="")

        rating = ratings.CODE_MAP.get(define.get_int(form.rating))
        if not rating:
            raise WeasylError("ratingInvalid")

        c = orm.Character()
        c.charid = define.get_int(form.charid)
        c.age = form.age
        c.gender = form.gender
        c.height = form.height
        c.weight = form.weight
        c.species = form.species
        c.char_name = form.title
        c.content = form.content
        c.rating = rating

        character.edit(self.user_id, c, friends_only=form.friends)
        raise web.seeother("/character/%i/%s%s" % (define.get_int(form.charid),
                                                   slug_for(form.title),
                                                   ("?anyway=true" if self.user_id in staff.MODS else '')))
Esempio n. 45
0
def edit_submission_post_(request):
    form = request.web_input(submitid="", title="", folderid="", subtype="", rating="",
                             content="", friends="", critique="", embedlink="")

    rating = ratings.CODE_MAP.get(define.get_int(form.rating))
    if not rating:
        raise WeasylError("ratingInvalid")

    s = orm.Submission()
    s.submitid = define.get_int(form.submitid)
    s.title = form.title
    s.rating = rating
    s.content = form.content
    s.folderid = define.get_int(form.folderid) or None
    s.subtype = define.get_int(form.subtype)

    submission.edit(request.userid, s, embedlink=form.embedlink,
                    friends_only=form.friends, critique=form.critique)
    raise HTTPSeeOther(location="/submission/%i/%s%s" % (
        define.get_int(form.submitid),
        slug_for(form.title),
        "?anyway=true" if request.userid in staff.MODS else ''
    ))
Esempio n. 46
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. 47
0
def _post_to_twitter_about(submitid, title, rating, tags):
    url = d.absolutify_url('/submission/%s/%s' %
                           (submitid, text.slug_for(title)))

    st = d.meta.tables['searchtag']
    sms = d.meta.tables['searchmapsubmit']
    q = (sa.select([st.c.title]).select_from(
        st.join(sms, st.c.tagid == sms.c.tagid)).where(
            st.c.title.in_(t.lower() for t in tags)).group_by(
                st.c.title).order_by(sa.func.count().desc()))

    account = 'WeasylCritique'
    if rating in (ratings.MATURE.code, ratings.EXPLICIT.code):
        account = 'WZLCritiqueNSFW'
    length = 26
    selected_tags = []
    db = d.connect()
    for tag, in db.execute(q):
        if len(tag) + 2 + length > 140:
            break
        selected_tags.append('#' + tag)
        length += len(tag) + 2

    twits.post(account, u'%s %s' % (url, ' '.join(selected_tags)))
Esempio n. 48
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),
        '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,
    }
Esempio n. 49
0
def _post_to_twitter_about(submitid, title, rating, tags):
    url = d.absolutify_url('/submission/%s/%s' % (submitid, text.slug_for(title)))

    st = d.meta.tables['searchtag']
    sms = d.meta.tables['searchmapsubmit']
    q = (sa.select([st.c.title])
         .select_from(st.join(sms, st.c.tagid == sms.c.tagid))
         .where(st.c.title.in_(t.lower() for t in tags))
         .group_by(st.c.title)
         .order_by(sa.func.count().desc()))

    account = 'WeasylCritique'
    if rating in (ratings.MATURE.code, ratings.EXPLICIT.code):
        account = 'WZLCritiqueNSFW'
    length = 26
    selected_tags = []
    db = d.connect()
    for tag, in db.execute(q):
        if len(tag) + 2 + length > 140:
            break
        selected_tags.append('#' + tag)
        length += len(tag) + 2

    twits.post(account, u'%s %s' % (url, ' '.join(selected_tags)))
Esempio n. 50
0
def submission_(request):
    username = request.matchdict.get('name')
    submitid = request.matchdict.get('submitid')

    form = request.web_input(submitid="", ignore="", anyway="")

    rating = define.get_rating(request.userid)
    submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid)

    extras = {
        "pdf": True,
    }

    if define.user_is_twitterbot():
        extras['twitter_card'] = submission.twitter_card(submitid)

    try:
        item = submission.select_view(
            request.userid, submitid, rating,
            ignore=define.text_bool(form.ignore, True), anyway=form.anyway
        )
    except WeasylError as we:
        we.errorpage_kwargs = extras
        if 'twitter_card' in extras:
            extras['options'] = ['nocache']
        if we.value in ("UserIgnored", "TagBlocked"):
            extras['links'] = [
                ("View Submission", "?ignore=false"),
                ("Return to the Home Page", "/index"),
            ]
        raise

    login = define.get_sysname(item['username'])
    canonical_path = request.route_path('submission_detail_profile', name=login, submitid=submitid, slug=slug_for(item['title']))

    if request.GET.get('anyway'):
        canonical_path += '?anyway=true'

    if login != username:
        raise httpexceptions.HTTPMovedPermanently(location=canonical_path)
    extras["canonical_url"] = canonical_path
    extras["title"] = item["title"]

    page = define.common_page_start(request.userid, **extras)
    page.append(define.render('detail/submission.html', [
        # Myself
        profile.select_myself(request.userid),
        # Submission detail
        item,
        # Subtypes
        macro.MACRO_SUBCAT_LIST,
        # Violations
        [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000],
    ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 51
0
    def GET(self, a="", b=None):
        if b is None:
            username, submitid = None, a
        else:
            username, submitid = a, b
        now = time.time()

        form = web.input(submitid="", ignore="", anyway="")

        rating = define.get_rating(self.user_id)
        submitid = define.get_int(submitid) if submitid else define.get_int(
            form.submitid)

        extras = {
            "pdf": True,
        }

        if define.user_is_twitterbot():
            extras['twitter_card'] = submission.twitter_card(submitid)

        try:
            item = submission.select_view(self.user_id,
                                          submitid,
                                          rating,
                                          ignore=define.text_bool(
                                              form.ignore, True),
                                          anyway=form.anyway)
        except WeasylError as we:
            we.errorpage_kwargs = extras
            if 'twitter_card' in extras:
                extras['options'] = ['nocache']
            if we.value in ("UserIgnored", "TagBlocked"):
                extras['links'] = [
                    ("View Submission", "?ignore=false"),
                    ("Return to the Home Page", "/index"),
                ]
            raise

        login = define.get_sysname(item['username'])
        if username is not None and login != username:
            raise web.seeother('/~%s/post/%s/%s' %
                               (login, submitid, slug_for(item["title"])))
        extras["canonical_url"] = "/submission/%d/%s" % (
            submitid, slug_for(item["title"]))
        extras["title"] = item["title"]

        page = define.common_page_start(self.user_id,
                                        options=["mediaplayer"],
                                        **extras)
        page.append(
            define.render(
                template.detail_submission,
                [
                    # Myself
                    profile.select_myself(self.user_id),
                    # Submission detail
                    item,
                    # Subtypes
                    macro.MACRO_SUBCAT_LIST,
                    # Violations
                    [
                        i for i in macro.MACRO_REPORT_VIOLATION
                        if 2000 <= i[0] < 3000
                    ],
                ]))

        return define.common_page_end(self.user_id, page, now=now)
Esempio n. 52
0
def submission_(request):
    username = request.matchdict.get('name')
    submitid = request.matchdict.get('submitid')

    form = request.web_input(submitid="", ignore="", anyway="")

    rating = define.get_rating(request.userid)
    submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid)

    extras = {}

    if not request.userid:
        # Only generate the Twitter/OGP meta headers if not authenticated (the UA viewing is likely automated).
        twit_card = submission.twitter_card(submitid)
        if define.user_is_twitterbot():
            extras['twitter_card'] = twit_card
        # The "og:" prefix is specified in page_start.html, and og:image is required by the OGP spec, so something must be in there.
        extras['ogp'] = {
            'title': twit_card['title'],
            'site_name': "Weasyl",
            'type': "website",
            'url': twit_card['url'],
            'description': twit_card['description'],
            # >> BUG AVOIDANCE: https://trello.com/c/mBx51jfZ/1285-any-image-link-with-in-it-wont-preview-up-it-wont-show-up-in-embeds-too
            #    Image URLs with '~' in it will not be displayed by Discord, so replace ~ with the URL encoded char code %7E
            'image': twit_card['image:src'].replace('~', '%7E') if 'image:src' in twit_card else define.cdnify_url(
                '/static/images/logo-mark-light.svg'),
        }

    try:
        item = submission.select_view(
            request.userid, submitid, rating,
            ignore=define.text_bool(form.ignore, True), anyway=form.anyway
        )
    except WeasylError as we:
        we.errorpage_kwargs = extras
        if we.value in ("UserIgnored", "TagBlocked"):
            extras['links'] = [
                ("View Submission", "?ignore=false"),
                ("Return to the Home Page", "/index"),
            ]
        raise

    login = define.get_sysname(item['username'])
    canonical_path = request.route_path('submission_detail_profile', name=login, submitid=submitid, slug=slug_for(item['title']))

    if request.GET.get('anyway'):
        canonical_path += '?anyway=true'

    if login != username:
        raise httpexceptions.HTTPMovedPermanently(location=canonical_path)
    extras["canonical_url"] = canonical_path
    extras["title"] = item["title"]

    submission_files = item["sub_media"].get("submission")
    submission_file = submission_files[0] if submission_files else None
    extras["pdf"] = bool(submission_file) and submission_file["file_type"] == "pdf"

    page = define.common_page_start(request.userid, **extras)
    page.append(define.render('detail/submission.html', [
        # Myself
        profile.select_myself(request.userid),
        # Submission detail
        item,
        # Subtypes
        macro.MACRO_SUBCAT_LIST,
        # Violations
        [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000],
    ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 53
0
def submission_(request):
    username = request.matchdict.get('name')
    submitid = request.matchdict.get('submitid')

    form = request.web_input(submitid="", ignore="", anyway="")

    rating = define.get_rating(request.userid)
    submitid = define.get_int(submitid) if submitid else define.get_int(
        form.submitid)

    extras = {
        "pdf": True,
    }

    if define.user_is_twitterbot():
        extras['twitter_card'] = submission.twitter_card(submitid)

    try:
        item = submission.select_view(request.userid,
                                      submitid,
                                      rating,
                                      ignore=define.text_bool(
                                          form.ignore, True),
                                      anyway=form.anyway)
    except WeasylError as we:
        we.errorpage_kwargs = extras
        if 'twitter_card' in extras:
            extras['options'] = ['nocache']
        if we.value in ("UserIgnored", "TagBlocked"):
            extras['links'] = [
                ("View Submission", "?ignore=false"),
                ("Return to the Home Page", "/index"),
            ]
        raise

    login = define.get_sysname(item['username'])
    if username is not None and login != username:
        raise httpexceptions.HTTPSeeOther(
            location='/~%s/post/%s/%s' %
            (login, submitid, slug_for(item["title"])))
    extras["canonical_url"] = "/submission/%d/%s" % (submitid,
                                                     slug_for(item["title"]))
    extras["title"] = item["title"]

    page = define.common_page_start(request.userid, **extras)
    page.append(
        define.render(
            'detail/submission.html',
            [
                # Myself
                profile.select_myself(request.userid),
                # Submission detail
                item,
                # Subtypes
                macro.MACRO_SUBCAT_LIST,
                # Violations
                [
                    i for i in macro.MACRO_REPORT_VIOLATION
                    if 2000 <= i[0] < 3000
                ],
            ]))

    return Response(define.common_page_end(request.userid, page))