コード例 #1
0
ファイル: views.py プロジェクト: rhozon/dataviva-site
def admin_delete():
    ids = request.form.getlist('ids[]')
    subjects = PublicationSubject.query.all()
    deleted_publications = []

    if ids:
        publications = Publication.query.filter(Publication.id.in_(ids)).all()
        for publication in publications:
            try:
                delete_s3_folder(os.path.join(mod.name, str(publication.id)))
            except Exception:
                pass
            db.session.delete(publication)
            db.session.flush()
            deleted_publications.append((publication.id, publication.title))

            for subject in subjects:
                if subject.publications.count() == 0:
                    db.session.delete(subject)

        db.session.commit()
        log_operation(module=mod.name,
                      operation='delete',
                      user=(g.user.id, g.user.email),
                      objs=deleted_publications)
        return u"Notícia(s) excluída(s) com sucesso!", 200
    else:
        return u'Selecione alguma notícia para excluí-la.', 205
コード例 #2
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
def admin_delete():
    ids = request.form.getlist('ids[]')
    subjects = PublicationSubject.query.all()
    deleted_publications = []

    if ids:
        publications = Publication.query.filter(Publication.id.in_(ids)).all()
        for publication in publications:
            try:
                delete_s3_folder(os.path.join(mod.name, str(publication.id)))
            except Exception:
                pass
            db.session.delete(publication)
            db.session.flush()
            deleted_publications.append((publication.id, publication.title))

            for subject in subjects:
                if subject.publications.count() == 0:
                    db.session.delete(subject)

        db.session.commit()
        log_operation(module=mod.name, operation='delete', user=(g.user.id, g.user.email), objs=deleted_publications)
        return u"Notícia(s) excluída(s) com sucesso!", 200
    else:
        return u'Selecione alguma notícia para excluí-la.', 205
コード例 #3
0
ファイル: views.py プロジェクト: rhozon/dataviva-site
def admin_delete():
    ids = request.form.getlist('ids[]')
    keywords = KeyWord.query.all()
    deleted_articles = []

    if ids:
        articles = Article.query.filter(Article.id.in_(ids)).all()
        for article in articles:
            upload_helper.delete_s3_folder(
                os.path.join(mod.name, str(article.id)))
            db.session.delete(article)
            db.session.flush()
            deleted_articles.append((article.id, article.title))

            for keyword in keywords:
                if keyword.articles.count() == 0:
                    db.session.delete(keyword)

        db.session.commit()
        upload_helper.log_operation(module=mod.name,
                                    operation='delete',
                                    user=(g.user.id, g.user.email),
                                    objs=deleted_articles)
        return u"Artigo(s) excluído(s) com sucesso!", 200
    else:
        return u'Selecione algum artigo para excluí-lo.', 205
コード例 #4
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
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'))
コード例 #5
0
ファイル: views.py プロジェクト: joaohbr28/dataviva-site
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'))
コード例 #6
0
ファイル: views.py プロジェクト: rhozon/dataviva-site
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'))
コード例 #7
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
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'))
コード例 #8
0
ファイル: views.py プロジェクト: rhozon/dataviva-site
def update(id):
    form = RegistrationForm()
    id = int(id.encode())
    if form.validate() is False:
        form.set_choices()
        return render_template('news/edit.html', form=form)
    else:
        publication = Publication.query.filter_by(id=id).first_or_404()
        old_title = publication.title
        publication.title = form.title.data
        publication.text_call = form.text_call.data
        publication.last_modification = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        publication.publish_date = form.publish_date.data.strftime('%Y-%m-%d')
        publication.show_home = form.show_home.data
        publication.author = form.author.data
        publication.language = form.language.data
        if form.thumb_src.data:
            publication.thumb_src = form.thumb_src.data
        else:
            publication.thumb_src = None

        num_subjects = len(publication.subjects)
        for i in range(0, num_subjects):
            publication.subjects.remove(publication.subjects[0])

        publication.add_subjects(form.subject.data, form.language.data)

        publication.text_content = upload_images_to_s3(form.text_content.data,
                                                       mod.name,
                                                       publication.id)
        clean_s3_folder(publication.text_content, mod.name, publication.id)

        if len(form.thumb.data.split(',')) > 1:
            upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name,
                                         str(publication.id), 'images')
            publication.thumb = save_b64_image(
                form.thumb.data.split(',')[1], upload_folder, 'thumb')

        db.session.commit()
        log_operation(module=mod.name,
                      operation='edit',
                      user=(g.user.id, g.user.email),
                      objs=[(publication.id, old_title)])

        message = u'Notícia editada com sucesso!'
        flash(message, 'success')
        return redirect(url_for('news.admin'))
