Esempio n. 1
0
    def test_blocked_tag(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # submission s1 has a walrus in it, but user2 does not like walruses
        s1 = db_utils.create_submission(user1, rating=ratings.GENERAL.code)
        tag1 = db_utils.create_tag("walrus")
        db_utils.create_submission_tag(tag1, s1)
        db_utils.create_blocktag(user2, tag1, ratings.GENERAL.code)
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # submission s2 has a penguin in it. user2 does not want to see penguins in
        # adult circumstances, but s2 is general, so visibility is OK
        s2 = db_utils.create_submission(user1, rating=ratings.GENERAL.code)
        tag2 = db_utils.create_tag("penguin")
        db_utils.create_submission_tag(tag2, s2)
        db_utils.create_blocktag(user2, tag2, ratings.EXPLICIT.code)
        self.assertEqual(
            1, len(submission.select_list(user2, ratings.EXPLICIT.code, 10)))

        # submission s3 has penguins on it in adult situations, but User2
        # is okay with that if it's one of User2's own submissions.
        s3 = db_utils.create_submission(user2, rating=ratings.EXPLICIT.code)
        db_utils.create_submission_tag(tag2, s3)
        self.assertEqual(
            2, len(submission.select_list(user2, ratings.EXPLICIT.code, 10)))
Esempio n. 2
0
    def test_friends_only(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        db_utils.create_submission(user1,
                                   rating=ratings.GENERAL.code,
                                   settings=CharSettings({'friends-only'}, {},
                                                         {}))

        # poster can view their submission
        self.assertEqual(
            1, len(submission.select_list(user1, ratings.GENERAL.code, 10)))

        # but a non-friend or a non-logged in user cannot
        self.assertEqual(
            0, len(submission.select_list(None, ratings.GENERAL.code, 10)))
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # user with a pending friendship cannot view
        db_utils.create_friendship(user1,
                                   user2,
                                   settings=CharSettings({'pending'}, {}, {}))
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # but a friend can
        d.sessionmaker().query(users.Friendship).delete()
        db_utils.create_friendship(user1, user2)
        self.assertEqual(
            1, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
Esempio n. 3
0
    def test_friends_only(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, settings=CharSettings({'friends-only'}, {}, {}))

        # poster can view their submission
        self.assertEqual(
            1, len(submission.select_list(user1, ratings.GENERAL.code, 10)))

        # but a non-friend or a non-logged in user cannot
        self.assertEqual(
            0, len(submission.select_list(None, ratings.GENERAL.code, 10)))
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # user with a pending friendship cannot view
        db_utils.create_friendship(user1, user2, settings=CharSettings({'pending'}, {}, {}))
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # but a friend can
        d.sessionmaker().query(users.Friendship).delete()
        db_utils.create_friendship(user1, user2)
        self.assertEqual(
            1, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
Esempio n. 4
0
    def test_blocked_tag(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # submission s1 has a walrus in it, but user2 does not like walruses
        s1 = db_utils.create_submission(user1, rating=ratings.GENERAL.code)
        tag1 = db_utils.create_tag("walrus")
        db_utils.create_submission_tag(tag1, s1)
        db_utils.create_blocktag(user2, tag1, ratings.GENERAL.code)
        self.assertEqual(
            0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))

        # submission s2 has a penguin in it. user2 does not want to see penguins in
        # adult circumstances, but s2 is general, so visibility is OK
        s2 = db_utils.create_submission(user1, rating=ratings.GENERAL.code)
        tag2 = db_utils.create_tag("penguin")
        db_utils.create_submission_tag(tag2, s2)
        db_utils.create_blocktag(user2, tag2, ratings.EXPLICIT.code)
        self.assertEqual(
            1, len(submission.select_list(user2, ratings.EXPLICIT.code, 10)))

        # submission s3 has penguins on it in adult situations, but User2
        # is okay with that if it's one of User2's own submissions.
        s3 = db_utils.create_submission(user2, rating=ratings.EXPLICIT.code)
        db_utils.create_submission_tag(tag2, s3)
        self.assertEqual(
            2, len(submission.select_list(user2, ratings.EXPLICIT.code, 10)))
Esempio n. 5
0
 def test_feature_page_filter(self):
     user1 = db_utils.create_user()
     folder = db_utils.create_folder(
         user1, settings=CharSettings({"featured-filter"}, {}, {}))
     db_utils.create_submissions(9, user1, ratings.GENERAL.code)
     db_utils.create_submission(user1, ratings.GENERAL.code, folderid=folder)
     self.assertEqual(
         10, len(submission.select_list(user1, ratings.GENERAL.code, 10)))
     self.assertEqual(
         1, len(submission.select_list(user1, ratings.GENERAL.code, 10,
                                       featured_filter=True)))
Esempio n. 6
0
 def test_feature_page_filter(self):
     user1 = db_utils.create_user()
     folder = db_utils.create_folder(
         user1, settings=CharSettings({"featured-filter"}, {}, {}))
     db_utils.create_submissions(9, user1, ratings.GENERAL.code)
     db_utils.create_submission(user1, ratings.GENERAL.code, folderid=folder)
     self.assertEqual(
         10, len(submission.select_list(user1, ratings.GENERAL.code, 10)))
     self.assertEqual(
         1, len(submission.select_list(user1, ratings.GENERAL.code, 10,
                                       featured_filter=True)))
Esempio n. 7
0
 def test_ignored_user(self):
     user1 = db_utils.create_user()
     user2 = db_utils.create_user()
     db_utils.create_submission(user1, rating=ratings.GENERAL.code)
     # can view the submission
     self.assertEqual(
         1, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
     # user2 blocks user1
     db_utils.create_ignoreuser(user2, user1)
     # user2 can no longer view the submission
     self.assertEqual(
         0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
     # but a non-logged in user can
     self.assertEqual(
         1, len(submission.select_list(None, ratings.GENERAL.code, 10)))
Esempio n. 8
0
    def test_filters(self):
        # Test filters of the following:
        # userid, folderid, category, hidden
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        folder = db_utils.create_folder(user1)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, folderid=folder)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, subtype=1010)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, settings=CharSettings({'hidden'}, {}, {}))
        db_utils.create_submission(user2, rating=ratings.GENERAL.code)

        self.assertEqual(3, len(submission.select_list(user1, ratings.EXPLICIT.code, 10)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, otherid=user2)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, folderid=folder)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, subcat=1010)))
