def get(self, **kwargs): files = File.get_latest_files(10) context = { 'files': files } return self.render_response('admin/files/index.html', **context)
def post(self, offer_id=None, **kwargs): """Handle submitted form data""" photo = self.request.form.get('photo') or None if photo: photo = File.get_by_id(int(photo)) # validate form if self.form.validate(): title = self.form.title.data intro = self.form.intro.data content = self.form.content.data promoted = self.form.promoted.data live = self.form.live.data language = self.form.language.data if offer_id: offer = Offer.get_by_id(offer_id) offer.title = title offer.intro = intro offer.content = content offer.live = live offer.promoted = promoted offer.language = language offer.photo = photo # creating new else: offer = Offer(title=title, intro=intro, content=content, live=live, promoted=promoted, language=language, photo=photo) if offer.put(): return redirect('admin/daily') return self.get(**kwargs)
def post(self, **kwargs): if self.form.validate(): title = self.form.title.data file_data = self.form.file_data.data uploaded_files = self.get_uploads('file_data') blob_info = uploaded_files[0] logging.warn(blob_info) new_file = File(title=title, file_data=blob_info.key()) # checking the file response = redirect_to('admin/files/index') if new_file.put(): response.data = '' return response return self.get(**kwargs)
def post(self, **kwargs): if self.form.validate(): title = self.form.title.data file_data = self.form.file_data.data uploaded_files = self.get_uploads('file_data') blob_info = uploaded_files[0] new_file = File(title=title, file_data=blob_info.key()) # checking the file response = redirect_to('admin/files/index') if new_file.put(): response.data = '' return response return self.get(**kwargs)
def file_create_new_file(file): ret = {'code': config.CODE_OK} sid = utils.fetch_sid(file.filename) conditions = {'sid': sid} data = utils.jsonify_item_by(Student, conditions) # If student with sid doesn't exist, return 1 if data['code'] != config.CODE_OK: ret['code'] = config.CODE_ERROR return ret data = utils.jsonify_item_by(File, conditions) # This student never upload a file before if data['code'] != config.CODE_OK: current_category = Category.query.filter_by(is_current=True).first() doc = File( sid=sid, filename=file.filename, upload_time=datetime.datetime.now(), size=0, # Will modify later category_id=current_category.id) # Will modify later db.session.add(doc) db.session.commit() directory = os.path.join(settings.UPLOAD_DIR, current_category.name) if not os.path.exists(directory): os.mkdir(directory) path = os.path.join(directory, doc.filename) file.save(path) ret['code'] = config.CODE_OK ret['item'] = utils.serialize(doc) tools.send_msg_when_upload_new_file(sender, sid, file) return ret # This student replace old file with a new file # Remove old file item = data['item'] category = Category.query.filter_by(id=item['category_id']).first() old_path = os.path.join(settings.UPLOAD_DIR, category.name, item['filename']) os.remove(old_path) # Create new file new_path = os.path.join(settings.UPLOAD_DIR, category.name, file.filename) file.save(new_path) # Update file in table old_file = File.query.filter_by(sid=sid).first() old_file.filename = file.filename old_file.upload_time = datetime.datetime.now() db.session.commit() data = utils.jsonify_item_by(File, conditions) ret['code'] = data['code'] ret['item'] = data['item'] tools.send_msg_when_replace_file(sender, sid, file) return ret
def get_files(): files = File.get_latest_files(None, 100) ''' [{ 'id': 1, 'title': 'title' }] ''' default_list = {'id': '', 'title': unicode(_('Please choose an image'))} if files: file_list = [( { 'id': f.key().id(), 'title': unicode(f.title) }) for f in files] file_list.insert(0, default_list) else: file_list = default_list return file_list
def post(self, product_id=None, **kwargs): """Handle submitted form data""" # validate form photo = self.request.form.get('photo') or None if photo: photo = File.get_by_id(int(photo)) if self.form.validate(): name = self.form.name.data description = self.form.description.data price = self.form.price.data unit = self.form.unit.data live = self.form.live.data promoted = self.form.promoted.data tags = self.form.tags.data language = self.form.language.data if tags is not None: tags = [tag.strip() for tag in tags.split(',') if tag != ''] # save edit form if product_id: product = Product.get_by_id(product_id) product.photo = photo product.name = name product.description = description product.price = price product.unit = unit product.live = live product.promoted = promoted product.tags = tags product.language = language # save new form else: product = Product(name=name, description=description, price=price, unit=unit, live=live, promoted=promoted, tags=tags, language=language, photo=photo) if product.put(): return redirect('/admin/shop/products/') return self.get(**kwargs)
def setup_file(self): file = File.encrypt_file(self.get_file(), self.aes_key_rlc) self.file = File.objects.create(name='test.txt', folder=self.folder, file=file)
def get(self, **kwargs): files = File.get_latest_files(10) context = {'files': files} return self.render_response('admin/files/index.html', **context)