def update(id): form = RegistrationForm() if form.validate() is False: return render_template('scholar/edit.html', form=form) else: article = Article.query.filter_by(id=id).first_or_404() article.title = form.title.data article.theme = form.theme.data article.abstract = form.abstract.data article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') article.authors = [] article.keywords = [] author_input_list = form.authors.data.split(',') for author_input in author_input_list: article.authors.append(AuthorScholar(author_input)) keyword_input_list = form.keywords.data.split(',') for keyword_input in keyword_input_list: keyword = KeyWord.query.filter_by(name=keyword_input).first() if not keyword: article.keywords.append(KeyWord(keyword_input)) else: article.keywords.append(keyword) db.session.commit() message = u'Estudo editado com sucesso!' flash(message, 'success') return redirect(url_for('scholar.index'))
def postKeyword(): try: body = request.get_json() new_keyword = body.get('keyword', None) newKeyword = KeyWord(keyword=new_keyword) newKeyword.insert() return jsonify({ 'success': True, 'keyword': newKeyword.format(), 'created': newKeyword.id }) except Exception as E: print(E) abort(422)
def create(): csrf_token = request.form.get('csrf_token') upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, csrf_token, 'files') form = RegistrationForm() if not os.path.exists(upload_folder): flash(u'Selecione o arquivo do artigo para enviá-lo.', 'danger') return render_template('scholar/new.html', form=form) if form.validate() is False: form.set_choices(approved_articles_keywords()) return render_template('scholar/new.html', form=form) else: article = Article() article.title = form.title.data article.theme = form.theme.data article.abstract = form.abstract.data article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') article.approval_status = 0 author_input_list = form.authors.data.replace(', ', ',').split(',') for author_input in author_input_list: article.authors.append(AuthorScholar(author_input)) for keyword_input in form.keywords.data: keyword = KeyWord.query.filter_by(name=keyword_input).first() if not keyword: article.keywords.append(KeyWord(keyword_input)) else: article.keywords.append(keyword) db.session.add(article) db.session.flush() if os.path.exists(upload_folder): file_name = [file for file in os.listdir(upload_folder)][0] article.file_url = upload_helper.upload_s3_file( os.path.join(upload_folder, file_name), os.path.join('scholar/', str(article.id), 'files/', 'article'), { 'ContentType': "application/pdf", 'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf' } ) shutil.rmtree(os.path.split(upload_folder)[0]) db.session.commit() upload_helper.log_operation(module=mod.name, operation='create', user=(g.user.id, g.user.email), objs=[(article.id, article.title)]) new_article_advise(article, request.url_root) message = dictionary()["article_submission"] flash(message, 'success') return redirect(url_for('scholar.index'))
def update(id): csrf_token = request.form.get('csrf_token') upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, csrf_token, 'files') article = Article.query.filter_by(id=id).first_or_404() form = RegistrationForm() if form.validate() is False: form.set_choices(approved_articles_keywords()) return render_template('scholar/edit.html', form=form) else: old_title = article.title article.title = form.title.data article.theme = form.theme.data article.abstract = form.abstract.data article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') article.authors = [] article.keywords = [] author_input_list = form.authors.data.replace(', ', ',').split(',') for author_input in author_input_list: article.authors.append(AuthorScholar(author_input)) for keyword_input in form.keywords.data: keyword = KeyWord.query.filter_by(name=keyword_input).first() if not keyword: article.keywords.append(KeyWord(keyword_input)) else: article.keywords.append(keyword) if os.path.exists(upload_folder): file_name = [file for file in os.listdir(upload_folder)][0] article.file_url = upload_helper.upload_s3_file( os.path.join(upload_folder, file_name), os.path.join('scholar/', str(article.id), 'files/', 'article'), { 'ContentType': "application/pdf", 'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf' }) shutil.rmtree(os.path.split(upload_folder)[0]) db.session.commit() upload_helper.log_operation(module=mod.name, operation='edit', user=(g.user.id, g.user.email), objs=[(article.id, old_title)]) message = u'Estudo editado com sucesso!' flash(message, 'success') return redirect(url_for('scholar.admin'))
def create(): form = RegistrationForm() if form.validate() is False: return render_template('scholar/new.html', form=form) else: article = Article() article.title = form.title.data article.theme = form.theme.data article.abstract = form.abstract.data article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') article.approval_status = 0 author_input_list = form.authors.data.split(',') for author_input in author_input_list: article.authors.append(AuthorScholar(author_input)) keyword_input_list = form.keywords.data.split(',') for keyword_input in keyword_input_list: keyword = KeyWord.query.filter_by(name=keyword_input).first() if not keyword: article.keywords.append(KeyWord(keyword_input)) else: article.keywords.append(keyword) db.session.add(article) db.session.flush() file_path = app.config['UPLOAD_FOLDER'] + request.form.get( 'csrf_token') file_name = [file for file in os.listdir(file_path)][0] upload_helper.upload_s3_file( os.path.join(file_path, file_name), 'dataviva', os.path.join('scholar/article/', str(article.id)), { 'ContentType': "application/pdf", 'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf' }) shutil.rmtree(file_path) db.session.commit() message = u'Muito obrigado! Seu estudo foi submetido com sucesso e será analisado pela equipe do DataViva. \ Em até 15 dias você receberá um retorno sobre sua publicação no site!' flash(message, 'success') return redirect(url_for('scholar.index'))
def add_keyword(): word = request.form.get('word') if word is not None: key = KeyWord() key.word = word key.enable = True key.put() flash(u'KeyWord add successfully~', 'success') flush_keyword_cache() return redirect(url_for("admin"))