def control_movefolder_(request): form = request.web_input(folderid="", parentid="") form.folderid = define.get_int(form.folderid) if form.folderid and define.get_int(form.parentid) >= 0: folder.move(request.userid, form) raise HTTPSeeOther(location="/manage/folders")
def POST(self): form = web.input(folderid="", parentid="") form.folderid = define.get_int(form.folderid) if form.folderid and define.get_int(form.parentid) >= 0: folder.move(self.user_id, form) raise web.seeother("/manage/folders")
def edit_submission_post_(request): form = request.web_input(submitid="", title="", folderid="", subtype="", rating="", content="", friends="", critique="", embedlink="") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.submitid = define.get_int(form.submitid) s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) submission.edit(request.userid, s, embedlink=form.embedlink, friends_only=form.friends, critique=form.critique) raise HTTPSeeOther( location="/submission/%i/%s%s" % (define.get_int(form.submitid), slug_for(form.title), "?anyway=true" if request.userid in staff.MODS else ''))
def submit_literary_post_(request): form = request.web_input(submitfile="", coverfile="boop", thumbfile="", title="", folderid="", subtype="", rating="", friends="", critique="", content="", tags="", embedlink="") tags = searchtag.parse_tags(form.tags) if not define.config_read_bool("allow_submit"): raise WeasylError("FeatureDisabled") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) submitid, thumb = submission.create_literary( request.userid, s, embedlink=form.embedlink, friends_only=form.friends, tags=tags, coverfile=form.coverfile, thumbfile=form.thumbfile, submitfile=form.submitfile, critique=form.critique, create_notifications=('nonotification' not in form)) if thumb: raise HTTPSeeOther(location="/manage/thumbnail?submitid=%i" % (submitid,)) else: raise HTTPSeeOther(location="/submission/%i/%s" % (submitid, slug_for(form.title)))
def POST(self): form = web.input(submitid="", title="", folderid="", subtype="", rating="", content="", friends="", critique="", embedlink="") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.submitid = define.get_int(form.submitid) s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) submission.edit(self.user_id, s, embedlink=form.embedlink, friends_only=form.friends, critique=form.critique) raise web.seeother( "/submission/%i/%s%s" % (define.get_int(form.submitid), slug_for(form.title), "?anyway=true" if self.user_id in staff.MODS else ''))
def create(userid, x1, y1, x2, y2, submitid=None, charid=None, config=None, remove=True): if charid: return _create_char(userid, x1, y1, x2, y2, charid, config, remove) db = d.connect() x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) source = thumbnail_source(submitid) im = db.query(orm.MediaItem).get(source['mediaid']).as_image() size = im.size.width, im.size.height bounds = None if image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = images.make_thumbnail(im, bounds) file_type = images.image_file_type(im) media_item = orm.fetch_or_create_media_item( thumb.to_buffer(format=file_type), file_type=file_type, im=thumb) orm.SubmissionMediaLink.make_or_replace_link(submitid, 'thumbnail-custom', media_item)
def GET(self): form = web.input(userid="", backid="", nextid="") form.userid = define.get_int(form.userid) form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) if form.userid: return define.webpage( self.user_id, "manage/following_user.html", [ # Profile profile.select_profile(form.userid, avatar=True), # Follow settings followuser.select_settings(self.user_id, form.userid), ]) else: return define.webpage( self.user_id, "manage/following_list.html", [ # Following followuser.manage_following(self.user_id, 44, backid=form.backid, nextid=form.nextid), ])
def _create_char(x1, y1, x2, y2, charid, remove=True): x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) filename = d.url_make(charid, "char/.thumb", root=True) if not m.os.path.exists(filename): filename = d.url_make(charid, "char/cover", root=True) if not filename: return remove = False im = image.read(filename) size = im.size.width, im.size.height d.engine.execute(""" UPDATE character SET settings = REGEXP_REPLACE(settings, '-.', '') || '-' || %(image_setting)s WHERE charid = %(char)s """, image_setting=image.image_setting(im), char=charid) dest = os.path.join(d.get_character_directory(charid), '%i.thumb%s' % (charid, images.image_extension(im))) bounds = None if image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = images.make_thumbnail(im, bounds) thumb.write(dest, format=images.image_file_type(thumb)) if remove: os.remove(filename)
def browse(userid, rating, limit, form, find=None): backid = d.get_int(form.backid) nextid = d.get_int(form.nextid) if find: form.find = find if form.find == "char": return character.select_list(userid, rating, limit, backid=backid, nextid=nextid) elif form.find == "journal": return journal.select_user_list(userid, rating, limit, backid=backid, nextid=nextid) else: return submission.select_list( userid, rating, limit, backid=backid, nextid=nextid, subcat=d.get_int(form.cat) if d.get_int(form.cat) in [1000, 2000, 3000] else None)
def followed_(request): name = request.matchdict.get('name', request.params.get('name', '')) userid = define.get_int(request.params.get('userid')) otherid = profile.resolve(request.userid, userid, name) backid = request.params.get('backid') nextid = request.params.get('nextid') if not otherid: raise WeasylError("userRecordMissing") elif not request.userid and "h" in define.get_config(otherid): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) return Response( define.webpage( request.userid, "user/followed.html", [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(request.userid, otherid), # Followed followuser.select_followed(request.userid, otherid, limit=44, backid=define.get_int(backid), nextid=define.get_int(nextid)), ]))
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True): x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) filename = d.url_make(charid, "char/.thumb", root=True) if not m.os.path.exists(filename): filename = d.url_make(charid, "char/cover", root=True) if not filename: return remove = False im = image.read(filename) size = im.size.width, im.size.height d.execute(""" UPDATE character SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s' WHERE charid = %i """, [image.image_setting(im), charid]) dest = os.path.join(d.get_character_directory(charid), '%i.thumb%s' % (charid, images.image_extension(im))) bounds = None if image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = images.make_thumbnail(im, bounds) thumb.write(dest, format=images.image_file_type(thumb)) if remove: os.remove(filename)
def manage_following_get_(request): form = request.web_input(userid="", backid="", nextid="") form.userid = define.get_int(form.userid) form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) if form.userid: return Response( define.webpage( request.userid, "manage/following_user.html", [ # Profile profile.select_profile(form.userid), # Follow settings followuser.select_settings(request.userid, form.userid), ], title="Followed User")) else: return Response( define.webpage( request.userid, "manage/following_list.html", [ # Following followuser.manage_following(request.userid, 44, backid=form.backid, nextid=form.nextid), ], title="Users You Follow"))
def followed_(request): cachename = "user/followed.html" form = request.web_input(userid="", name="", backid=None, nextid=None) form.name = request.matchdict.get('name', form.name) form.userid = define.get_int(form.userid) otherid = profile.resolve(request.userid, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not request.userid and "h" in define.get_config(otherid): return Response(define.errorpage(request.userid, errorcode.no_guest_access)) userprofile = profile.select_profile(otherid, images=True, viewer=request.userid) return Response(define.webpage(request.userid, cachename, [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(request.userid, otherid), # Followed followuser.select_followed(request.userid, otherid, limit=44, backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)), ]))
def GET(self, charid=""): form = web.input(charid="", ignore="", anyway="") rating = define.get_rating(self.user_id) charid = define.get_int(charid) if charid else define.get_int(form.charid) try: item = character.select_view( self.user_id, charid, rating, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: if we.value in ("UserIgnored", "TagBlocked"): we.errorpage_kwargs['links'] = [ ("View Character", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise canonical_url = "/character/%d/%s" % (charid, slug_for(item["title"])) page = define.common_page_start(self.user_id, canonical_url=canonical_url, title=item["title"]) page.append(define.render(template.detail_character, [ # Profile profile.select_myself(self.user_id), # Character detail item, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 2000 <= i[0] < 3000], ])) return define.common_page_end(self.user_id, page)
def POST(self): form = web.input(charid="", title="", age="", gender="", height="", weight="", species="", rating="", content="", friends="") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") c = orm.Character() c.charid = define.get_int(form.charid) c.age = form.age c.gender = form.gender c.height = form.height c.weight = form.weight c.species = form.species c.char_name = form.title c.content = form.content c.rating = rating character.edit(self.user_id, c, friends_only=form.friends) raise web.seeother( "/character/%i/%s%s" % (define.get_int(form.charid), slug_for(form.title), ("?anyway=true" if self.user_id in staff.MODS else '')))
def POST(self): form = web.input(submitfile="", thumbfile="", title="", folderid="", subtype="", rating="", friends="", critique="", content="", tags="", imageURL="") tags = searchtag.parse_tags(form.tags) if not define.config_read_bool("allow_submit"): raise WeasylError("FeatureDisabled") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) submitid = submission.create_visual( self.user_id, s, friends_only=form.friends, tags=tags, imageURL=form.imageURL, thumbfile=form.thumbfile, submitfile=form.submitfile, critique=form.critique, create_notifications=('nonotification' not in form)) if 'customthumb' in form: raise web.seeother("/manage/thumbnail?submitid=%i" % (submitid,)) else: raise web.seeother("/submission/%i/%s" % (submitid, slug_for(form.title)))
def POST(self): form = web.input(submitfile="", coverfile="", thumbfile="", embedlink="", title="", folderid="", subtype="", rating="", friends="", critique="", content="", tags="") tags = searchtag.parse_tags(form.tags) if not define.config_read_bool("allow_submit"): raise WeasylError("FeatureDisabled") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) autothumb = ('noautothumb' not in form) submitid, thumb = submission.create_multimedia( self.user_id, s, embedlink=form.embedlink, friends_only=form.friends, tags=tags, coverfile=form.coverfile, thumbfile=form.thumbfile, submitfile=form.submitfile, critique=form.critique, create_notifications=('nonotification' not in form), auto_thumb=autothumb) if thumb and not autothumb: raise web.seeother("/manage/thumbnail?submitid=%i" % (submitid,)) else: raise web.seeother("/submission/%i/%s" % (submitid, slug_for(form.title)))
def manage_thumbnail_get_(request): form = request.web_input(submitid="", charid="", auto="") submitid = define.get_int(form.submitid) charid = define.get_int(form.charid) if submitid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid(submitid=submitid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif charid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid(charid=charid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif not submitid and not charid: return Response(define.errorpage(request.userid)) if charid: source_path = define.url_make(charid, "char/.thumb", root=True) if os.path.exists(source_path): source = define.url_make(charid, "char/.thumb") else: source = define.url_make(charid, "char/cover") else: try: source = thumbnail.thumbnail_source(submitid)['display_url'] except WeasylError: source = None return Response(define.webpage(request.userid, "manage/thumbnail.html", [ # Feature "submit" if submitid else "char", # Targetid define.get_targetid(submitid, charid), # Thumbnail source, # Exists bool(source), ], options=['imageselect'], title="Select Thumbnail"))
def submit_visual_post_(request): form = request.web_input(submitfile="", thumbfile="", title="", folderid="", subtype="", rating="", friends="", critique="", content="", tags="", imageURL="") tags = searchtag.parse_tags(form.tags) if not define.config_read_bool("allow_submit"): raise WeasylError("FeatureDisabled") if not define.is_vouched_for(request.userid): raise WeasylError("vouchRequired") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") s = orm.Submission() s.title = form.title s.rating = rating s.content = form.content s.folderid = define.get_int(form.folderid) or None s.subtype = define.get_int(form.subtype) s.submitter_ip_address = request.client_addr s.submitter_user_agent_id = get_user_agent_id(ua_string=request.user_agent) submitid = submission.create_visual( request.userid, s, friends_only=form.friends, tags=tags, imageURL=form.imageURL, thumbfile=form.thumbfile, submitfile=form.submitfile, critique=form.critique, create_notifications=('nonotification' not in form)) if 'customthumb' in form: raise HTTPSeeOther(location="/manage/thumbnail?submitid=%i" % (submitid,)) else: raise HTTPSeeOther(location="/submission/%i/%s" % (submitid, slug_for(form.title)))
def edit_character_post_(request): form = request.web_input(charid="", title="", age="", gender="", height="", weight="", species="", rating="", content="", friends="") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") c = orm.Character() c.charid = define.get_int(form.charid) c.age = form.age c.gender = form.gender c.height = form.height c.weight = form.weight c.species = form.species c.char_name = form.title c.content = form.content c.rating = rating character.edit(request.userid, c, friends_only=form.friends) raise HTTPSeeOther(location="/character/%i/%s%s" % ( define.get_int(form.charid), slug_for(form.title), ("?anyway=true" if request.userid in staff.MODS else '') ))
def GET(self, name=""): cachename = "user/followed.html" form = web.input(userid="", name="", backid=None, nextid=None) form.name = name if name else form.name form.userid = define.get_int(form.userid) otherid = profile.resolve(self.user_id, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not self.user_id and "h" in define.get_config(otherid): return define.errorpage(self.user_id, errorcode.no_guest_access) userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id) return define.webpage( self.user_id, cachename, [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(self.user_id, otherid), # Followed followuser.select_followed(self.user_id, otherid, limit=44, backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)), ])
def edit_character_post_(request): form = request.web_input(charid="", title="", age="", gender="", height="", weight="", species="", rating="", content="", friends="") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") c = orm.Character() c.charid = define.get_int(form.charid) c.age = form.age c.gender = form.gender c.height = form.height c.weight = form.weight c.species = form.species c.char_name = form.title c.content = form.content c.rating = rating character.edit(request.userid, c, friends_only=form.friends) raise HTTPSeeOther( location="/character/%i/%s%s" % (define.get_int(form.charid), slug_for(form.title), ("?anyway=true" if request.userid in staff.MODS else '')))
def manage_friends_(request): form = request.web_input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) if form.feature == "pending": return Response( define.webpage(request.userid, "manage/friends_pending.html", [ frienduser.select_requests(request.userid, limit=20, backid=form.backid, nextid=form.nextid), ], title="Pending Friend Requests")) else: return Response( define.webpage( request.userid, "manage/friends_accepted.html", [ # Friends frienduser.select_accepted(request.userid, limit=20, backid=form.backid, nextid=form.nextid), ], title="Friends"))
def remove_price(userid, priceid): if not d.execute( "SELECT EXISTS (SELECT 0 FROM commishprice WHERE (priceid, userid) = (%i, %i))", [d.get_int(priceid), userid], ["bool"]): raise WeasylError("priceidInvalid") d.execute("DELETE FROM commishprice WHERE (priceid, userid) = (%i, %i)", [d.get_int(priceid), userid])
def submit_shout_(request): form = request.web_input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and request.userid not in staff.MODS: raise WeasylError("InsufficientPermissions") if not define.is_vouched_for(request.userid): raise WeasylError("vouchRequired") commentid = shout.insert( request.userid, target_user=define.get_int(form.userid or form.staffnotes), parentid=define.get_int(form.parentid), content=form.content, staffnotes=bool(form.staffnotes), ) if form.format == "json": return {"id": commentid} if form.staffnotes: raise HTTPSeeOther(location='/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise HTTPSeeOther(location="/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True): x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) filename = d.url_make(charid, "char/.thumb", root=True) if not m.os.path.exists(filename): filename = d.url_make(charid, "char/cover", root=True) if not filename: return remove = False im = image.read(filename) size = im.size.width, im.size.height d.execute( """ UPDATE character SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s' WHERE charid = %i """, [image.image_setting(im), charid]) dest = '%s%i.thumb%s' % (d.get_hash_path( charid, "char"), charid, images.image_extension(im)) bounds = None if image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = images.make_thumbnail(im, bounds) thumb.write(dest, format=images.image_file_type(thumb)) if remove: m.os.remove(filename)
def GET(self, journalid=""): form = web.input(journalid="", ignore="", anyway="") rating = define.get_rating(self.user_id) journalid = define.get_int(journalid) if journalid else define.get_int(form.journalid) try: item = journal.select_view( self.user_id, rating, journalid, ignore=define.text_bool(form.ignore, True), anyway=form.anyway ) except WeasylError as we: if we.value in ("UserIgnored", "TagBlocked"): we.errorpage_kwargs['links'] = [ ("View Journal", "?ignore=false"), ("Return to the Home Page", "/index"), ] raise canonical_url = "/journal/%d/%s" % (journalid, slug_for(item["title"])) page = define.common_page_start(self.user_id, options=["pager"], canonical_url=canonical_url, title=item["title"]) page.append(define.render('detail/journal.html', [ # Myself profile.select_myself(self.user_id), # Journal detail item, # Violations [i for i in macro.MACRO_REPORT_VIOLATION if 3000 <= i[0] < 4000], ])) return define.common_page_end(self.user_id, page)
def GET(self, name=""): cachename = "user/followed.html" form = web.input(userid="", name="", backid=None, nextid=None) form.name = name if name else form.name form.userid = define.get_int(form.userid) otherid = profile.resolve(self.user_id, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not self.user_id and "h" in define.get_config(otherid): return define.errorpage(self.user_id, errorcode.no_guest_access) userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id) return define.webpage(self.user_id, cachename, [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(self.user_id, otherid), # Followed followuser.select_followed(self.user_id, otherid, limit=44, backid=define.get_int(form.backid), nextid=define.get_int(form.nextid)), ])
def following_(request): form = request.web_input(userid="", name="", backid=None, nextid=None) form.name = request.matchdict.get('name', form.name) form.userid = define.get_int(form.userid) otherid = profile.resolve(request.userid, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not request.userid and "h" in define.get_config(otherid): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) return Response( define.webpage( request.userid, "user/following.html", [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(request.userid, otherid), # Following followuser.select_following(request.userid, otherid, limit=44, backid=define.get_int(form.backid), nextid=define.get_int( form.nextid)), ]))
def submit_shout_(request): form = request.web_input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and request.userid not in staff.MODS: raise WeasylError("InsufficientPermissions") c = orm.Comment() c.parentid = define.get_int(form.parentid) c.userid = define.get_int(form.userid or form.staffnotes) c.content = form.content commentid = shout.insert(request.userid, c, staffnotes=form.staffnotes) if form.format == "json": return {"id": commentid} if form.staffnotes: raise HTTPSeeOther(location='/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise HTTPSeeOther(location="/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def POST(self): form = web.input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and self.user_id not in staff.MODS: raise WeasylError("InsufficientPermissions") c = orm.Comment() c.parentid = define.get_int(form.parentid) c.userid = define.get_int(form.userid or form.staffnotes) c.content = form.content commentid = shout.insert(self.user_id, c, staffnotes=form.staffnotes) if form.format == "json": return {"id": commentid} if form.staffnotes: raise web.seeother('/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise web.seeother("/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def browse(userid, rating, limit, find, cat, backid, nextid): if find == "char": return character.select_list(userid, rating, limit, backid=backid, nextid=nextid) elif find == "journal": return journal.select_user_list(userid, rating, limit, backid=backid, nextid=nextid) else: return submission.select_list(userid, rating, limit, backid=backid, nextid=nextid, subcat=d.get_int(cat) if d.get_int(cat) in [1000, 2000, 3000] else None)
def manage_ignore_(request): form = request.web_input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) return Response(define.webpage(request.userid, "manage/ignore.html", [ ignoreuser.select(request.userid, 20, backid=form.backid, nextid=form.nextid), ]))
def GET(self): form = web.input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) return define.webpage(self.user_id, "manage/ignore.html", [ ignoreuser.select(self.user_id, 20, backid=form.backid, nextid=form.nextid), ])
def manage_ignore_(request): form = request.web_input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) return Response(define.webpage(request.userid, "manage/ignore.html", [ ignoreuser.select(request.userid, 20, backid=form.backid, nextid=form.nextid), ], title="Ignored Users"))
def collections_(request): form = request.web_input(userid="", name="", backid=None, nextid=None, folderid=None) form.name = request.matchdict.get('name', form.name) form.userid = define.get_int(form.userid) config = define.get_config(request.userid) rating = define.get_rating(request.userid) otherid = profile.resolve(request.userid, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not request.userid and "h" in define.get_config(otherid): return Response( define.errorpage(request.userid, errorcode.no_guest_access)) userprofile = profile.select_profile(otherid, images=True, viewer=request.userid) has_fullname = userprofile[ 'full_name'] is not None and userprofile['full_name'].strip() != '' page_title = u"%s's collections" % (userprofile['full_name'] if has_fullname else userprofile['username'], ) page = define.common_page_start(request.userid, title=page_title) url_format = "/collections?userid={userid}&%s".format( userid=userprofile['userid']) result = pagination.PaginatedResult(collection.select_list, collection.select_count, 'submitid', url_format, request.userid, rating, 66, otherid=otherid, backid=define.get_int(form.backid), nextid=define.get_int(form.nextid), config=config) page.append( define.render( 'user/collections.html', [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(request.userid, otherid), # Collections result, ])) return Response(define.common_page_end(request.userid, page))
def submissions_(request): name = request.matchdict.get('name', request.params.get('name', '')) userid = define.get_int(request.params.get('userid')) rating = define.get_rating(request.userid) otherid = profile.resolve(request.userid, userid, name) folderid = define.get_int(request.params.get('folderid')) or None backid = request.params.get('backid') nextid = request.params.get('nextid') if not otherid: raise WeasylError("userRecordMissing") elif not request.userid and "h" in define.get_config(otherid): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) has_fullname = userprofile[ 'full_name'] is not None and userprofile['full_name'].strip() != '' page_title = u"%s's submissions" % (userprofile['full_name'] if has_fullname else userprofile['username'], ) page = define.common_page_start(request.userid, title=page_title) url_format = "/submissions/{username}?%s{folderquery}".format( username=define.get_sysname(userprofile['username']), folderquery="&folderid=%d" % folderid if folderid else "") result = pagination.PaginatedResult(submission.select_list, submission.select_count, 'submitid', url_format, request.userid, rating, limit=60, otherid=otherid, folderid=folderid, backid=define.get_int(backid), nextid=define.get_int(nextid), profile_page_filter=not folderid) page.append( define.render( 'user/submissions.html', [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(request.userid, otherid), # Recent submissions result, # Folders folder.select_list(otherid), # Current folder folderid, ])) return Response(define.common_page_end(request.userid, page))
def submit_tags_(request): if not define.is_vouched_for(request.userid): raise WeasylError("vouchRequired") form = request.web_input(submitid="", charid="", journalid="", preferred_tags_userid="", optout_tags_userid="", tags="") tags = searchtag.parse_tags(form.tags) submitid = define.get_int(form.submitid) charid = define.get_int(form.charid) journalid = define.get_int(form.journalid) preferred_tags_userid = define.get_int(form.preferred_tags_userid) optout_tags_userid = define.get_int(form.optout_tags_userid) result = searchtag.associate(request.userid, tags, submitid, charid, journalid, preferred_tags_userid, optout_tags_userid) if result: failed_tag_message = "" if result["add_failure_restricted_tags"] is not None: failed_tag_message += "The following tags have been restricted from being added to this item by the content owner, or Weasyl staff: **" + result[ "add_failure_restricted_tags"] + "**. \n" if result["remove_failure_owner_set_tags"] is not None: failed_tag_message += "The following tags were not removed from this item as the tag was added by the owner: **" + result[ "remove_failure_owner_set_tags"] + "**.\n" failed_tag_message += "Any other changes to this item's tags were completed." if submitid: location = "/submission/%i" % (submitid, ) if not result: raise HTTPSeeOther(location=location) else: return Response( define.errorpage(request.userid, failed_tag_message, [["Return to Content", location]])) elif charid: location = "/character/%i" % (charid, ) if not result: raise HTTPSeeOther(location=location) else: return Response( define.errorpage(request.userid, failed_tag_message, [["Return to Content", location]])) elif journalid: location = "/journal/%i" % (journalid, ) if not result: raise HTTPSeeOther(location=location) else: return Response( define.errorpage(request.userid, failed_tag_message, [["Return to Content", location]])) else: raise HTTPSeeOther(location="/control/editcommissionsettings")
def GET(self): form = web.input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) return define.webpage(self.user_id, "manage/ignore.html", [ ignoreuser.select( self.user_id, 20, backid=form.backid, nextid=form.nextid), ])
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 POST(self): form = web.input(submitid="", charid="", journalid="", parentid="", content="", format="") commentid = comment.insert(self.user_id, charid=define.get_int(form.charid), parentid=define.get_int(form.parentid), submitid=define.get_int(form.submitid), journalid=define.get_int(form.journalid), content=form.content) if form.format == "json": return {"id": commentid} if define.get_int(form.submitid): raise web.seeother("/submission/%i#cid%i" % (define.get_int(form.submitid), commentid)) elif define.get_int(form.charid): raise web.seeother("/character/%i#cid%i" % (define.get_int(form.charid), commentid)) else: raise web.seeother("/journal/%i#cid%i" % (define.get_int(form.journalid), commentid))
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 messages_submissions_(request): form = request.web_input(feature="", backtime=None, nexttime=None) define._page_header_info.refresh(request.userid) return Response(define.webpage(request.userid, "message/submissions_thumbnails.html", [ # Feature form.feature, # Submissions message.select_submissions(request.userid, 66, include_tags=False, backtime=define.get_int(form.backtime), nexttime=define.get_int(form.nexttime)), ]))
def POST(self): form = web.input(submitid="", charid="", journalid="", reportid="", violation="", content="") report.create(self.user_id, form) if form.reportid: raise web.seeother("/modcontrol/report?reportid=%s" % (form.reportid,)) elif define.get_int(form.submitid): raise web.seeother("/submission/%i" % (define.get_int(form.submitid),)) elif define.get_int(form.charid): raise web.seeother("/character/%i" % (define.get_int(form.charid),)) else: raise web.seeother("/journal/%i" % (define.get_int(form.journalid),))
def submit_report_(request): form = request.web_input(submitid="", charid="", journalid="", reportid="", violation="", content="") report.create(request.userid, form) if form.reportid: raise HTTPSeeOther(location="/modcontrol/report?reportid=%s" % (form.reportid,)) elif define.get_int(form.submitid): raise HTTPSeeOther(location="/submission/%i" % (define.get_int(form.submitid),)) elif define.get_int(form.charid): raise HTTPSeeOther(location="/character/%i" % (define.get_int(form.charid),)) else: raise HTTPSeeOther(location="/journal/%i" % (define.get_int(form.journalid),))
def manage_friends_(request): form = request.web_input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) if form.feature == "pending": return Response(define.webpage(request.userid, "manage/friends_pending.html", [ frienduser.select_requests(request.userid, 20, backid=form.backid, nextid=form.nextid), ])) else: return Response(define.webpage(request.userid, "manage/friends_accepted.html", [ # Friends frienduser.select_accepted(request.userid, 20, backid=form.backid, nextid=form.nextid), ]))
def GET(self): form = web.input(feature="", backid="", nextid="") form.backid = define.get_int(form.backid) form.nextid = define.get_int(form.nextid) if form.feature == "pending": return define.webpage(self.user_id, "manage/friends_pending.html", [ frienduser.select_requests(self.user_id, 20, backid=form.backid, nextid=form.nextid), ]) else: return define.webpage(self.user_id, "manage/friends_accepted.html", [ # Friends frienduser.select_accepted(self.user_id, 20, backid=form.backid, nextid=form.nextid), ])
def create(userid, x1, y1, x2, y2, auto=False, config=None): x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) db = d.connect() im = db.query(orm.MediaItem).get(avatar_source(userid)['mediaid']).as_image() file_type = image.image_file_type(im) bounds = None size = im.size.width, im.size.height if not auto and image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = image.shrinkcrop(im, geometry.Size(100, 100), bounds) media_item = orm.fetch_or_create_media_item( thumb.to_buffer(format=file_type), file_type=file_type, im=thumb) orm.UserMediaLink.make_or_replace_link(userid, 'avatar', media_item) orm.UserMediaLink.clear_link(userid, 'avatar-source')
def create(userid, form): form.submitid = d.get_int(form.submitid) form.charid = d.get_int(form.charid) form.journalid = d.get_int(form.journalid) form.violation = d.get_int(form.violation) form.content = form.content.strip()[:_CONTENT] # get the violation type from allowed types try: vtype = next(x for x in m.MACRO_REPORT_VIOLATION if x[0] == form.violation) except StopIteration: raise WeasylError("Unexpected") if not form.submitid and not form.charid and not form.journalid: raise WeasylError("Unexpected") elif form.violation == 0: if userid not in staff.MODS: raise WeasylError("Unexpected") elif (form.submitid or form.charid) and not 2000 <= form.violation < 3000: raise WeasylError("Unexpected") elif form.journalid and not 3000 <= form.violation < 4000: raise WeasylError("Unexpected") elif vtype[3] and not form.content: raise WeasylError("ReportCommentRequired") query = d.execute( "SELECT userid, settings FROM %s WHERE %s = %i", ["submission", "submitid", form.submitid] if form.submitid else ["character", "charid", form.charid] if form.charid else ["journal", "journalid", form.journalid], options="single") if not query or (form.violation != 0 and 'h' in query[1]): raise WeasylError("TargetRecordMissing") now = arrow.get() target_dict = _dict_of_targetid(form.submitid, form.charid, form.journalid) report = Report.query.filter_by(is_closed=False, **target_dict).first() if report is None: if form.violation == 0: raise WeasylError("Unexpected") urgency = vtype[1] report = Report(urgency=urgency, opened_at=now, **target_dict) Report.dbsession.add(report) Report.dbsession.add(ReportComment( report=report, violation=form.violation, userid=userid, unixtime=now, content=form.content)) Report.dbsession.flush()
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())
def control_removefolder_(request): form = request.web_input(folderid="") form.folderid = define.get_int(form.folderid) if form.folderid: folder.remove(request.userid, form.folderid) raise HTTPSeeOther(location="/manage/folders")
def GET(self, name=""): form = web.input(userid="", name="", backid=None, nextid=None) form.name = name if name else form.name form.userid = define.get_int(form.userid) config = define.get_config(self.user_id) rating = define.get_rating(self.user_id) otherid = profile.resolve(self.user_id, form.userid, form.name) if not otherid: raise WeasylError("userRecordMissing") elif not self.user_id and "h" in define.get_config(otherid): return define.errorpage(self.user_id, errorcode.no_guest_access) userprofile = profile.select_profile(otherid, images=True, viewer=self.user_id) has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' page_title = u"%s's journals" % (userprofile['full_name'] if has_fullname else userprofile['username'],) page = define.common_page_start(self.user_id, title=page_title) page.append(define.render(template.user_journals, [ # Profile information userprofile, # User information profile.select_userinfo(otherid, config=userprofile['config']), # Relationship profile.select_relation(self.user_id, otherid), # Journals list # TODO(weykent): use select_user_list journal.select_list(self.user_id, rating, 250, otherid=otherid, config=config), # Latest journal journal.select_latest(self.user_id, rating, otherid=otherid), ])) return define.common_page_end(self.user_id, page)
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)
def finduser(userid, form): form.userid = d.get_int(form.userid) lo = d.meta.tables['login'] sh = d.meta.tables['comments'] q = d.sa.select([ lo.c.userid, lo.c.login_name, lo.c.email, (d.sa.select([d.sa.func.count()]) .select_from(sh) .where(sh.c.target_user == lo.c.userid) .where(sh.c.settings.op('~')('s'))).label('staff_notes'), ]) if form.userid: q = q.where(lo.c.userid == form.userid) elif form.username: q = q.where(lo.c.login_name.op('~')(form.username)) elif form.email: q = q.where(d.sa.or_( lo.c.email.op('~')(form.email), lo.c.email.op('ilike')('%%%s%%' % form.email), )) else: return [] q = q.limit(100).order_by(lo.c.login_name.asc()) db = d.connect() return db.execute(q)
def control_streaming_post_(request): form = request.web_input(target="", set_stream="", stream_length="", stream_url="", stream_text="") if form.target and request.userid not in staff.MODS: return Response(define.errorpage(request.userid, errorcode.permission)) if form.target: target = int(form.target) else: target = request.userid stream_length = define.clamp(define.get_int(form.stream_length), 0, 360) p = orm.Profile() p.stream_text = form.stream_text p.stream_url = define.text_fix_url(form.stream_url.strip()) set_stream = form.set_stream profile.edit_streaming_settings(request.userid, target, p, set_stream=set_stream, stream_length=stream_length) if form.target: target_username = define.get_sysname(define.get_display_name(target)) raise HTTPSeeOther(location="/modcontrol/manageuser?name=" + target_username) else: raise HTTPSeeOther(location="/control")
def submit_character_post_(request): form = request.web_input(submitfile="", thumbfile="", title="", age="", gender="", height="", weight="", species="", rating="", friends="", content="", tags="") tags = searchtag.parse_tags(form.tags) if not define.config_read_bool("allow_submit"): raise WeasylError("FeatureDisabled") rating = ratings.CODE_MAP.get(define.get_int(form.rating)) if not rating: raise WeasylError("ratingInvalid") c = orm.Character() c.age = form.age c.gender = form.gender c.height = form.height c.weight = form.weight c.species = form.species c.char_name = form.title c.content = form.content c.rating = rating charid = character.create(request.userid, c, form.friends, tags, form.thumbfile, form.submitfile) raise HTTPSeeOther(location="/manage/thumbnail?charid=%i" % (charid,))