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))
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))
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
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)
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)
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))
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))