Esempio n. 9
0
 def test_ignored_user(self):
     user1 = db_utils.create_user()
     user2 = db_utils.create_user()
     db_utils.create_submission(user1, rating=ratings.GENERAL.code)
     # can view the submission
     self.assertEqual(
         1, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
     # user2 blocks user1
     db_utils.create_ignoreuser(user2, user1)
     # user2 can no longer view the submission
     self.assertEqual(
         0, len(submission.select_list(user2, ratings.GENERAL.code, 10)))
     # but a non-logged in user can
     self.assertEqual(
         1, len(submission.select_list(None, ratings.GENERAL.code, 10)))
Esempio n. 10
0
    def test_filters(self):
        # Test filters of the following:
        # userid, folderid, category, hidden
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        folder = db_utils.create_folder(user1)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, folderid=folder)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, subtype=1010)
        db_utils.create_submission(user1, rating=ratings.GENERAL.code, settings=CharSettings({'hidden'}, {}, {}))
        db_utils.create_submission(user2, rating=ratings.GENERAL.code)

        self.assertEqual(3, len(submission.select_list(user1, ratings.EXPLICIT.code, 10)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, otherid=user2)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, folderid=folder)))
        self.assertEqual(1, len(submission.select_list(user1, ratings.EXPLICIT.code, 10, subcat=1010)))
Esempio n. 11
0
    def test_ratings(self):
        # Create a bunch of submissions with different ratings, check counts
        # Check that a user will see their own submissions even if the rating is off
        # Check that non-logged-in user will see only general ratings.
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        db_utils.create_submission(user1, rating=ratings.GENERAL.code)
        db_utils.create_submission(user1, rating=ratings.MATURE.code)
        db_utils.create_submission(user1, rating=ratings.EXPLICIT.code)
        self.assertEqual(3, len(submission.select_list(user2, ratings.EXPLICIT.code, 10, config="l")))
        self.assertEqual(2, len(submission.select_list(user2, ratings.MATURE.code, 10, config="l")))
        self.assertEqual(1, len(submission.select_list(user2, ratings.GENERAL.code, 10, config="l")))

        # A user sees their own submissions regardless of the rating level
        self.assertEqual(3, len(submission.select_list(
            user1, ratings.GENERAL.code, 10, otherid=user1)))
Esempio n. 12
0
def browse(userid, rating, limit, form, find=None):
    backid = d.get_int(form.backid)
    nextid = d.get_int(form.nextid)

    if find:
        form.find = find

    if form.find == "char":
        return character.select_list(userid,
                                     rating,
                                     limit,
                                     backid=backid,
                                     nextid=nextid)
    elif form.find == "journal":
        return journal.select_user_list(userid,
                                        rating,
                                        limit,
                                        backid=backid,
                                        nextid=nextid)
    else:
        return submission.select_list(
            userid,
            rating,
            limit,
            backid=backid,
            nextid=nextid,
            subcat=d.get_int(form.cat)
            if d.get_int(form.cat) in [1000, 2000, 3000] else None)
Esempio n. 13
0
File: api.py Progetto: Weasyl/weasyl
def api_user_gallery_(request):
    userid = profile.resolve_by_login(request.matchdict['login'])
    if not userid:
        raise WeasylError('userRecordMissing')

    form = request.web_input(since=None, count=0, folderid=0, backid=0, nextid=0)
    since = None
    try:
        if form.since:
            since = d.parse_iso8601(form.since)
        count = int(form.count)
        folderid = int(form.folderid)
        backid = int(form.backid)
        nextid = int(form.nextid)
    except ValueError:
        raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED)
    else:
        count = min(count or 100, 100)

    submissions = submission.select_list(
        request.userid, d.get_rating(request.userid), count + 1,
        otherid=userid, folderid=folderid, backid=backid, nextid=nextid)
    backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid')

    ret = []
    for sub in submissions:
        if since is not None and since >= sub['unixtime']:
            break
        tidy_submission(sub)
        ret.append(sub)

    return {
        'backid': backid, 'nextid': nextid,
        'submissions': ret,
    }