コード例 #9
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
def update(id):
    form = RegistrationForm()
    id = int(id.encode())
    if form.validate() is False:
        form.set_choices()
        return render_template('news/edit.html', form=form)
    else:
        publication = Publication.query.filter_by(id=id).first_or_404()
        old_title = publication.title
        publication.title = form.title.data
        publication.text_call = form.text_call.data
        publication.last_modification = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        publication.publish_date = form.publish_date.data.strftime('%Y-%m-%d')
        publication.show_home = form.show_home.data
        publication.author = form.author.data
        publication.language = form.language.data
        if form.thumb_src.data:
            publication.thumb_src = form.thumb_src.data
        else:
            publication.thumb_src = None

        num_subjects = len(publication.subjects)
        for i in range(0, num_subjects):
            publication.subjects.remove(publication.subjects[0])

        publication.add_subjects(form.subject.data, form.language.data)

        publication.text_content = upload_images_to_s3(
            form.text_content.data, mod.name, publication.id)
        clean_s3_folder(publication.text_content, mod.name, publication.id)

        if len(form.thumb.data.split(',')) > 1:
            upload_folder = os.path.join(
                app.config['UPLOAD_FOLDER'], mod.name, str(publication.id), 'images')
            publication.thumb = save_b64_image(
                form.thumb.data.split(',')[1], upload_folder, 'thumb')

        db.session.commit()
        log_operation(module=mod.name, operation='edit', user=(g.user.id, g.user.email), objs=[(publication.id, old_title)])

        message = u'Notícia editada com sucesso!'
        flash(message, 'success')
        return redirect(url_for('news.admin'))
コード例 #10
0
ファイル: views.py プロジェクト: rhozon/dataviva-site
def create():
    form = RegistrationForm()
    if form.validate() is False:
        form.set_choices()
        return render_template('news/new.html', form=form)
    else:
        publication = Publication()
        publication.title = form.title.data
        publication.text_call = form.text_call.data
        publication.last_modification = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        publication.publish_date = form.publish_date.data.strftime('%Y-%m-%d')
        publication.show_home = form.show_home.data
        publication.active = 0
        publication.author = form.author.data
        publication.language = form.language.data
        publication.add_subjects(form.subject.data, form.language.data)

        if form.thumb_src.data:
            publication.thumb_src = form.thumb_src.data

        db.session.add(publication)
        db.session.flush()

        text_content = upload_images_to_s3(form.text_content.data, mod.name,
                                           publication.id)
        Publication.query.get(publication.id).text_content = text_content
        clean_s3_folder(text_content, mod.name, publication.id)

        if len(form.thumb.data.split(',')) > 1:
            upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name,
                                         str(publication.id), 'images')
            publication.thumb = save_b64_image(
                form.thumb.data.split(',')[1], upload_folder, 'thumb')

        db.session.commit()
        log_operation(module=mod.name,
                      operation='create',
                      user=(g.user.id, g.user.email),
                      objs=[(publication.id, publication.title)])
        message = u'Muito obrigado! Sua notícia foi submetida com sucesso!'
        flash(message, 'success')
        return redirect(url_for('news.admin'))
コード例 #11
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
def create():
    form = RegistrationForm()
    if form.validate() is False:
        form.set_choices()
        return render_template('news/new.html', form=form)
    else:
        publication = Publication()
        publication.title = form.title.data
        publication.text_call = form.text_call.data
        publication.last_modification = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        publication.publish_date = form.publish_date.data.strftime('%Y-%m-%d')
        publication.show_home = form.show_home.data
        publication.active = 0
        publication.author = form.author.data
        publication.language = form.language.data
        publication.add_subjects(form.subject.data, form.language.data)

        if form.thumb_src.data:
            publication.thumb_src = form.thumb_src.data

        db.session.add(publication)
        db.session.flush()

        text_content = upload_images_to_s3(
            form.text_content.data, mod.name, publication.id)
        Publication.query.get(publication.id).text_content = text_content
        clean_s3_folder(text_content, mod.name, publication.id)

        if len(form.thumb.data.split(',')) > 1:
            upload_folder = os.path.join(
                app.config['UPLOAD_FOLDER'], mod.name, str(publication.id), 'images')
            publication.thumb = save_b64_image(
                form.thumb.data.split(',')[1], upload_folder, 'thumb')

        db.session.commit()
        log_operation(module=mod.name, operation='create', user=(g.user.id, g.user.email), objs=[(publication.id, publication.title)])
        message = u'Muito obrigado! Sua notícia foi submetida com sucesso!'
        flash(message, 'success')
        return redirect(url_for('news.admin'))
コード例 #12
0
ファイル: views.py プロジェクト: DataViva/dataviva-site
def admin_delete():
    ids = request.form.getlist('ids[]')
    keywords = KeyWord.query.all()
    deleted_articles = []

    if ids:
        articles = Article.query.filter(Article.id.in_(ids)).all()
        for article in articles:
            upload_helper.delete_s3_folder(os.path.join(mod.name, str(article.id)))
            db.session.delete(article)
            db.session.flush()
            deleted_articles.append((article.id, article.title))

            for keyword in keywords:
                if keyword.articles.count() == 0:
                    db.session.delete(keyword)

        db.session.commit()
        upload_helper.log_operation(module=mod.name, operation='delete', user=(g.user.id, g.user.email), objs=deleted_articles)
        return u"Artigo(s) excluído(s) com sucesso!", 200
    else:
        return u'Selecione algum artigo para excluí-lo.', 205