Exemplo n.º 1
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())
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
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))
Exemplo n.º 5
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))
Exemplo n.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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())
Exemplo n.º 9
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)
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
0
    def test_add_and_remove_shout(self):
        # commenter1 posts a shout on owner's page
        c1 = shout.insert(self.commenter1,
                          target_user=self.owner,
                          parentid=None,
                          content="hello",
                          staffnotes=False)
        self.assertEqual(1, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 1)
        self.assertTrue(
            shouts[0].viewitems() >= {"content": "hello"}.viewitems())

        # commenter2 posts a reply to c1
        c2 = shout.insert(self.commenter2,
                          target_user=self.owner,
                          parentid=c1,
                          content="reply",
                          staffnotes=False)
        self.assertEqual(1, self.count_notifications(self.commenter1))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 2)
        self.assertTrue(
            shouts[1].viewitems() >= {"content": "reply"}.viewitems())

        # owner posts a reply to c2
        c3 = shout.insert(self.owner,
                          target_user=self.owner,
                          parentid=c2,
                          content="reply 2",
                          staffnotes=False)
        self.assertEqual(1, self.count_notifications(self.commenter2))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 3)
        self.assertTrue(
            shouts[2].viewitems() >= {"content": "reply 2"}.viewitems())

        # commenter1 responds to owner
        shout.insert(self.commenter1,
                     target_user=self.owner,
                     parentid=c3,
                     content="reply 3",
                     staffnotes=False)
        self.assertEqual(2, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 4)
        self.assertTrue(
            shouts[3].viewitems() >= {"content": "reply 3"}.viewitems())

        # commenter1 posts a new root shout
        shout.insert(self.commenter1,
                     target_user=self.owner,
                     parentid=None,
                     content="root 2",
                     staffnotes=False)
        self.assertEqual(3, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 5)
        self.assertTrue(
            shouts[0].viewitems() >= {"content": "root 2"}.viewitems())
        self.assertTrue(
            shouts[4].viewitems() >= {"content": "reply 3"}.viewitems())

        # commenter2 posts another reply to c1
        shout.insert(self.commenter2,
                     target_user=self.owner,
                     parentid=c1,
                     content="reply 4",
                     staffnotes=False)
        self.assertEqual(2, self.count_notifications(self.commenter1))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 6)
        self.assertTrue(
            shouts[5].viewitems() >= {"content": "reply 4"}.viewitems())

        # owner deletes comment thread
        shout.remove(self.owner, commentid=c1)
        self.assertEqual(1, self.count_notifications(self.owner))
        self.assertEqual(0, self.count_notifications(self.commenter1))
        self.assertEqual(0, self.count_notifications(self.commenter2))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 1)
        self.assertTrue(
            shouts[0].viewitems() >= {"content": "root 2"}.viewitems())
Exemplo n.º 13
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)
Exemplo n.º 14
0
    def test_add_and_remove_shout(self):
        # commenter1 posts a shout on owner's page
        c1 = shout.insert(self.commenter1, orm.Comment(userid=self.owner,
                                                       content="hello"))
        self.assertEqual(1, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 1)
        self.assertTrue(shouts[0].viewitems() >= {"content": "hello"}.viewitems())

        # commenter2 posts a reply to c1
        c2 = shout.insert(self.commenter2, orm.Comment(userid=self.owner,
                                                       content="reply", parentid=c1))
        self.assertEqual(1, self.count_notifications(self.commenter1))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 2)
        self.assertTrue(shouts[1].viewitems() >= {"content": "reply"}.viewitems())

        # owner posts a reply to c2
        c3 = shout.insert(self.owner, orm.Comment(userid=self.owner,
                                                  content="reply 2", parentid=c2))
        self.assertEqual(1, self.count_notifications(self.commenter2))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 3)
        self.assertTrue(shouts[2].viewitems() >= {"content": "reply 2"}.viewitems())

        # commenter1 responds to owner
        shout.insert(self.commenter1, orm.Comment(userid=self.owner,
                                                  content="reply 3", parentid=c3))
        self.assertEqual(2, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 4)
        self.assertTrue(shouts[3].viewitems() >= {"content": "reply 3"}.viewitems())

        # commenter1 posts a new root shout
        shout.insert(self.commenter1, orm.Comment(userid=self.owner,
                                                  content="root 2"))
        self.assertEqual(3, self.count_notifications(self.owner))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 5)
        self.assertTrue(shouts[0].viewitems() >= {"content": "root 2"}.viewitems())
        self.assertTrue(shouts[4].viewitems() >= {"content": "reply 3"}.viewitems())

        # commenter2 posts another reply to c1
        shout.insert(self.commenter2, orm.Comment(userid=self.owner,
                                                  content="reply 4", parentid=c1))
        self.assertEqual(2, self.count_notifications(self.commenter1))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 6)
        self.assertTrue(shouts[5].viewitems() >= {"content": "reply 4"}.viewitems())

        # owner deletes comment thread
        shout.remove(self.owner, commentid=c1)
        self.assertEqual(1, self.count_notifications(self.owner))
        self.assertEqual(0, self.count_notifications(self.commenter1))
        self.assertEqual(0, self.count_notifications(self.commenter2))

        shouts = shout.select(0, self.owner)
        self.assertEqual(len(shouts), 1)
        self.assertTrue(shouts[0].viewitems() >= {"content": "root 2"}.viewitems())
Exemplo n.º 15
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))
Exemplo n.º 16
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))