Esempio n. 14
0
def api_user_gallery_(request):
    userid = profile.resolve_by_login(d.get_sysname(request.matchdict['login']))
    if not userid:
        raise WeasylError('userRecordMissing')

    form = request.web_input(since=None, count=0, folderid=0, backid=0, nextid=0)
    since = None
    try:
        if form.since:
            since = d.parse_iso8601(form.since)
        count = int(form.count)
        folderid = int(form.folderid)
        backid = int(form.backid)
        nextid = int(form.nextid)
    except ValueError:
        raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED)
    else:
        count = min(count or 100, 100)

    submissions = submission.select_list(
        request.userid, d.get_rating(request.userid), count + 1,
        otherid=userid, folderid=folderid, backid=backid, nextid=nextid)
    backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid')

    ret = []
    for sub in submissions:
        if since is not None and since >= sub['unixtime']:
            break
        tidy_submission(sub)
        ret.append(sub)

    return {
        'backid': backid, 'nextid': nextid,
        'submissions': ret,
    }
Esempio n. 15
0
def recent_submissions():
    submissions = []
    for category in m.ALL_SUBMISSION_CATEGORIES:
        submissions.extend(
            submission.select_list(userid=None,
                                   rating=ratings.EXPLICIT.code,
                                   limit=256,
                                   subcat=category,
                                   index_page_filter=True))

    tag_map = searchtag.select_list(d.meta.tables['searchmapsubmit'],
                                    [s['submitid'] for s in submissions])
    for s in submissions:
        s['tags'] = tag_map.get(s['submitid'], [])

    characters = character.select_list(userid=None,
                                       rating=ratings.EXPLICIT.code,
                                       limit=256)
    tag_map = searchtag.select_list(d.meta.tables['searchmapchar'],
                                    [c['charid'] for c in characters])
    for c in characters:
        c['tags'] = tag_map.get(c['charid'], [])

    submissions.extend(characters)
    submissions.sort(key=operator.itemgetter('unixtime'), reverse=True)
    return submissions
Esempio n. 16
0
    def test_select_list_limits(self):
        user1 = db_utils.create_user()
        submissions = db_utils.create_submissions(
            20, user1, rating=ratings.GENERAL.code)

        results = submission.select_list(user1, ratings.EXPLICIT.code, 10)
        # submissions are descending, so we get the highest numbers first
        self.assertEqual(submissions[19], results[0]['submitid'])
        self.assertEqual(10, len(results))

        results = submission.select_list(
            user1, ratings.EXPLICIT.code, 10, nextid=submissions[10])
        self.assertEqual(submissions[9], results[0]['submitid'])

        results = submission.select_list(
            user1, ratings.EXPLICIT.code, 10, backid=submissions[10])
        self.assertEqual(submissions[19], results[0]['submitid'])
Esempio n. 17
0
def browse(userid, rating, limit, find, cat, backid, nextid):
    if find == "char":
        return character.select_list(userid, rating, limit, backid=backid, nextid=nextid)
    elif find == "journal":
        return journal.select_user_list(userid, rating, limit, backid=backid, nextid=nextid)
    else:
        return submission.select_list(userid, rating, limit, backid=backid, nextid=nextid,
                                      subcat=d.get_int(cat) if d.get_int(cat) in [1000, 2000, 3000] else None)
Esempio n. 18
0
    def test_select_list_limits(self):
        user1 = db_utils.create_user()
        submissions = db_utils.create_submissions(
            20, user1, rating=ratings.GENERAL.code)

        results = submission.select_list(user1, ratings.EXPLICIT.code, 10)
        # submissions are descending, so we get the highest numbers first
        self.assertEqual(submissions[19], results[0]['submitid'])
        self.assertEqual(10, len(results))

        results = submission.select_list(
            user1, ratings.EXPLICIT.code, 10, nextid=submissions[10])
        self.assertEqual(submissions[9], results[0]['submitid'])

        results = submission.select_list(
            user1, ratings.EXPLICIT.code, 10, backid=submissions[10])
        self.assertEqual(submissions[19], results[0]['submitid'])
Esempio n. 19
0
def template_fields(userid):
    config = d.get_config(userid)
    rating = d.get_rating(userid)
    submissions = list(filter_submissions(userid, recent_submissions()))
    ret = partition_submissions(submissions)

    return ret + [
        # Recent site news update
        siteupdate.select(),
        # Recent critique submissions
        submission.select_list(userid, rating, 4, options=["critique"], config=config),
        # Currently streaming users
        profile.select_streaming(userid, rating, 4),
        # Recently popular submissions
        list(itertools.islice(filter_submissions(userid, submission.select_recently_popular(), incidence_limit=1), 11)),
    ]
