Beispiel #1
0
    def test_insert_ignores(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 ignores user2
        db_utils.create_ignoreuser(user1, user2)
        # attempts to follow in either direction throw a WeasylError
        self.assertRaises(WeasylError, followuser.insert, user1, user2)
        self.assertRaises(WeasylError, followuser.insert, user2, user1)
        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        self.assertFalse(profile.select_relation(user2, user1)["follower"])
Beispiel #2
0
    def test_insert_ignores(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 ignores user2
        db_utils.create_ignoreuser(user1, user2)
        # attempts to follow in either direction throw a WeasylError
        self.assertRaises(WeasylError, followuser.insert, user1, user2)
        self.assertRaises(WeasylError, followuser.insert, user2, user1)
        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        self.assertFalse(profile.select_relation(user2, user1)["follower"])
Beispiel #3
0
    def test_mutual_follow(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)
        # user2 watches user1
        followuser.insert(user2, user1)
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertTrue(profile.select_relation(user2, user1)["follow"])
        self.assertTrue(profile.select_relation(user1, user2)["follower"])
Beispiel #4
0
    def test_mutual_follow(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)
        # user2 watches user1
        followuser.insert(user2, user1)
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertTrue(profile.select_relation(user2, user1)["follow"])
        self.assertTrue(profile.select_relation(user1, user2)["follower"])
Beispiel #5
0
    def test_insert_s_only(self, followuser_insert, followuser_remove, get_config):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        get_config.side_effect = lambda userid: "s"

        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())
        followuser_remove.assert_called_once_with(user1, user2)
        followuser_insert.assert_called_once_with(user1, user2)
        self.assertEqual("s", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #6
0
    def test_insert_s_only(self, followuser_insert, followuser_remove, get_config):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        get_config.side_effect = lambda userid: "s"

        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())
        followuser_remove.assert_called_once_with(user1, user2)
        followuser_insert.assert_called_once_with(user1, user2)
        self.assertEqual("s", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #7
0
    def GET(self, name=""):
        cachename = "user/followed.html"

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

        otherid = profile.resolve(self.user_id, form.userid, form.name)

        if not otherid:
            raise WeasylError("userRecordMissing")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid,
                                             images=True,
                                             viewer=self.user_id)

        return define.webpage(
            self.user_id,
            cachename,
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(self.user_id, otherid),
                # Followed
                followuser.select_followed(self.user_id,
                                           otherid,
                                           limit=44,
                                           backid=define.get_int(form.backid),
                                           nextid=define.get_int(form.nextid)),
            ])
Beispiel #8
0
def followed_(request):
    cachename = "user/followed.html"

    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)

    return Response(define.webpage(request.userid, cachename, [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Followed
        followuser.select_followed(request.userid, otherid, limit=44,
                                   backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)),
    ]))
Beispiel #9
0
def staffnotes_(request):
    form = request.web_input(userid="")
    otherid = profile.resolve(request.userid, define.get_int(form.userid), request.matchdict.get('name', None))
    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's staff notes" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    userinfo = profile.select_userinfo(otherid, config=userprofile['config'])
    reportstats = profile.select_report_stats(otherid)
    userinfo['reportstats'] = reportstats
    userinfo['reporttotal'] = sum(reportstats.values())

    page.append(define.render('user/shouts.html', [
        # Profile information
        userprofile,
        # User information
        userinfo,
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Myself
        profile.select_myself(request.userid),
        # Comments
        shout.select(request.userid, ownerid=otherid, staffnotes=True),
        # Feature
        "staffnotes",
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #10
0
def shouts_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's shouts" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    page.append(define.render('user/shouts.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Myself
        profile.select_myself(request.userid),
        # Comments
        shout.select(request.userid, ownerid=otherid),
        # Feature
        "shouts",
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #11
0
def journals_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None)
    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")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's journals" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    page.append(define.render('user/journals.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Journals list
        # TODO(weykent): use select_user_list
        journal.select_list(request.userid, rating, 250, otherid=otherid, config=config),
        # Latest journal
        journal.select_latest(request.userid, rating, otherid=otherid),
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #12
0
    def GET(self, name=""):
        cachename = "user/followed.html"

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

        otherid = profile.resolve(self.user_id, form.userid, form.name)

        if not otherid:
            raise WeasylError("userRecordMissing")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)

        return define.webpage(self.user_id, cachename, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Followed
            followuser.select_followed(self.user_id, otherid, limit=44,
                                       backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)),
        ])
Beispiel #13
0
    def test_remove(self, followuser_remove):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())

        followuser_remove.reset_mock()

        # user1 changed their mind
        followuser.remove(user1, user2)
        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        self.assertFalse(profile.select_relation(user2, user1)["follower"])
        self.assertEqual(0, d.sessionmaker().query(orm.Follow).count())
        followuser_remove.assert_called_once_with(user1, user2)
