def test_ratings_twittercard(self): # For tests, this isn't set. absolutify_url requires it, # so this test would fail if it wasn't set. web.ctx.realhome = 'https://lo.weasyl.com:8443' user = db_utils.create_user() sub1 = db_utils.create_submission(user, rating=ratings.GENERAL.code) sub2 = db_utils.create_submission(user, rating=ratings.MODERATE.code) sub3 = db_utils.create_submission(user, rating=ratings.MATURE.code) sub4 = db_utils.create_submission(user, rating=ratings.EXPLICIT.code) card1 = submission.twitter_card(sub1) card2 = submission.twitter_card(sub2) card3 = submission.twitter_card(sub3) card4 = submission.twitter_card(sub4) self.assertNotEqual( 'This image is rated 18+ and only viewable on weasyl.com', card1['description']) self.assertNotEqual( 'This image is rated 18+ and only viewable on weasyl.com', card2['description']) self.assertEqual( 'This image is rated 18+ and only viewable on weasyl.com', card3['description']) self.assertEqual( 'This image is rated 18+ and only viewable on weasyl.com', card4['description']) # Delete this so it cannot interfere with other things. del web.ctx.realhome
def test_ratings_twittercard(self): user = db_utils.create_user() sub1 = db_utils.create_submission(user, rating=ratings.GENERAL.code) sub2 = db_utils.create_submission(user, rating=ratings.MODERATE.code) sub3 = db_utils.create_submission(user, rating=ratings.MATURE.code) sub4 = db_utils.create_submission(user, rating=ratings.EXPLICIT.code) card1 = submission.twitter_card(sub1) card2 = submission.twitter_card(sub2) card3 = submission.twitter_card(sub3) card4 = submission.twitter_card(sub4) self.assertNotEqual( 'This image is rated 18+ and only viewable on weasyl.com', card1['description']) self.assertNotEqual( 'This image is rated 18+ and only viewable on weasyl.com', card2['description']) self.assertEqual( 'This image is rated 18+ and only viewable on weasyl.com', card3['description']) self.assertEqual( 'This image is rated 18+ and only viewable on weasyl.com', card4['description'])
def test_ratings_twittercard(self): user = db_utils.create_user() sub1 = db_utils.create_submission(user, rating=ratings.GENERAL.code) sub2 = db_utils.create_submission(user, rating=ratings.MATURE.code) sub3 = db_utils.create_submission(user, rating=ratings.EXPLICIT.code) card1 = submission.twitter_card(sub1) card2 = submission.twitter_card(sub2) card3 = submission.twitter_card(sub3) self.assertNotEqual('This image is rated 18+ and only viewable on weasyl.com', card1['description']) self.assertEqual('This image is rated 18+ and only viewable on weasyl.com', card2['description']) self.assertEqual('This image is rated 18+ and only viewable on weasyl.com', card3['description'])
def submission_(request): username = request.matchdict.get('name') submitid = request.matchdict.get('submitid') form = request.web_input(submitid="", ignore="", anyway="") rating = define.get_rating(request.userid) submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid) extras = { "pdf": True, } if define.user_is_twitterbot(): extras['twitter_card'] = submission.twitter_card(submitid) try: item = submission.select_view( request.userid, submitid, rating, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: we.errorpage_kwargs = extras if 'twitter_card' in extras: extras['options'] = ['nocache'] if we.value in ("UserIgnored", "TagBlocked"): extras['links'] = [ ("View Submission", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise login = define.get_sysname(item['username']) canonical_path = request.route_path('submission_detail_profile', name=login, submitid=submitid, slug=slug_for(item['title'])) if request.GET.get('anyway'): canonical_path += '?anyway=true' if login != username: raise httpexceptions.HTTPMovedPermanently(location=canonical_path) extras["canonical_url"] = canonical_path extras["title"] = item["title"] page = define.common_page_start(request.userid, **extras) page.append(define.render('detail/submission.html', [ # Myself profile.select_myself(request.userid), # Submission detail item, # Subtypes macro.MACRO_SUBCAT_LIST, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000], ])) return Response(define.common_page_end(request.userid, page))
def GET(self, a="", b=None): if b is None: username, submitid = None, a else: username, submitid = a, b now = time.time() form = web.input(submitid="", ignore="", anyway="") rating = define.get_rating(self.user_id) submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid) extras = { "pdf": True, } if define.user_is_twitterbot(): extras['twitter_card'] = submission.twitter_card(submitid) try: item = submission.select_view( self.user_id, submitid, rating, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: we.errorpage_kwargs = extras if 'twitter_card' in extras: extras['options'] = ['nocache'] if we.value in ("UserIgnored", "TagBlocked"): extras['links'] = [ ("View Submission", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise login = define.get_sysname(item['username']) if username is not None and login != username: raise web.seeother('/~%s/post/%s/%s' % (login, submitid, slug_for(item["title"]))) extras["canonical_url"] = "/submission/%d/%s" % (submitid, slug_for(item["title"])) extras["title"] = item["title"] page = define.common_page_start(self.user_id, options=["mediaplayer"], **extras) page.append(define.render('detail/submission.html', [ # Myself profile.select_myself(self.user_id), # Submission detail item, # Subtypes macro.MACRO_SUBCAT_LIST, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000], ])) return define.common_page_end(self.user_id, page, now=now)
def test_ratings_twittercard(self): # For tests, this isn't set. absolutify_url requires it, # so this test would fail if it wasn't set. web.ctx.realhome = 'https://lo.weasyl.com:8443' user = db_utils.create_user() sub1 = db_utils.create_submission(user, rating=ratings.GENERAL.code) sub2 = db_utils.create_submission(user, rating=ratings.MODERATE.code) sub3 = db_utils.create_submission(user, rating=ratings.MATURE.code) sub4 = db_utils.create_submission(user, rating=ratings.EXPLICIT.code) card1 = submission.twitter_card(sub1) card2 = submission.twitter_card(sub2) card3 = submission.twitter_card(sub3) card4 = submission.twitter_card(sub4) self.assertNotEqual('This image is rated 18+ and only viewable on weasyl.com', card1['description']) self.assertNotEqual('This image is rated 18+ and only viewable on weasyl.com', card2['description']) self.assertEqual('This image is rated 18+ and only viewable on weasyl.com', card3['description']) self.assertEqual('This image is rated 18+ and only viewable on weasyl.com', card4['description']) # Delete this so it cannot interfere with other things. del web.ctx.realhome
def submission_(request): username = request.matchdict.get('name') submitid = request.matchdict.get('submitid') form = request.web_input(submitid="", ignore="", anyway="") rating = define.get_rating(request.userid) submitid = define.get_int(submitid) if submitid else define.get_int(form.submitid) extras = {} if not request.userid: # Only generate the Twitter/OGP meta headers if not authenticated (the UA viewing is likely automated). twit_card = submission.twitter_card(submitid) 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'], # >> BUG AVOIDANCE: https://trello.com/c/mBx51jfZ/1285-any-image-link-with-in-it-wont-preview-up-it-wont-show-up-in-embeds-too # Image URLs with '~' in it will not be displayed by Discord, so replace ~ with the URL encoded char code %7E 'image': twit_card['image:src'].replace('~', '%7E') if 'image:src' in twit_card else define.cdnify_url( '/static/images/logo-mark-light.svg'), } try: item = submission.select_view( request.userid, submitid, rating, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: we.errorpage_kwargs = extras if we.value in ("UserIgnored", "TagBlocked"): extras['links'] = [ ("View Submission", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise login = define.get_sysname(item['username']) canonical_path = request.route_path('submission_detail_profile', name=login, submitid=submitid, slug=slug_for(item['title'])) if request.GET.get('anyway'): canonical_path += '?anyway=true' if login != username: raise httpexceptions.HTTPMovedPermanently(location=canonical_path) extras["canonical_url"] = canonical_path extras["title"] = item["title"] submission_files = item["sub_media"].get("submission") submission_file = submission_files[0] if submission_files else None extras["pdf"] = bool(submission_file) and submission_file["file_type"] == "pdf" page = define.common_page_start(request.userid, **extras) page.append(define.render('detail/submission.html', [ # Myself profile.select_myself(request.userid), # Submission detail item, # Subtypes macro.MACRO_SUBCAT_LIST, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000], ])) return Response(define.common_page_end(request.userid, page))
def GET(self, a="", b=None): if b is None: username, submitid = None, a else: username, submitid = a, b now = time.time() form = web.input(submitid="", ignore="", anyway="") rating = define.get_rating(self.user_id) submitid = define.get_int(submitid) if submitid else define.get_int( form.submitid) extras = { "pdf": True, } if define.user_is_twitterbot(): extras['twitter_card'] = submission.twitter_card(submitid) try: item = submission.select_view(self.user_id, submitid, rating, ignore=define.text_bool( form.ignore, True), anyway=form.anyway) except WeasylError as we: we.errorpage_kwargs = extras if 'twitter_card' in extras: extras['options'] = ['nocache'] if we.value in ("UserIgnored", "TagBlocked"): extras['links'] = [ ("View Submission", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise login = define.get_sysname(item['username']) if username is not None and login != username: raise web.seeother('/~%s/post/%s/%s' % (login, submitid, slug_for(item["title"]))) extras["canonical_url"] = "/submission/%d/%s" % ( submitid, slug_for(item["title"])) extras["title"] = item["title"] page = define.common_page_start(self.user_id, options=["mediaplayer"], **extras) page.append( define.render( template.detail_submission, [ # Myself profile.select_myself(self.user_id), # Submission detail item, # Subtypes macro.MACRO_SUBCAT_LIST, # Violations [ i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000 ], ])) return define.common_page_end(self.user_id, page, now=now)