Esempio n. 20
0
def template_fields(userid):
    config = d.get_config(userid)
    rating = d.get_rating(userid)
    submissions = list(filter_submissions(userid, recent_submissions()))
    ret = partition_submissions(submissions)

    return ret + [
        # Recent site news update
        siteupdate.select_last(),
        # Recent critique submissions
        submission.select_list(userid, rating, 4, options=["critique"], config=config),
        # Currently streaming users
        profile.select_streaming(userid, rating, 4),
        # Recently popular submissions
        list(itertools.islice(filter_submissions(userid, submission.select_recently_popular(), incidence_limit=1), 11)),
    ]
Esempio n. 21
0
def recent_submissions():
    submissions = []
    for category in m.ALL_SUBMISSION_CATEGORIES:
        submissions.extend(submission.select_list(
            userid=None, rating=ratings.EXPLICIT.code, limit=256, subcat=category,
            index_page_filter=True))

    tag_map = searchtag.select_list(
        d.meta.tables['searchmapsubmit'], [s['submitid'] for s in submissions])
    for s in submissions:
        s['tags'] = tag_map.get(s['submitid'], [])

    characters = character.select_list(
        userid=None, rating=ratings.EXPLICIT.code, limit=256)
    tag_map = searchtag.select_list(
        d.meta.tables['searchmapchar'], [c['charid'] for c in characters])
    for c in characters:
        c['tags'] = tag_map.get(c['charid'], [])

    submissions.extend(characters)
    submissions.sort(key=operator.itemgetter('unixtime'), reverse=True)
    return submissions
Esempio n. 22
0
def browse(userid, rating, limit, form, find=None, config=None):
    backid = d.get_int(form.backid)
    nextid = d.get_int(form.nextid)

    if find:
        form.find = find

    if form.find == "char":
        query = character.select_list(userid, rating, limit, backid=backid, nextid=nextid, config=config)
    elif form.find == "journal":
        query = journal.select_user_list(userid, rating, limit, backid=backid, nextid=nextid, config=config)
    else:
        query = submission.select_list(userid, rating, limit, backid=backid, nextid=nextid,
                                       subcat=d.get_int(form.cat) if d.get_int(form.cat) in [1000, 2000, 3000] else None,
                                       config=config)

    if query and not backid:
        backid = query[0][form.find + "id"]
    if query and not nextid:
        nextid = query[-1][form.find + "id"]

    return query
Esempio n. 23
0
def browse(userid, rating, limit, form, find=None, config=None):
    backid = d.get_int(form.backid)
    nextid = d.get_int(form.nextid)

    if find:
        form.find = find

    if form.find == "char":
        query = character.select_list(userid,
                                      rating,
                                      limit,
                                      backid=backid,
                                      nextid=nextid,
                                      config=config)
    elif form.find == "journal":
        query = journal.select_user_list(userid,
                                         rating,
                                         limit,
                                         backid=backid,
                                         nextid=nextid,
                                         config=config)
    else:
        query = submission.select_list(
            userid,
            rating,
            limit,
            backid=backid,
            nextid=nextid,
            subcat=d.get_int(form.cat)
            if d.get_int(form.cat) in [1000, 2000, 3000] else None,
            config=config)

    if query and not backid:
        backid = query[0][form.find + "id"]
    if query and not nextid:
        nextid = query[-1][form.find + "id"]

    return query
Esempio n. 24
0
    def GET(self, login):
        userid = profile.resolve_by_login(login)
        if not userid:
            web.ctx.status = '404 Not Found'
            raise WeasylError('userRecordMissing')

        form = web.input(since=None, count=0, folderid=0, backid=0, nextid=0)
        since = None
        try:
            if form.since:
                since = d.parse_iso8601(form.since)
            count = int(form.count)
            folderid = int(form.folderid)
            backid = int(form.backid)
            nextid = int(form.nextid)
        except ValueError:
            web.ctx.status = '422 Unprocessable Entity'
            return json.dumps(_ERROR_UNEXPECTED)
        else:
            count = min(count or 100, 100)

        submissions = submission.select_list(
            self.user_id, d.get_rating(self.user_id), count + 1,
            otherid=userid, folderid=folderid, backid=backid, nextid=nextid)
        backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid')

        ret = []
        for sub in submissions:
            if since is not None and since >= sub['unixtime']:
                break
            tidy_submission(sub)
            ret.append(sub)

        return json.dumps({
            'backid': backid, 'nextid': nextid,
            'submissions': ret,
        })
