def new_poster(): source_url = session.get('source_url') context = { 'title': 'Untitled', 'authors': '', 'abstract': '', 'download_url': '', 'presented_at': '', } if request.method == 'GET': if not source_url: return redirect(url_for('index')) context.update(extract_data(source_url)) form = PosterForm(**context) if form.validate_on_submit(): p = Poster( title=form.title.data, authors=form.authors.data, abstract=form.abstract.data, source_url=source_url, download_url=form.download_url.data, presented_at=form.presented_at.data, ) db.session.add(p) db.session.commit() flash('Information successfully saved!') return redirect(url_for('publish_poster', id_admin=p.id_admin)) return render_template('new_edit_poster.html', is_edit=False, form=form)
def test_get_qrcode_svg(self): p = Poster(title='Hello', source_url='http://example.org', download_url='') with app.app_context(): db.session.add(p) db.session.commit() r = self.client.get('/posters/{}.svg'.format(p.id)) assert r.status_code == 200
def test_get_poster(self): p = Poster(title='Hello', source_url='http://example.org', download_url='') with app.app_context(): db.session.add(p) db.session.commit() r = self.client.get('/posters/{}'.format(p.id)) assert r.status_code == 200 assert b'<h1 class="title">Hello</h1>' in r.data
def test_get_poster_json(self): p = Poster(title='Hello', source_url='http://example.org', download_url='') with app.app_context(): db.session.add(p) db.session.commit() r = self.client.get('/posters/{}'.format(p.id), headers={ 'Accept': 'application/json', }) assert r.status_code == 200 assert r.content_type == 'application/json'
def save(self): self.img = self.__find_by_md5_hash() if self.img is not None: return None file_name = secure_filename(self.file.filename) self.img = Poster(id=str(uuid4()), file_name=file_name, mime_type=self.file.mimetype, md5_hash=self.md5_hash) self.file.save( os.path.join(current_app.config['UPLOAD_FOLDER'], self.img.storage_filename)) db.session.add(self.img) db.session.commit() return self.img
def new_thread(): """ POST API endpoint for creating new threads. """ form = NewThreadForm() if form.validate_on_submit(): data = form.data.copy() poster = Poster.from_details(data.pop('name')) t = poster.create_thread(**data) return redirect(url_for('thread', thread_id=t.id)) else: flash_form_errors(form) return redirect(url_for('index'))
def new_post(thread_id): """ POST API endpoint for creating a new post for the thread with given `thread_id`. Also returns a 404 if it doesn't exist. """ t = Thread.query.get_or_404(thread_id) form = NewPostForm() if form.validate_on_submit(): data = form.data.copy() poster = Poster.from_details(data.pop('name')) poster.create_post(t, **data) return redirect(url_for('thread', thread_id=thread_id)) else: flash_form_errors(form) return redirect(url_for('thread', thread_id=thread_id))
def test_is_image(): p = Poster(title='title', source_url='', download_url='http://example.org/poster.png') assert p.is_image() is True