Beispiel #14
0
    def test_update(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)

        # user1 updates watch settings
        followuser.update(user1, user2, followuser.WatchSettings.from_code("cf"))
        self.assertEqual("cf", d.sessionmaker().query(orm.Follow).first().settings)

        # again
        followuser.update(user1, user2, followuser.WatchSettings.from_code("st"))
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertEqual("st", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #15
0
def following_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)

    return Response(
        define.webpage(
            request.userid,
            "user/following.html",
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Following
                followuser.select_following(request.userid,
                                            otherid,
                                            limit=44,
                                            backid=define.get_int(form.backid),
                                            nextid=define.get_int(
                                                form.nextid)),
            ]))
Beispiel #16
0
    def GET(self, name=""):
        now = time.time()

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

        otherid = profile.resolve(self.user_id, form.userid, form.name)

        if not otherid:
            raise WeasylError("userRecordMissing")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's shouts" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        page.append(define.render(template.user_shouts, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Myself
            profile.select_myself(self.user_id),
            # Comments
            shout.select(self.user_id, ownerid=otherid),
            # Feature
            "shouts",
        ]))

        return define.common_page_end(self.user_id, page, now=now)
Beispiel #17
0
    def GET(self, name=None):
        form = web.input(userid="")
        otherid = profile.resolve(self.user_id, define.get_int(form.userid), name)
        if not otherid:
            raise WeasylError("userRecordMissing")

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's staff notes" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        userinfo = profile.select_userinfo(otherid, config=userprofile['config'])
        reportstats = profile.select_report_stats(otherid)
        userinfo['reportstats'] = reportstats
        userinfo['reporttotal'] = sum(reportstats.values())

        page.append(define.render(template.user_shouts, [
            # Profile information
            userprofile,
            # User information
            userinfo,
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Myself
            profile.select_myself(self.user_id),
            # Comments
            shout.select(self.user_id, ownerid=otherid, staffnotes=True),
            # Feature
            "staffnotes",
        ]))

        return define.common_page_end(self.user_id, page, now=time.time())
Beispiel #18
0
    def GET(self, name=""):
        form = web.input(userid="", name="", backid=None, nextid=None)
        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")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's journals" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        page.append(define.render(template.user_journals, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Journals list
            # TODO(weykent): use select_user_list
            journal.select_list(self.user_id, rating, 250, otherid=otherid, config=config),
            # Latest journal
            journal.select_latest(self.user_id, rating, otherid=otherid),
        ]))

        return define.common_page_end(self.user_id, page)
Beispiel #19
0
def shouts_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's shouts" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    page.append(define.render('user/shouts.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Myself
        profile.select_myself(request.userid),
        # Comments
        shout.select(request.userid, ownerid=otherid),
        # Feature
        "shouts",
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #20
0
    def test_update(self):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)

        # user1 updates watch settings
        followuser.update(user1, user2, followuser.WatchSettings.from_code("cf"))
        self.assertEqual("cf", d.sessionmaker().query(orm.Follow).first().settings)

        # again
        followuser.update(user1, user2, followuser.WatchSettings.from_code("st"))
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertEqual("st", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #21
0
def followed_(request):
    cachename = "user/followed.html"

    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)

    return Response(define.webpage(request.userid, cachename, [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Followed
        followuser.select_followed(request.userid, otherid, limit=44,
                                   backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)),
    ]))