Esempio n. 25
0
def profile_(request):
    form = request.web_input(userid="", name="")

    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    config = define.get_config(request.userid)
    rating = define.get_rating(request.userid)
    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    extras = {
        "canonical_url": "/~" + define.get_sysname(form.name)
    }

    if not request.userid:
        # Only generate the Twitter/OGP meta headers if not authenticated (the UA viewing is likely automated).
        twit_card = profile.twitter_card(otherid)
        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'],
            'image': twit_card['image:src'] if 'image:src' in twit_card else define.cdnify_url('/static/images/logo-mark-light.svg'),
        }

    if not request.userid and "h" in userprofile['config']:
        return Response(define.errorpage(
            request.userid,
            "You cannot view this page because the owner does not allow guests to view their profile.",
            **extras))

    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    extras['title'] = u"%s's profile" % (userprofile['full_name'] if has_fullname else userprofile['username'],)

    page = define.common_page_start(request.userid, **extras)
    define.common_view_content(request.userid, otherid, "profile")

    if 'O' in userprofile['config']:
        submissions = collection.select_list(
            request.userid, rating, 11, otherid=otherid, options=["cover"], config=config)
        more_submissions = 'collections'
        featured = None
    elif 'A' in userprofile['config']:
        submissions = character.select_list(
            request.userid, rating, 11, otherid=otherid, options=["cover"], config=config)
        more_submissions = 'characters'
        featured = None
    else:
        submissions = submission.select_list(
            request.userid, rating, 11, otherid=otherid, options=["cover"], config=config,
            profile_page_filter=True)
        more_submissions = 'submissions'
        featured = submission.select_featured(request.userid, otherid, rating)

    if userprofile['show_favorites_bar']:
        favorites = favorite.select_submit(request.userid, rating, 11, otherid=otherid, config=config)
    else:
        favorites = None

    statistics, show_statistics = profile.select_statistics(otherid)

    page.append(define.render('user/profile.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        macro.SOCIAL_SITES,
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Myself
        profile.select_myself(request.userid),
        # Recent submissions
        submissions, more_submissions,
        favorites,
        featured,
        # Folders preview
        folder.select_preview(request.userid, otherid, rating, 3),
        # Latest journal
        journal.select_latest(request.userid, rating, otherid=otherid, config=config),
        # Recent shouts
        shout.select(request.userid, ownerid=otherid, limit=8),
        # Statistics information
        statistics,
        show_statistics,
        # Commission information
        commishinfo.select_list(otherid),
        # Friends
        lambda: frienduser.has_friends(otherid),
    ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 26
0
def profile_(request):
    form = request.web_input(userid="", name="")

    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    config = define.get_config(request.userid)
    rating = define.get_rating(request.userid)
    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid,
                                         images=True,
                                         viewer=request.userid)
    extras = {"canonical_url": "/~" + define.get_sysname(form.name)}

    if not request.userid:
        # Only generate the Twitter/OGP meta headers if not authenticated (the UA viewing is likely automated).
        twit_card = profile.twitter_card(otherid)
        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'],
            'image':
            twit_card['image:src'] if 'image:src' in twit_card else
            define.cdnify_url('/static/images/logo-mark-light.svg'),
        }

    if not request.userid and "h" in userprofile['config']:
        return Response(
            define.errorpage(
                request.userid,
                "You cannot view this page because the owner does not allow guests to view their profile.",
                **extras))

    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    extras['title'] = u"%s's profile" % (userprofile['full_name']
                                         if has_fullname else
                                         userprofile['username'], )

    page = define.common_page_start(request.userid, **extras)
    define.common_view_content(request.userid, otherid, "profile")

    if 'O' in userprofile['config']:
        submissions = collection.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             options=["cover"],
                                             config=config)
        more_submissions = 'collections'
        featured = None
    elif 'A' in userprofile['config']:
        submissions = character.select_list(request.userid,
                                            rating,
                                            11,
                                            otherid=otherid,
                                            options=["cover"],
                                            config=config)
        more_submissions = 'characters'
        featured = None
    else:
        submissions = submission.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             options=["cover"],
                                             config=config,
                                             profile_page_filter=True)
        more_submissions = 'submissions'
        featured = submission.select_featured(request.userid, otherid, rating)

    if userprofile['show_favorites_bar']:
        favorites = favorite.select_submit(request.userid,
                                           rating,
                                           11,
                                           otherid=otherid,
                                           config=config)
    else:
        favorites = None

    statistics, show_statistics = profile.select_statistics(otherid)

    page.append(
        define.render(
            'user/profile.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                macro.SOCIAL_SITES,
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Myself
                profile.select_myself(request.userid),
                # Recent submissions
                submissions,
                more_submissions,
                favorites,
                featured,
                # Folders preview
                folder.select_preview(request.userid, otherid, rating, 3),
                # Latest journal
                journal.select_latest(
                    request.userid, rating, otherid=otherid, config=config),
                # Recent shouts
                shout.select(request.userid, ownerid=otherid, limit=8),
                # Statistics information
                statistics,
                show_statistics,
                # Commission information
                commishinfo.select_list(otherid),
                # Friends
                lambda: frienduser.has_friends(otherid),
            ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 27
0
def profile_(request):
    name = request.params.get('name', '')
    name = request.matchdict.get('name', name)
    userid = define.get_int(request.params.get('userid'))

    rating = define.get_rating(request.userid)
    otherid = profile.resolve(request.userid, userid, name)

    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid, viewer=request.userid)
    is_unverified = otherid != request.userid and not define.is_vouched_for(
        otherid)

    if is_unverified and request.userid not in staff.MODS:
        can_vouch = request.userid != 0 and define.is_vouched_for(
            request.userid)

        return Response(
            define.webpage(
                request.userid,
                "error/unverified.html",
                [request, otherid, userprofile['username'], can_vouch],
            ),
            status=403,
        )

    extras = {
        "canonical_url": "/~" + define.get_sysname(userprofile['username'])
    }

    if not request.userid:
        # Only generate the Twitter/OGP meta headers if not authenticated (the UA viewing is likely automated).
        twit_card = profile.twitter_card(otherid)
        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'],
            'image':
            twit_card['image:src'] if 'image:src' in twit_card else
            define.get_resource_url('img/logo-mark-light.svg'),
        }

    if not request.userid and "h" in userprofile['config']:
        raise WeasylError('noGuests')

    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    extras['title'] = u"%s's profile" % (userprofile['full_name']
                                         if has_fullname else
                                         userprofile['username'], )

    page = define.common_page_start(request.userid, **extras)
    define.common_view_content(request.userid, otherid, "profile")

    if 'O' in userprofile['config']:
        submissions = collection.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid)
        more_submissions = 'collections'
        featured = None
    elif 'A' in userprofile['config']:
        submissions = character.select_list(request.userid,
                                            rating,
                                            11,
                                            otherid=otherid)
        more_submissions = 'characters'
        featured = None
    else:
        submissions = submission.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             profile_page_filter=True)
        more_submissions = 'submissions'
        featured = submission.select_featured(request.userid, otherid, rating)

    if userprofile['show_favorites_bar']:
        favorites = favorite.select_submit(request.userid,
                                           rating,
                                           11,
                                           otherid=otherid)
    else:
        favorites = None

    statistics, show_statistics = profile.select_statistics(otherid)

    page.append(
        define.render(
            'user/profile.html',
            [
                request,
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                macro.SOCIAL_SITES,
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Myself
                profile.select_myself(request.userid),
                # Recent submissions
                submissions,
                more_submissions,
                favorites,
                featured,
                # Folders preview
                folder.select_preview(request.userid, otherid, rating),
                # Latest journal
                journal.select_latest(request.userid, rating, otherid=otherid),
                # Recent shouts
                shout.select(request.userid, ownerid=otherid, limit=8),
                # Statistics information
                statistics,
                show_statistics,
                # Commission information
                commishinfo.select_list(otherid),
                # Friends
                lambda: frienduser.has_friends(otherid),
                is_unverified,
            ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 28
0
def profile_(request):
    form = request.web_input(userid="", name="")

    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    config = define.get_config(request.userid)
    rating = define.get_rating(request.userid)
    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid,
                                         images=True,
                                         viewer=request.userid)
    extras = {"canonical_url": "/~" + define.get_sysname(form.name)}

    if define.user_is_twitterbot():
        extras['twitter_card'] = profile.twitter_card(otherid)
        extras['options'] = ['nocache']

    if not request.userid and "h" in userprofile['config']:
        return Response(
            define.errorpage(
                request.userid,
                "You cannot view this page because the owner does not allow guests to view their profile.",
                **extras))

    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    extras['title'] = u"%s's profile" % (userprofile['full_name']
                                         if has_fullname else
                                         userprofile['username'], )

    page = define.common_page_start(request.userid, **extras)
    define.common_view_content(request.userid, otherid, "profile")

    if 'O' in userprofile['config']:
        submissions = collection.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             options=["cover"],
                                             config=config)
        more_submissions = 'collections'
        featured = None
    elif 'A' in userprofile['config']:
        submissions = character.select_list(request.userid,
                                            rating,
                                            11,
                                            otherid=otherid,
                                            options=["cover"],
                                            config=config)
        more_submissions = 'characters'
        featured = None
    else:
        submissions = submission.select_list(request.userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             options=["cover"],
                                             config=config,
                                             profile_page_filter=True)
        more_submissions = 'submissions'
        featured = submission.select_featured(request.userid, otherid, rating)

    if userprofile['show_favorites_bar']:
        favorites = favorite.select_submit(request.userid,
                                           rating,
                                           11,
                                           otherid=otherid,
                                           config=config)
    else:
        favorites = None

    page.append(
        define.render(
            'user/profile.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                macro.SOCIAL_SITES,
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Myself
                profile.select_myself(request.userid),
                # Recent submissions
                submissions,
                more_submissions,
                favorites,
                featured,
                # Folders preview
                folder.select_preview(request.userid, otherid, rating, 3),
                # Latest journal
                journal.select_latest(
                    request.userid, rating, otherid=otherid, config=config),
                # Recent shouts
                shout.select(request.userid, ownerid=otherid, limit=8),
                # Statistics information
                profile.select_statistics(otherid),
                # Commission information
                commishinfo.select_list(otherid),
                # Friends
                frienduser.select(request.userid, otherid, 5, choose=None),
                # Following
                followuser.select_following(request.userid, otherid, choose=5),
                # Followed
                followuser.select_followed(request.userid, otherid, choose=5),
            ]))

    return Response(define.common_page_end(request.userid, page))
