def upload(self, request): form = self.upload_form(request) if form.get_submit() != 'upload': r = TemplateIO(html=True) r += page.pre(request, 'Upload pictures', 'upload') r += page.menupane(request) r += form.render() #r += H(request.dump_html()) r += page.post() return r.getvalue() else: user = request.session.getuser() start = calendar.int_day.rounddown(gmt()) end = calendar.int_day.roundup(gmt()) upload = db.Upload.select(AND(db.Upload.q.import_time >= start, db.Upload.q.import_time < end, db.Upload.q.userID == user.id, db.Upload.q.collectionID == self.collection.db.id)) assert upload.count() == 0 or upload.count() == 1, \ 'Should be only one Upload per day per user' if upload.count() == 1: u = upload[0] else: u = db.Upload(user=user, collection=self.collection.db) c = int(form['camera']) if c == -2: camera = None # new camera elif c == -1: camera = None # guess else: camera = db.Camera.get(c) numfiles = int(form['numfiles']) keywords = form['keywords'] if keywords is not None: keywords = splitKeywords(keywords) print 'self.collection.db=%s' % self.collection.db request.response.buffered=False upload = self.do_upload(request, [ (f.fp, f.base_filename) for f in [ form['file.%d' % n] for n in range(numfiles) ] if f is not None], user, camera, keywords, form['visibility'], u) return quixote.http_response.Stream(upload)
def commit(self, request): user = request.session.getuser() print request.dump() if not request.form: raise QueryError, 'missing form' pics = request.form['pic'] if not isinstance(pics, list): pics = [ pics ] if request.form.has_key('commit'): for p in pics: p = db.Picture.get(int(p)) print 'p=%d p.upload=%s' % (p.id, p.upload) if p.upload is None: continue if not user.mayAdmin and (not p.mayEdit(user) or p.upload.userID != user.id): raise AccessError, "you can't commit this" p.upload = None if not self.have_pending(user): return quixote.redirect(self.collection.path()) elif request.form.has_key('defaults'): kw = splitKeywords(request.form['keywords']) vis = request.form['visibility'] for p in pics: p = db.Picture.get(int(p)) p.addKeywords(kw) if vis != 'unchanged': p.visibility = vis return quixote.redirect(self.pending_path())