Beispiel #22
0
    def test_remove(self, followuser_remove):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()

        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())

        followuser_remove.reset_mock()

        # user1 changed their mind
        followuser.remove(user1, user2)
        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        self.assertFalse(profile.select_relation(user2, user1)["follower"])
        self.assertEqual(0, d.sessionmaker().query(orm.Follow).count())
        followuser_remove.assert_called_once_with(user1, user2)
Beispiel #23
0
def staffnotes_(request):
    form = request.web_input(userid="")
    otherid = profile.resolve(request.userid, define.get_int(form.userid), request.matchdict.get('name', None))
    if not otherid:
        raise WeasylError("userRecordMissing")

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's staff notes" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    userinfo = profile.select_userinfo(otherid, config=userprofile['config'])
    reportstats = profile.select_report_stats(otherid)
    userinfo['reportstats'] = reportstats
    userinfo['reporttotal'] = sum(reportstats.values())

    page.append(define.render('user/shouts.html', [
        # Profile information
        userprofile,
        # User information
        userinfo,
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Myself
        profile.select_myself(request.userid),
        # Comments
        shout.select(request.userid, ownerid=otherid, staffnotes=True),
        # Feature
        "staffnotes",
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #24
0
def journals_(request):
    name = request.matchdict.get('name', request.params.get('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")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's journals" % (userprofile['full_name'] if has_fullname
                                     else userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    page.append(
        define.render(
            'user/journals.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Journals list
                journal.select_list(request.userid, rating, otherid=otherid),
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #25
0
def followed_(request):
    name = request.matchdict.get('name', request.params.get('name', ''))
    userid = define.get_int(request.params.get('userid'))

    otherid = profile.resolve(request.userid, userid, name)

    backid = request.params.get('backid')
    nextid = request.params.get('nextid')

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)

    return Response(
        define.webpage(
            request.userid,
            "user/followed.html",
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Followed
                followuser.select_followed(request.userid,
                                           otherid,
                                           limit=44,
                                           backid=define.get_int(backid),
                                           nextid=define.get_int(nextid)),
            ]))
Beispiel #26
0
    def test_insert(self, followuser_insert, followuser_remove, get_config):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        get_config.side_effect = lambda userid: "scftj"

        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())
        # profile.select_relation should return u1 follows u2, u2 is follower of u1, u1 is not
        # follower of u2
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertFalse(profile.select_relation(user1, user2)["follower"])
        followuser_remove.assert_called_once_with(user1, user2)
        followuser_insert.assert_called_once_with(user1, user2)
        self.assertEqual("cfjst", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #27
0
    def test_insert(self, followuser_insert, followuser_remove, get_config):
        user1 = db_utils.create_user()
        user2 = db_utils.create_user()
        get_config.side_effect = lambda userid: "scftj"

        self.assertFalse(profile.select_relation(user1, user2)["follow"])
        # user1 watches user2
        followuser.insert(user1, user2)
        self.assertEqual(1, d.sessionmaker().query(orm.Follow).count())
        # profile.select_relation should return u1 follows u2, u2 is follower of u1, u1 is not
        # follower of u2
        self.assertTrue(profile.select_relation(user1, user2)["follow"])
        self.assertTrue(profile.select_relation(user2, user1)["follower"])
        self.assertFalse(profile.select_relation(user1, user2)["follower"])
        followuser_remove.assert_called_once_with(user1, user2)
        followuser_insert.assert_called_once_with(user1, user2)
        self.assertEqual("cfjst", d.sessionmaker().query(orm.Follow).first().settings)
Beispiel #28
0
def submissions_(request):
    name = request.matchdict.get('name', request.params.get('name', ''))
    userid = define.get_int(request.params.get('userid'))

    rating = define.get_rating(request.userid)
    otherid = profile.resolve(request.userid, userid, name)
    folderid = define.get_int(request.params.get('folderid')) or None
    backid = request.params.get('backid')
    nextid = request.params.get('nextid')

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's submissions" % (userprofile['full_name']
                                        if has_fullname else
                                        userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    url_format = "/submissions/{username}?%s{folderquery}".format(
        username=define.get_sysname(userprofile['username']),
        folderquery="&folderid=%d" % folderid if folderid else "")
    result = pagination.PaginatedResult(submission.select_list,
                                        submission.select_count,
                                        'submitid',
                                        url_format,
                                        request.userid,
                                        rating,
                                        limit=60,
                                        otherid=otherid,
                                        folderid=folderid,
                                        backid=define.get_int(backid),
                                        nextid=define.get_int(nextid),
                                        profile_page_filter=not folderid)

    page.append(
        define.render(
            'user/submissions.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Recent submissions
                result,
                # Folders
                folder.select_list(otherid),
                # Current folder
                folderid,
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #29
0
def collections_(request):
    form = request.web_input(userid="",
                             name="",
                             backid=None,
                             nextid=None,
                             folderid=None)
    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")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(
            define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid,
                                         images=True,
                                         viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's collections" % (userprofile['full_name']
                                        if has_fullname else
                                        userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    url_format = "/collections?userid={userid}&%s".format(
        userid=userprofile['userid'])
    result = pagination.PaginatedResult(collection.select_list,
                                        collection.select_count,
                                        'submitid',
                                        url_format,
                                        request.userid,
                                        rating,
                                        66,
                                        otherid=otherid,
                                        backid=define.get_int(form.backid),
                                        nextid=define.get_int(form.nextid),
                                        config=config)

    page.append(
        define.render(
            'user/collections.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Collections
                result,
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #30
0
    def GET(self, name=""):

        form = web.input(userid="", name="", backid=None, nextid=None)
        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")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid,
                                             images=True,
                                             viewer=self.user_id)
        has_fullname = userprofile[
            'full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's characters" % (userprofile['full_name']
                                           if has_fullname else
                                           userprofile['username'], )
        page = define.common_page_start(self.user_id, title=page_title)

        url_format = "/characters?userid={userid}&%s".format(
            userid=userprofile['userid'])
        result = pagination.PaginatedResult(character.select_list,
                                            character.select_count,
                                            'charid',
                                            url_format,
                                            self.user_id,
                                            rating,
                                            60,
                                            otherid=otherid,
                                            backid=define.get_int(form.backid),
                                            nextid=define.get_int(form.nextid),
                                            config=config)

        page.append(
            define.render(
                template.user_characters,
                [
                    # Profile information
                    userprofile,
                    # User information
                    profile.select_userinfo(otherid,
                                            config=userprofile['config']),
                    # Relationship
                    profile.select_relation(self.user_id, otherid),
                    # Characters list
                    result,
                ]))

        return define.common_page_end(self.user_id, page)
Beispiel #31
0
def shouts_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None)
    form.name = request.matchdict.get('name', form.name)
    form.userid = define.get_int(form.userid)

    otherid = profile.resolve(request.userid, form.userid, form.name)

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)

    if otherid != request.userid and not define.is_vouched_for(otherid):
        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,
        )

    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's shouts" % (userprofile['full_name'] if has_fullname
                                   else userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    page.append(
        define.render(
            'user/shouts.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Myself
                profile.select_myself(request.userid),
                # Comments
                shout.select(request.userid, ownerid=otherid),
                # Feature
                "shouts",
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #32
0
def collections_(request):
    name = request.matchdict.get('name', request.params.get('name', ''))
    userid = define.get_int(request.params.get('userid'))

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

    backid = request.params.get('backid')
    nextid = request.params.get('nextid')

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')

    userprofile = profile.select_profile(otherid, viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's collections" % (userprofile['full_name']
                                        if has_fullname else
                                        userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    url_format = "/collections?userid={userid}&%s".format(
        userid=userprofile['userid'])
    result = pagination.PaginatedResult(collection.select_list,
                                        collection.select_count,
                                        'submitid',
                                        url_format,
                                        request.userid,
                                        rating,
                                        limit=66,
                                        otherid=otherid,
                                        backid=define.get_int(backid),
                                        nextid=define.get_int(nextid))

    page.append(
        define.render(
            'user/collections.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Collections
                result,
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #33
0
def submissions_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None, folderid=None)
    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)
    folderid = define.get_int(form.folderid) or None

    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's submissions" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    url_format = "/submissions/{username}?%s{folderquery}".format(
                 username=define.get_sysname(userprofile['username']),
                 folderquery="&folderid=%d" % folderid if folderid else "")
    result = pagination.PaginatedResult(
        submission.select_list, submission.select_count, 'submitid', url_format, request.userid, rating,
        60, otherid=otherid, folderid=folderid, backid=define.get_int(form.backid),
        nextid=define.get_int(form.nextid), config=config, profile_page_filter=not folderid)

    page.append(define.render('user/submissions.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Recent submissions
        result,
        # Folders
        folder.select_list(otherid, "sidebar/all"),
        # Current folder
        folderid,
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #34
0
    def GET(self, name=""):
        form = web.input(userid="", name="", backid=None, nextid=None, folderid=None)
        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)
        folderid = define.get_int(form.folderid) or None

        if not otherid:
            raise WeasylError("userRecordMissing")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's submissions" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        url_format = "/submissions/{username}?%s{folderquery}".format(
                     username=define.get_sysname(userprofile['username']),
                     folderquery="&folderid=%d" % folderid if folderid else "")
        result = pagination.PaginatedResult(
            submission.select_list, submission.select_count, 'submitid', url_format, self.user_id, rating,
            60, otherid=otherid, folderid=folderid, backid=define.get_int(form.backid),
            nextid=define.get_int(form.nextid), config=config, profile_page_filter=not folderid)

        page.append(define.render(template.user_submissions, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Recent submissions
            result,
            # Folders
            folder.select_list(otherid, "sidebar/all"),
            # Current folder
            folderid,
        ]))

        return define.common_page_end(self.user_id, page)
Beispiel #35
0
    def GET(self, name=None):
        form = web.input(userid="")
        otherid = profile.resolve(self.user_id, define.get_int(form.userid),
                                  name)
        if not otherid:
            raise WeasylError("userRecordMissing")

        userprofile = profile.select_profile(otherid,
                                             images=True,
                                             viewer=self.user_id)
        has_fullname = userprofile[
            'full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's staff notes" % (userprofile['full_name']
                                            if has_fullname else
                                            userprofile['username'], )
        page = define.common_page_start(self.user_id, title=page_title)

        userinfo = profile.select_userinfo(otherid,
                                           config=userprofile['config'])
        reportstats = profile.select_report_stats(otherid)
        userinfo['reportstats'] = reportstats
        userinfo['reporttotal'] = sum(reportstats.values())

        page.append(
            define.render(
                template.user_shouts,
                [
                    # Profile information
                    userprofile,
                    # User information
                    userinfo,
                    # Relationship
                    profile.select_relation(self.user_id, otherid),
                    # Myself
                    profile.select_myself(self.user_id),
                    # Comments
                    shout.select(
                        self.user_id, ownerid=otherid, staffnotes=True),
                    # Feature
                    "staffnotes",
                ]))

        return define.common_page_end(self.user_id, page, now=time.time())
Beispiel #36
0
    def GET(self, name=""):
        now = time.time()

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

        otherid = profile.resolve(self.user_id, form.userid, form.name)

        if not otherid:
            raise WeasylError("userRecordMissing")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid,
                                             images=True,
                                             viewer=self.user_id)
        has_fullname = userprofile[
            'full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's shouts" % (userprofile['full_name'] if has_fullname
                                       else userprofile['username'], )
        page = define.common_page_start(self.user_id, title=page_title)

        page.append(
            define.render(
                template.user_shouts,
                [
                    # Profile information
                    userprofile,
                    # User information
                    profile.select_userinfo(otherid,
                                            config=userprofile['config']),
                    # Relationship
                    profile.select_relation(self.user_id, otherid),
                    # Myself
                    profile.select_myself(self.user_id),
                    # Comments
                    shout.select(self.user_id, ownerid=otherid),
                    # Feature
                    "shouts",
                ]))

        return define.common_page_end(self.user_id, page, now=now)
Beispiel #37
0
    def GET(self, name=""):

        form = web.input(userid="", name="", backid=None, nextid=None)
        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")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's characters" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        url_format = "/characters?userid={userid}&%s".format(userid=userprofile['userid'])
        result = pagination.PaginatedResult(
            character.select_list, character.select_count,
            'charid', url_format, self.user_id, rating, 60,
            otherid=otherid, backid=define.get_int(form.backid),
            nextid=define.get_int(form.nextid), config=config)

        page.append(define.render(template.user_characters, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Characters list
            result,
        ]))

        return define.common_page_end(self.user_id, page)
Beispiel #38
0
def collections_(request):
    form = request.web_input(userid="", name="", backid=None, nextid=None,
                             folderid=None)
    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")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's collections" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    url_format = "/collections?userid={userid}&%s".format(userid=userprofile['userid'])
    result = pagination.PaginatedResult(
        collection.select_list, collection.select_count, 'submitid', url_format, request.userid, rating, 66,
        otherid=otherid, backid=define.get_int(form.backid), nextid=define.get_int(form.nextid), config=config)

    page.append(define.render('user/collections.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Collections
        result,
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #39
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)
Beispiel #40
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)
Beispiel #41
0
def favorites_(request):
    def _FEATURE(target):
        if target == "submit":
            return 10
        elif target == "char":
            return 20
        elif target == "journal":
            return 30
        else:
            return 0

    form = request.web_input(userid="", name="", feature="", backid=None, nextid=None)
    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)

    # TODO(hyena): Why aren't more of these WeasylErrors?
    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(define.errorpage(request.userid, errorcode.no_guest_access))
    elif request.userid != otherid and 'v' in define.get_config(otherid):
        return Response(define.errorpage(
            request.userid,
            "You cannot view this page because the owner does not allow anyone to see their favorites."))

    userprofile = profile.select_profile(otherid, images=True, viewer=request.userid)
    has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's favorites" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
    page = define.common_page_start(request.userid, title=page_title)

    if form.feature:
        nextid = define.get_int(form.nextid)
        backid = define.get_int(form.backid)
        url_format = (
            "/favorites?userid={userid}&feature={feature}&%s".format(userid=userprofile['userid'], feature=form.feature))
        id_field = form.feature + "id"

        count_function = None
        if form.feature == "submit":
            select_function = favorite.select_submit
            count_function = favorite.select_submit_count
        elif form.feature == "char":
            select_function = favorite.select_char
        elif form.feature == "journal":
            select_function = favorite.select_journal
        else:
            raise httpexceptions.HTTPNotFound()

        faves = pagination.PaginatedResult(
            select_function, count_function,
            id_field, url_format, request.userid, rating, 60,
            otherid=otherid, backid=backid, nextid=nextid, config=config)
    else:
        faves = {
            "submit": favorite.select_submit(request.userid, rating, 22, otherid=otherid, config=config),
            "char": favorite.select_char(request.userid, rating, 22, otherid=otherid, config=config),
            "journal": favorite.select_journal(request.userid, rating, 22, otherid=otherid, config=config),
        }

    page.append(define.render('user/favorites.html', [
        # Profile information
        userprofile,
        # User information
        profile.select_userinfo(otherid, config=userprofile['config']),
        # Relationship
        profile.select_relation(request.userid, otherid),
        # Feature
        form.feature,
        # Favorites
        faves,
    ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #42
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))
Beispiel #43
0
    def GET(self, name=""):
        def _FEATURE(target):
            if target == "submit":
                return 10
            elif target == "char":
                return 20
            elif target == "journal":
                return 30
            else:
                return 0

        form = web.input(userid="", name="", feature="", backid=None, nextid=None)
        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")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)
        elif self.user_id != otherid and 'v' in define.get_config(otherid):
            return define.errorpage(
                self.user_id,
                "You cannot view this page because the owner does not allow anyone to see their favorites.")

        userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id)
        has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's favorites" % (userprofile['full_name'] if has_fullname else userprofile['username'],)
        page = define.common_page_start(self.user_id, title=page_title)

        if form.feature:
            nextid = define.get_int(form.nextid)
            backid = define.get_int(form.backid)
            url_format = (
                "/favorites?userid={userid}&feature={feature}&%s".format(userid=userprofile['userid'], feature=form.feature))
            id_field = form.feature + "id"

            count_function = None
            if form.feature == "submit":
                select_function = favorite.select_submit
                count_function = favorite.select_submit_count
            elif form.feature == "char":
                select_function = favorite.select_char
            elif form.feature == "journal":
                select_function = favorite.select_journal

            faves = pagination.PaginatedResult(
                select_function, count_function,
                id_field, url_format, self.user_id, rating, 60,
                otherid=otherid, backid=backid, nextid=nextid, config=config)
        else:
            faves = {
                "submit": favorite.select_submit(self.user_id, rating, 22, otherid=otherid, config=config),
                "char": favorite.select_char(self.user_id, rating, 22, otherid=otherid, config=config),
                "journal": favorite.select_journal(self.user_id, rating, 22, otherid=otherid, config=config),
            }

        page.append(define.render(template.user_favorites, [
            # Profile information
            userprofile,
            # User information
            profile.select_userinfo(otherid, config=userprofile['config']),
            # Relationship
            profile.select_relation(self.user_id, otherid),
            # Feature
            form.feature,
            # Favorites
            faves,
        ]))

        return define.common_page_end(self.user_id, page)
Beispiel #44
0
def favorites_(request):
    name = request.matchdict.get('name', request.params.get('name', ''))
    userid = define.get_int(request.params.get('userid'))

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

    backid = request.params.get('backid')
    nextid = request.params.get('nextid')

    feature = request.params.get('feature', False)

    # TODO(hyena): Why aren't more of these WeasylErrors?
    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        raise WeasylError('noGuests')
    elif request.userid != otherid and 'v' in define.get_config(otherid):
        raise WeasylError('hiddenFavorites')

    userprofile = profile.select_profile(otherid, viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's favorites" % (userprofile['full_name'] if has_fullname
                                      else userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    if feature:
        nextid = define.get_int(nextid)
        backid = define.get_int(backid)
        url_format = ("/favorites?userid={userid}&feature={feature}&%s".format(
            userid=otherid, feature=feature))
        id_field = feature + "id"

        count_function = None
        if feature == "submit":
            select_function = favorite.select_submit
            count_function = favorite.select_submit_count
        elif feature == "char":
            select_function = favorite.select_char
        elif feature == "journal":
            select_function = favorite.select_journal
        else:
            raise httpexceptions.HTTPNotFound()

        faves = pagination.PaginatedResult(select_function,
                                           count_function,
                                           id_field,
                                           url_format,
                                           request.userid,
                                           rating,
                                           limit=60,
                                           otherid=otherid,
                                           backid=backid,
                                           nextid=nextid)
    else:
        faves = {
            "submit":
            favorite.select_submit(request.userid, rating, 22,
                                   otherid=otherid),
            "char":
            favorite.select_char(request.userid, rating, 22, otherid=otherid),
            "journal":
            favorite.select_journal(request.userid,
                                    rating,
                                    22,
                                    otherid=otherid),
        }

    page.append(
        define.render(
            'user/favorites.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Feature
                feature,
                # Favorites
                faves,
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #45
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
Beispiel #46
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))
Beispiel #47
0
def favorites_(request):
    def _FEATURE(target):
        if target == "submit":
            return 10
        elif target == "char":
            return 20
        elif target == "journal":
            return 30
        else:
            return 0

    form = request.web_input(userid="",
                             name="",
                             feature="",
                             backid=None,
                             nextid=None)
    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)

    # TODO(hyena): Why aren't more of these WeasylErrors?
    if not otherid:
        raise WeasylError("userRecordMissing")
    elif not request.userid and "h" in define.get_config(otherid):
        return Response(
            define.errorpage(request.userid, errorcode.no_guest_access))
    elif request.userid != otherid and 'v' in define.get_config(otherid):
        return Response(
            define.errorpage(
                request.userid,
                "You cannot view this page because the owner does not allow anyone to see their favorites."
            ))

    userprofile = profile.select_profile(otherid,
                                         images=True,
                                         viewer=request.userid)
    has_fullname = userprofile[
        'full_name'] is not None and userprofile['full_name'].strip() != ''
    page_title = u"%s's favorites" % (userprofile['full_name'] if has_fullname
                                      else userprofile['username'], )
    page = define.common_page_start(request.userid, title=page_title)

    if form.feature:
        nextid = define.get_int(form.nextid)
        backid = define.get_int(form.backid)
        url_format = ("/favorites?userid={userid}&feature={feature}&%s".format(
            userid=userprofile['userid'], feature=form.feature))
        id_field = form.feature + "id"

        count_function = None
        if form.feature == "submit":
            select_function = favorite.select_submit
            count_function = favorite.select_submit_count
        elif form.feature == "char":
            select_function = favorite.select_char
        elif form.feature == "journal":
            select_function = favorite.select_journal
        else:
            raise httpexceptions.HTTPNotFound()

        faves = pagination.PaginatedResult(select_function,
                                           count_function,
                                           id_field,
                                           url_format,
                                           request.userid,
                                           rating,
                                           60,
                                           otherid=otherid,
                                           backid=backid,
                                           nextid=nextid,
                                           config=config)
    else:
        faves = {
            "submit":
            favorite.select_submit(request.userid,
                                   rating,
                                   22,
                                   otherid=otherid,
                                   config=config),
            "char":
            favorite.select_char(request.userid,
                                 rating,
                                 22,
                                 otherid=otherid,
                                 config=config),
            "journal":
            favorite.select_journal(request.userid,
                                    rating,
                                    22,
                                    otherid=otherid,
                                    config=config),
        }

    page.append(
        define.render(
            'user/favorites.html',
            [
                # Profile information
                userprofile,
                # User information
                profile.select_userinfo(otherid, config=userprofile['config']),
                # Relationship
                profile.select_relation(request.userid, otherid),
                # Feature
                form.feature,
                # Favorites
                faves,
            ]))

    return Response(define.common_page_end(request.userid, page))
Beispiel #48
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))
Beispiel #49
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))
Beispiel #50
0
    def GET(self, name=""):
        def _FEATURE(target):
            if target == "submit":
                return 10
            elif target == "char":
                return 20
            elif target == "journal":
                return 30
            else:
                return 0

        form = web.input(userid="",
                         name="",
                         feature="",
                         backid=None,
                         nextid=None)
        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")
        elif not self.user_id and "h" in define.get_config(otherid):
            return define.errorpage(self.user_id, errorcode.no_guest_access)
        elif self.user_id != otherid and 'v' in define.get_config(otherid):
            return define.errorpage(
                self.user_id,
                "You cannot view this page because the owner does not allow anyone to see their favorites."
            )

        userprofile = profile.select_profile(otherid,
                                             images=True,
                                             viewer=self.user_id)
        has_fullname = userprofile[
            'full_name'] is not None and userprofile['full_name'].strip() != ''
        page_title = u"%s's favorites" % (userprofile['full_name']
                                          if has_fullname else
                                          userprofile['username'], )
        page = define.common_page_start(self.user_id, title=page_title)

        if form.feature:
            nextid = define.get_int(form.nextid)
            backid = define.get_int(form.backid)
            url_format = (
                "/favorites?userid={userid}&feature={feature}&%s".format(
                    userid=userprofile['userid'], feature=form.feature))
            id_field = form.feature + "id"

            count_function = None
            if form.feature == "submit":
                select_function = favorite.select_submit
                count_function = favorite.select_submit_count
            elif form.feature == "char":
                select_function = favorite.select_char
            elif form.feature == "journal":
                select_function = favorite.select_journal

            faves = pagination.PaginatedResult(select_function,
                                               count_function,
                                               id_field,
                                               url_format,
                                               self.user_id,
                                               rating,
                                               60,
                                               otherid=otherid,
                                               backid=backid,
                                               nextid=nextid,
                                               config=config)
        else:
            faves = {
                "submit":
                favorite.select_submit(self.user_id,
                                       rating,
                                       22,
                                       otherid=otherid,
                                       config=config),
                "char":
                favorite.select_char(self.user_id,
                                     rating,
                                     22,
                                     otherid=otherid,
                                     config=config),
                "journal":
                favorite.select_journal(self.user_id,
                                        rating,
                                        22,
                                        otherid=otherid,
                                        config=config),
            }

        page.append(
            define.render(
                template.user_favorites,
                [
                    # Profile information
                    userprofile,
                    # User information
                    profile.select_userinfo(otherid,
                                            config=userprofile['config']),
                    # Relationship
                    profile.select_relation(self.user_id, otherid),
                    # Feature
                    form.feature,
                    # Favorites
                    faves,
                ]))

        return define.common_page_end(self.user_id, page)