Esempio n. 29
0
def api_user_view_(request):
    # Helper functions for this view.
    def convert_commission_price(value, options):
        return d.text_price_symbol(options) + d.text_price_amount(value)

    def convert_commission_setting(target):
        if target == "o":
            return "open"
        elif target == "s":
            return "sometimes"
        elif target == "f":
            return "filled"
        elif target == "c":
            return "closed"
        else:
            return None

    userid = request.userid
    otherid = profile.resolve_by_login(
        d.get_sysname(request.matchdict['login']))
    user = profile.select_profile(otherid)

    rating = d.get_rating(userid)
    o_config = user.pop('config')
    o_settings = user.pop('settings')

    if not otherid and "h" in o_config:
        raise HTTPForbidden(
            json={
                "error": {
                    "code": 200,
                    "text": "Profile hidden from unlogged users.",
                },
            })

    user.pop('userid', None)
    user.pop('commish_slots', None)

    user['created_at'] = d.iso8601(user.pop('unixtime'))
    user['media'] = api.tidy_all_media(user.pop('user_media'))
    user['login_name'] = d.get_sysname(user['username'])
    user['profile_text'] = markdown(user['profile_text'])

    user['folders'] = folder.select_list(otherid)

    commissions = {
        "details": None,
        "price_classes": None,
        "commissions": convert_commission_setting(o_settings[0]),
        "trades": convert_commission_setting(o_settings[1]),
        "requests": convert_commission_setting(o_settings[2])
    }

    commission_list = commishinfo.select_list(otherid)
    if commission_list:
        commissions['details'] = commission_list['content']

        if len(commission_list['class']) > 0:
            classes = list()
            for cclass in commission_list['class']:
                commission_class = {"title": cclass['title']}

                if len(commission_list['price']) > 0:
                    prices = list()
                    for cprice in (i for i in commission_list['price']
                                   if i['classid'] == cclass['classid']):
                        if 'a' in cprice['settings']:
                            ptype = 'additional'
                        else:
                            ptype = 'base'

                        price = {
                            "title":
                            cprice['title'],
                            "price_min":
                            convert_commission_price(cprice['amount_min'],
                                                     cprice['settings']),
                            "price_max":
                            convert_commission_price(cprice['amount_min'],
                                                     cprice['settings']),
                            'price_type':
                            ptype
                        }
                        prices.append(price)
                    commission_class['prices'] = prices

                classes.append(commission_class)
            commissions['price_classes'] = classes

    user['commission_info'] = commissions

    user['relationship'] = profile.select_relation(userid,
                                                   otherid) if userid else None

    if 'O' in o_config:
        submissions = collection.select_list(userid,
                                             rating,
                                             11,
                                             otherid=otherid)
        more_submissions = 'collections'
        featured = None
    elif 'A' in o_config:
        submissions = character.select_list(userid,
                                            rating,
                                            11,
                                            otherid=otherid)
        more_submissions = 'characters'
        featured = None
    else:
        submissions = submission.select_list(userid,
                                             rating,
                                             11,
                                             otherid=otherid,
                                             profile_page_filter=True)
        more_submissions = 'submissions'
        featured = submission.select_featured(userid, otherid, rating)

    if submissions:
        for sub in submissions:
            tidy_submission(sub)

    user['recent_submissions'] = submissions
    user['recent_type'] = more_submissions

    if featured:
        tidy_submission(featured)

    user['featured_submission'] = featured

    statistics, show_statistics = profile.select_statistics(otherid)
    if statistics:
        statistics.pop('staff_notes')
    user['statistics'] = statistics if show_statistics else None

    user_info = profile.select_userinfo(otherid)
    if user_info:
        if not user_info['show_age']:
            user_info['age'] = None
        user_info.pop('show_age', None)
        user_info.pop('birthday', None)
        user_info['location'] = user_info.pop('country', None)
    user['user_info'] = user_info
    user['link'] = d.absolutify_url("/~" + user['login_name'])

    return user
