Пример #1
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))
Пример #2
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))
Пример #3
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))
Пример #4
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)
Пример #5
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))
Пример #6
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)
Пример #7
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))
Пример #8
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)
Пример #9
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))
Пример #10
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))