def _q_lookup(self, request, component): request = quixote.get_request() response = quixote.get_response() if component not in self.get_fields: raise TraversalError('No meta key "%s"' % component) http.json_response() if request.get_method() in ('POST', 'PUT'): if '_json' in request.form: data = json.read(request.form['_json']) # Return a callable thing def set_a_meta(request): ret = self.set_meta(component, data) ref = request.get_environ('HTTP_REFERER') if ref is not None: p = self.image.pic() response.redirect(ref + '#pic%d' % p.id) http.json_response() return json.write(ret) return set_a_meta respose.set_status(204) # no content return '' p = self.image.pic() return json.write(self.get_fields[component](p))
def handle_upload(self): request = quixote.get_request() response = quixote.get_response() user = auth.login_user() perm = self.db.permissions(user) mayupload = (user and user.mayUpload) or (perm and perm.mayUpload) if not mayupload: raise AccessError('You may not upload images') if 'image' not in request.form: response.set_status(204) # no content return '' added = [] skipped = {} if isinstance(request.form['image'], list): for img in request.form['image']: self.do_upload(img, user, added, skipped) else: img = request.form['image'] self.do_upload(img, user, added, skipped) added = [ image.Image(self, id) for id in added ] added = [ (p.path(), p.meta.get_meta()) for p in added ] http.json_response() response.set_status(201) # created return json.write({ 'added': added, 'skipped': skipped })
def _q_index(self, request): request = quixote.get_request() response = quixote.get_response() if request.get_method() in ('POST', 'PUT'): if '_json' in request.form: ret = {} try: changes = json.read(request.form['_json']) for n,v in changes.items(): ret[n] = self.set_meta(n, v) ref = request.get_environ('HTTP_REFERER') if ref is not None: p = self.image.pic() response.redirect(ref + '#pic%d' % p.id) http.json_response() return json.write(ret) except json.ReadException: raise QueryError('badly formatted JSON') response.set_status(204) # no content return '' meta = self.get_meta() http.json_response() return json.write(meta)
def _q_index(self, request): ret = {} for k in self.__properties__: ret[k] = self._get_pref(k) self._set_cookies() http.json_response() return json.write(ret)
def set_a_meta(request): ret = self.set_meta(component, data) ref = request.get_environ('HTTP_REFERER') if ref is not None: p = self.image.pic() response.redirect(ref + '#pic%d' % p.id) http.json_response() return json.write(ret)
def _q_index(self, request): request = quixote.get_request() response = quixote.get_response() if request.get_method() not in ('GET', 'HEAD'): raise http.MethodError(('GET', 'HEAD')) exif = self.get_exif() if exif is None: raise TraversalError('Image has no EXIF data') http.json_response() return json.write(exif.keys())
def user(request): """ Return the currently authenticated user, if any. """ quiet = True if request.form.get('force'): quiet = False u = login_user(quiet=quiet) ret = None if u is not None: ret = { 'id': u.id, 'username': u.username, 'fullname': u.fullname } http.json_response() return json.write(ret)
def prop(request): request = quixote.get_request() response = quixote.get_response() self._set_cookie(component) if 'set' in request.form: setattr(self, _propname(component), json.read(request.form['set'])) back = request.get_environ('HTTP_REFERER') if back is not None: response.set_status(204) # no content return quixote.redirect(back) else: return 'pref set'; else: http.json_response() return json.write(getattr(self, _propname(component)))
def _q_lookup(self, request, component): response = quixote.get_response() exif = self.get_exif() if exif is None: raise TraversalError('Image has no EXIF data') if component not in exif: raise TraversalError('No such EXIF tag') if component == 'JPEGThumbnail': response.set_content_type('image/jpeg') return exif[component] elif component == 'TIFFThumbnail': response.set_content_type('image/tiff') return exif[component] http.json_response() return json.write(exif[component])
def challenge(request): """ Generate a HTTP Digest authentication challenge, along with an expiry time. """ request = quixote.get_request() response = quixote.get_response() if request.get_method() != 'GET': raise http.MethodError(['GET']) http.json_response() scheme = _schemes_allowed[0] (expire,dict) = _auth_challenge(scheme, _realm) auth = '%s %s' % (scheme.capitalize(), ', '.join([ '%s="%s"' % (k, v.encode('string-escape')) for k,v in dict.items() ])) # XXX use expire header instead/as well? return json.write({ 'expire': expire, 'challenge': auth })
def _q_index(self, request): request = quixote.get_request() method = request.get_method() user = auth.login_user() if method == 'POST': if request.form.get('file') is None: raise QueryError('Missing file') dbu = db.Upload(user=user, collection=self.collection.db) pending = PendingUpload(self, dbu) if isinstance(request.form['file'], list): files = request.form['file'] else: files = [ request.form['file'] ] response = quixote.get_response() response.buffered = False return pending.do_upload(files, request.form['visibility']) elif method == 'GET': uploads = self.uploads(user) if http.want_json(): ret = [ (u.import_time.year, u.import_time.month, u.import_time.day, u.import_time.hour, u.import_time.minute, u.import_time.second) for u in uploads if len(u.pictures) > 0 ] http.json_response() return json.write(ret) else: return self.ui.uploadform(uploads) else: raise http.MethodError(['GET', 'POST'])
def rotate(self, request): request = quixote.get_request() response = quixote.get_response() if request.get_method() != 'POST': http.MethodError(('POST',)) p = self.pic(); if not self.collection.mayEdit(p): raise AccessError('may not edit image') angle = request.form.get('angle', None) self.meta.set_orientation(angle) ref = request.get_environ('HTTP_REFERER') if ref is not None: response.redirect(ref + '#pic%d' % p.id) http.json_response() (tw,th) = ImageTransform.thumb_size(p) ret = { 'thumb': { 'width': tw, 'height': th, 'pos_left': (style.thumb_size - tw) / 2, 'pos_top': (style.thumb_size - th) / 2, }, 'image': { 'width': p.width, 'height': p.height, 'orientation': p.orientation, }, 'rot90': ( 90 + p.orientation) % 360, 'rot180': (180 + p.orientation) % 360, 'rot270': (270 + p.orientation) % 360, } return json.write(ret)