Esempio n. 30
0
    def GET(self, login):
        userid = self.user_id
        otherid = profile.resolve_by_login(login)
        user = profile.select_profile(otherid)

        rating = d.get_rating(userid)
        u_config = d.get_config(userid)
        o_config = user.pop('config')
        o_settings = user.pop('settings')

        if not otherid and "h" in o_config:
            return json.dumps({
                "error": {
                    "code": 200,
                    "text": "Profile hidden from unlogged users."
                }})

        user.pop('userid', None)
        user.pop('commish_slots', None)

        user['created_at'] = d.iso8601(user.pop('unixtime'))
        user['media'] = api.tidy_all_media(user.pop('user_media'))
        user['login_name'] = d.get_sysname(user['username'])
        user['profile_text'] = markdown(user['profile_text'])

        folders = folder.select_list(otherid, "api/all")
        if folders:
            old_folders = folders
            folders = list()
            for fldr in (i for i in old_folders if 'parentid' not in i):
                newfolder = {
                    "folder_id": fldr['folderid'],
                    "title": fldr['title']
                }

                if fldr['haschildren']:
                    subfolders = list()
                    for sub in (i for i in old_folders if 'parentid' in i and i['parentid'] == fldr['folderid']):
                        subfolders.append({
                            "folder_id": sub['folderid'],
                            "title": sub['title']
                        })

                    newfolder['subfolders'] = subfolders

                folders.append(newfolder)

        user['folders'] = folders

        commissions = {
            "details": None,
            "price_classes": None,
            "commissions": self.convert_commission_setting(o_settings[0]),
            "trades": self.convert_commission_setting(o_settings[1]),
            "requests": self.convert_commission_setting(o_settings[2])
        }

        commission_list = commishinfo.select_list(otherid)
        if commission_list:
            commissions['details'] = commission_list['content']

            if len(commission_list['class']) > 0:
                classes = list()
                for cclass in commission_list['class']:
                    commission_class = {
                        "title": cclass['title']
                    }

                    if len(commission_list['price']) > 0:
                        prices = list()
                        for cprice in (i for i in commission_list['price'] if i['classid'] == cclass['classid']):
                            if 'a' in cprice['settings']:
                                ptype = 'additional'
                            else:
                                ptype = 'base'

                            price = {
                                "title": cprice['title'],
                                "price_min": self.convert_commission_price(cprice['amount_min'], cprice['settings']),
                                "price_max": self.convert_commission_price(cprice['amount_min'], cprice['settings']),
                                'price_type': ptype
                            }
                            prices.append(price)
                        commission_class['prices'] = prices

                    classes.append(commission_class)
                commissions['price_classes'] = classes

        user['commission_info'] = commissions

        user['relationship'] = profile.select_relation(userid, otherid) if userid else None

        if 'O' in o_config:
            submissions = collection.select_list(
                userid, rating, 11, otherid=otherid, options=["cover"], config=u_config)
            more_submissions = 'collections'
            featured = None
        elif 'A' in o_config:
            submissions = character.select_list(
                userid, rating, 11, otherid=otherid, options=["cover"], config=u_config)
            more_submissions = 'characters'
            featured = None
        else:
            submissions = submission.select_list(
                userid, rating, 11, otherid=otherid, options=["cover"], config=u_config,
                profile_page_filter=True)
            more_submissions = 'submissions'
            featured = submission.select_featured(userid, otherid, rating)

        if submissions:
            submissions = map(tidy_submission, submissions)

        user['recent_submissions'] = submissions
        user['recent_type'] = more_submissions

        if featured:
            featured = tidy_submission(featured)

        user['featured_submission'] = featured

        statistics = profile.select_statistics(otherid)
        if statistics:
            statistics.pop('staff_notes')
        user['statistics'] = statistics

        user_info = profile.select_userinfo(otherid)
        if user_info:
            if not user_info['show_age']:
                user_info['age'] = None
            user_info.pop('show_age', None)
            user_info.pop('birthday', None)
            user_info['location'] = user_info.pop('country', None)
        user['user_info'] = user_info
        user['link'] = d.absolutify_url("/~" + user['login_name'])

        return json.dumps(user)
Esempio n. 31
0
    def GET(self, name=""):
        now = time.time()

        form = web.input(userid="", name="")
        form.name = name if name else form.name
        form.userid = define.get_int(form.userid)

        config = define.get_config(self.user_id)
        rating = define.get_rating(self.user_id)
        otherid = profile.resolve(self.user_id, form.userid, form.name)

        if not otherid:
            raise WeasylError("userRecordMissing")

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        extras = {
            "canonical_url": "/~" + define.get_sysname(form.name)
        }

        if define.user_is_twitterbot():
            extras['twitter_card'] = profile.twitter_card(otherid)
            extras['options'] = ['nocache']

        if not self.user_id and "h" in userprofile['config']:
            return define.errorpage(
                self.user_id,
                "You cannot view this page because the owner does not allow guests to view their profile.",
                **extras)

        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        extras['title'] = u"%s's profile" % (userprofile['full_name'] if has_fullname else userprofile['username'],)

        page = define.common_page_start(self.user_id, **extras)
        define.common_view_content(self.user_id, otherid, "profile")

        if 'O' in userprofile['config']:
            submissions = collection.select_list(
                self.user_id, rating, 11, otherid=otherid, options=["cover"], config=config)
            more_submissions = 'collections'
            featured = None
        elif 'A' in userprofile['config']:
            submissions = character.select_list(
                self.user_id, rating, 11, otherid=otherid, options=["cover"], config=config)
            more_submissions = 'characters'
            featured = None
        else:
            submissions = submission.select_list(
                self.user_id, rating, 11, otherid=otherid, options=["cover"], config=config,
                profile_page_filter=True)
            more_submissions = 'submissions'
            featured = submission.select_featured(self.user_id, otherid, rating)

        if userprofile['show_favorites_bar']:
            favorites = favorite.select_submit(self.user_id, rating, 11, otherid=otherid, config=config)
        else:
            favorites = None

        page.append(define.render(template.user_profile, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            macro.SOCIAL_SITES,
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Myself
            profile.select_myself(self.user_id),
            # Recent submissions
            submissions, more_submissions,
            favorites,
            featured,
            # Folders preview
            folder.select_preview(self.user_id, otherid, rating, 3),
            # Latest journal
            journal.select_latest(self.user_id, rating, otherid=otherid, config=config),
            # Recent shouts
            shout.select(self.user_id, ownerid=otherid, limit=8),
            # Statistics information
            profile.select_statistics(otherid),
            # Commission information
            commishinfo.select_list(otherid),
            # Friends
            frienduser.select(self.user_id, otherid, 5, choose=None),
            # Following
            followuser.select_following(self.user_id, otherid, choose=5),
            # Followed
            followuser.select_followed(self.user_id, otherid, choose=5),
        ]))

        return define.common_page_end(self.user_id, page, now=now)