Exemplo n.º 1
0
def edit_professors():
    """Render a view for editing professors."""

    form = ProfessorForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.boards_of_professors_dao()
    json = pfactory.boards_of_professors_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        new_professor = {
            'name': form.name.data,
            'rank': form.rank.data,
            'lattes': form.lattes.data,
            'email': form.email.data
        }

        dao.find_one_and_update(
            None, {'$set': {
                'professors.' + index: new_professor
            }})

        return redirect(
            url_for('admin.edit_professors',
                    professors=json,
                    success_msg='Professor editado com sucesso.'))

    return render_template('admin/edit_professors.html',
                           form=form,
                           professors=json,
                           success_msg=request.args.get('success_msg'))
def edit_project():
    """Render project editing form."""

    form = ProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if form.validate_on_submit() and form.create.data:
        new_project = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'description': form.description.data,
            'situation': form.situation.data,
            'year': form.year.data,
            'email': form.email.data,
            'dt_init': form.dt_init.data,
            'dt_end': form.dt_end.data
        }
        dao.find_one_and_update({'_id' : ObjectId(form.project_id.data)}, {
            '$set' : new_project})
        return redirect(
            url_for(
                'crud_projects.edit_project',
                success_msg='Projeto editado com sucesso.'
            )
        )
    return render_template(
        'admin/edit_projects.html',
        form=form,
        projects=projects,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 3
0
def delete_professors():
    """Render a view for deleting professors."""

    form = ProfessorForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.boards_of_professors_dao()
    json = pfactory.boards_of_professors_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(
            None, {'$set': {
                'professors.' + index + '.deleted': ""
            }})

        return redirect(
            url_for('admin.delete_professors',
                    professors=json,
                    success_msg='Professor deletado com sucesso.'))

    return render_template('admin/delete_professors.html',
                           form=form,
                           professors=json,
                           success_msg=request.args.get('success_msg'))
def delete_project():
    """Render project deleting form."""

    form = ProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if form.validate_on_submit() and form.create.data:
        dao.find_one_and_update({'_id' : ObjectId(form.project_id.data)}, {
            '$set' : {'deleted' : '' }})
        return redirect(
            url_for(
                'crud_projects.delete_project',
                success_msg='Projeto deletado com sucesso.'
            )
        )
    return render_template(
        'admin/delete_project.html',
        form=form,
        projects=projects,
        success_msg=request.args.get('success_msg')
    )
def delete_subjects():
    """
    Render a delete subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType' : course_type})
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        condition = {'title': form.requirement.data, 'courseType' : form.course_type.data}
        dao.find_one_and_update(condition, {
            '$set': {'subjects.' + index + '.deleted' : ""}
        })

        return redirect(
            url_for(
                'crud_subjects.delete_subjects',
                success_msg='Disciplina deletada com sucesso',
                course_type=form.course_type.data
            )
        )
    return render_template(
        'admin/delete_subjects.html',
        form=form,
        subjects=json,
        success_msg=request.args.get('success_msg'),
    )
Exemplo n.º 6
0
def delete_book():
    """
    Render a book deleting form
    """

    form = BookForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    json = pfactory.publications_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None,
                                {'$set': {
                                    'books.' + index + '.deleted': ''
                                }})

        return redirect(
            url_for('crud_books.delete_book',
                    success_msg='Livro deletado com sucesso.'))

    return render_template('admin/delete_books.html',
                           publications=json,
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 7
0
def edit_member():

    form = MemberOfProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if form.validate_on_submit():
        index = str(form.index.data)
        new_member = {
            'name': form.name.data,
            'general_role': form.general_role.data,
            'project_role': form.project_role.data
        }
        dao.find_one_and_update({'_id': ObjectId(form.project_id.data)},
                                {'$set': {
                                    'members.' + index: new_member
                                }})
        projects = pfactory.projects_database_dao().find()
        projects = list(projects)
        projects = dumps(projects)
        return jsonify(projects=projects)
    else:
        return jsonify({'error': 'Houve um erro'})
Exemplo n.º 8
0
 def get(nick, authenticated=False):
     """Return an User from database. If failed, None."""
     try:
         condition = {'users.nick': nick}
         pfactory = PosGraduationFactory()
         dao = pfactory.post_graduations_dao()
         program = list(dao.find(condition))
         if program:
             initials = program[0]['initials']
         else:
             return None
         for user in program[0]['users']:
             if nick.lower() == user['nick'].lower():
                 found_user = User()
                 found_user._nick = user['nick']
                 found_user._pg_initials = initials.lower()
                 found_user._full_name = user['fullName']
                 found_user._role = user['role']
                 found_user._email = user['email']
                 found_user._token = user['token']
                 found_user.__is_authenticated = authenticated
                 found_user.__is_active = True
                 found_user.__is_anonymous = False
                 return found_user
         return None
     except (TypeError, AttributeError):
         return None
Exemplo n.º 9
0
def edit_project():
    """Render project editing form."""

    form = ProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if form.validate_on_submit() and form.create.data:
        new_project = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'description': form.description.data,
            'situation': form.situation.data,
            'year': form.year.data,
            'email': form.email.data,
            'dt_init': form.dt_init.data,
            'dt_end': form.dt_end.data
        }
        dao.find_one_and_update({'_id': ObjectId(form.project_id.data)},
                                {'$set': new_project})
        return redirect(
            url_for('crud_projects.edit_project',
                    success_msg='Projeto editado com sucesso.'))
    return render_template('admin/edit_projects.html',
                           form=form,
                           projects=projects,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 10
0
def edit_book():
    """
    Render a book editing form
    """

    form = BookForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    json = pfactory.publications_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        new_book = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'authors': form.authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'year': form.year.data
        }

        dao.find_one_and_update(None, {'$set': {'books.' + index: new_book}})

        return redirect(
            url_for('crud_books.edit_book',
                    success_msg='Livro editado com sucesso.'))

    return render_template('admin/edit_books.html',
                           publications=json,
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 11
0
def view_classes(initials):
    """Render a view for classes list."""

    form = FindClass()

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation
    now = datetime.datetime.now()
    if now.month <= 7:
        semester = 1
    else:
        semester = 2
    classes = pfactory.classes_dao(now.year, semester, 100).find()
    if form.validate_on_submit():
        return redirect(
            url_for('public.find_classes',
                    initials=initials,
                    year=form.year.data,
                    period=form.period.data))

    # renders an own page or redirect to another (external/404)?
    return render_template('public/subjectsinclasses.html',
                           std=get_std_for_template(post_graduation),
                           form=form,
                           classes=classes)
Exemplo n.º 12
0
def delete_events():
    """Render a view for deleting events."""

    form = CalendarForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.calendar_dao()
    json = pfactory.calendar_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None,
                                {'$set': {
                                    'events.' + index + '.deleted': ""
                                }})

        return redirect(
            url_for('crud_events.delete_events',
                    events=json,
                    success_msg='Evento deletado com sucesso.'))

    return render_template('admin/delete_events.html',
                           events=json,
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 13
0
def add_article():
    """
    Render a article adding form
    """

    form = ArticleForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()

    if form.validate_on_submit() and form.create.data:
        new_article = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'authors': form.authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'number': form.number.data,
            'pages': form.pages.data,
            'date': form.date.data
        }

        dao.find_one_and_update(None, {'$push': {'articles': new_article}})

        return redirect(
            url_for('crud_articles.add_article',
                    success_msg='Novo artigo adicionado com sucesso.'))

    return render_template('admin/add_article.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 14
0
def participations():
    """Render a view for integrations lists."""

    form = ParticipationsInEventsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.integrations_infos_dao()

    if form.validate_on_submit() and form.create.data:
        new_participation = {
            'title': form.title.data,
            'description': form.description.data,
            'year': form.year.data,
            'international': form.location.data
        }

        dao.find_one_and_update(
            None, {'$push': {
                'participationsInEvents': new_participation
            }})

        return redirect(
            url_for(
                'admin.participations',
                success_msg='Intercâmbio adicionado adicionado com sucesso.'))

    return render_template(
        'admin/participations.html',
        participations=dao.find_one()['participationsInEvents'],
        form=form,
        success_msg=request.args.get('success_msg'))
Exemplo n.º 15
0
def delete_subjects():
    """
    Render a delete subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType': course_type})
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        condition = {
            'title': form.requirement.data,
            'courseType': form.course_type.data
        }
        dao.find_one_and_update(
            condition, {'$set': {
                'subjects.' + index + '.deleted': ""
            }})

        return redirect(
            url_for('crud_subjects.delete_subjects',
                    success_msg='Disciplina deletada com sucesso',
                    course_type=form.course_type.data))
    return render_template(
        'admin/delete_subjects.html',
        form=form,
        subjects=json,
        success_msg=request.args.get('success_msg'),
    )
def delete_news():

    form = NewsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.news_dao()
    news = pfactory.news_dao().find_one()
    news = dict(news)
    news = dumps(news)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'news.' + index + '.deleted' : ''}
        })

        return redirect(
            url_for(
                'crud_news.delete_news',
                success_msg='Notícia deletada com sucesso.'))

    return render_template(
        'admin/delete_news.html',
        news=news,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def delete_scheduled_reports():

    form = ScheduledReportForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.final_reports_dao()
    json = pfactory.final_reports_dao().find_one()
    json = dict(json)

    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'scheduledReports.' + index + '.deleted' : ""}
        })
        return redirect(
            url_for(
                'crud_scheduled_reports.delete_scheduled_reports',
                final_reports=json,
                success_msg='Agendamento deletado com sucesso'
            )
        )

    return render_template(
        'admin/delete_scheduled_reports.html',
        final_reports=json,
        form=form,
        post_graduation=current_user.pg_initials,
        success_msg=request.args.get('success_msg')
    )
def scheduled_reports():
    """
    Render a report scheduling form.
    """

    form = ScheduledReportForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.final_reports_dao()

    if form.validate_on_submit():
        new_report = {
            'time': datetime.combine(form.date.data, form.time.data.time()),
            'title': form.title.data,
            'author': form.author.data,
            'location': form.location.data
        }

        dao.find_one_and_update(None, {
            '$push': {'scheduledReports': new_report}
        })

        return redirect(
            url_for(
                'crud_scheduled_reports.scheduled_reports',
                success_msg='Defesa de tese adicionada com sucesso.'
            )
        )

    return render_template(
        'admin/scheduled_reports.html',
        form=form,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 19
0
def add_book():
    """
    Render a book adding form
    """

    form = BookForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()

    if form.validate_on_submit() and form.create.data:
        new_book = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'authors': form.authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'link': form.link.data,
            'year': form.year.data
        }

        dao.find_one_and_update(None, {'$push': {'books': new_book}})

        return redirect(
            url_for('crud_books.add_book',
                    success_msg='Novo livro adicionado com sucesso.'))

    return render_template('admin/add_book.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
def delete_staff():
    """
    Render a delete staff form.
    """

    form = StaffForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.boards_of_staffs_dao()
    json = pfactory.boards_of_staffs_dao().find_one()
    json = dict(json)
    json = dumps(json)
    index = '.' + str(form.index.data)
    if form.validate_on_submit():
        dao.find_one_and_update(None, {
            '$set': {form.function.data + index + '.deleted' : ''}
            })
        return redirect(
            url_for(
                'crud_staff.delete_staff',
                success_msg='Servidor deletado com sucesso.',
                staff=json
                )
        )

    return render_template(
        'admin/delete_staff.html',
        form=form,
        success_msg=request.args.get('success_msg'),
        staff=json
    )
Exemplo n.º 21
0
def add_researcher():
    """Render a view for researchers."""

    form = ResearcherForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.board_of_professors_dao()

    if form.validate_on_submit() and form.create.data:
        new_researcher = {
            'name': form.name.data,
            'cpf': form.cpf.data,
        }

        dao.find_one_and_update(None, {
            '$push': {'researchers': new_researcher}
        })

        return redirect(
            url_for(
                'admin.add_researcher',
                success_msg='Pesquisador adicionado com sucesso.'
            )
        )

    return render_template(
        'admin/add_researcher.html',
        form=form,
        success_msg=request.args.get('success_msg')
    )
def delete_book():
    """
    Render a book deleting form
    """

    form = BookForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    json = pfactory.publications_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'books.' + index + '.deleted' : ''}
        })

        return redirect(
            url_for(
                'crud_books.delete_book',
                success_msg='Livro deletado com sucesso.'))

    return render_template(
        'admin/delete_books.html',
        publications=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 23
0
def add_professors():
    """Render a view for professors."""

    form = ProfessorForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.board_of_professors_dao()

    if form.validate_on_submit() and form.create.data:
        new_professor = {
            'name': form.name.data,
            'rank': form.rank.data,
            'lattes': form.lattes.data,
            'email': form.email.data
        }

        dao.find_one_and_update(None, {
            '$push': {'professors': new_professor}
        })

        return redirect(
            url_for(
                'admin.add_professors',
                success_msg='Professor adicionado adicionado com sucesso.'
            )
        )

    return render_template(
        'admin/add_professors.html',
        form=form,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 24
0
def add_chapter():
    """
    Render a chapter in book adding form
    """

    pfactory = PosGraduationFactory(current_user.pg_initials)
    form = ChapterForm()

    dao = pfactory.publications_dao()

    if form.validate_on_submit() and form.create.data:
        new_chapter = {
            'bookTitle': form.book_title.data,
            'bookAuthors': form.book_authors.data,
            'chapterTitle': form.chapter_title.data,
            'chapterAuthors': form.chapter_authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'link': form.link.data,
            'pages': form.pages.data,
            'year': form.year.data
        }

        dao.find_one_and_update(None, {'$push': {'chapters': new_chapter}})

        return redirect(
            url_for('crud_books.add_chapter',
                    success_msg='Novo capitulo adicionado com sucesso.'))

    return render_template('admin/add_chapter.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 25
0
def delete_covenants():
    """Render covenant deleting form."""

    form = EditInstitutionsWithCovenantsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.integrations_infos_dao()
    json = pfactory.integrations_infos_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'institutionsWithCovenant.' + index + '.deleted' : ""}
        })
        return redirect(
            url_for(
                'admin.delete_covenants',
                integrations=json,
                success_msg='Convênio deletado com sucesso.'
            )
        )

    return render_template(
        'admin/delete_covenants.html',
        form=form,
        integrations=json,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 26
0
def view_documents(initials, document):
    """Render a view for documents list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation
    document_types = {
        'ata': 'Atas',
        'regiments': 'Regimentos',
        'resolucao': 'Resoluções',
        'outros': 'Outros',
        'reunion': 'Planos'
    }
    document_numbers = {
        'ata': 'Data',
        'regiments': 'Ano',
        'resolucao': 'N Resolução',
        'outros': 'Ano',
        'reunion': 'Título'
    }
    documents = pfactory.official_documents_dao().find({'category': document})

    # renders an own page or redirect to another (external/404)?
    return render_template('public/documents.html',
                           document_type=document_types[document],
                           document_number=document_numbers[document],
                           std=get_std_for_template(post_graduation),
                           documents=documents)
Exemplo n.º 27
0
def delete_documents():
    """Render document deleting form."""

    form = EditDocumentForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.official_documents_dao()
    json = pfactory.official_documents_dao().find()
    json = list(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        dao.find_one_and_update({'_id' : ObjectId(form.document_id.data)}, {
            '$set' : {'deleted' : ''}})
        return redirect(
            url_for(
                'admin.delete_documents',
                success_msg='Documento deletado com sucesso.'
            )
        )

    return render_template(
        'admin/delete_documents.html',
        documents=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 28
0
def add_events():
    """Render a view for adding events."""

    form = CalendarForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.calendar_dao()

    if form.validate_on_submit():
        initial_date = datetime.datetime.combine(form.initial_date.data,
                                                 datetime.datetime.min.time())
        if form.final_date.data != "":
            final_date = datetime.datetime.strptime(form.final_date.data,
                                                    '%d/%m/%Y')
            final_date = datetime.datetime.combine(
                final_date, datetime.datetime.min.time())
        else:
            final_date = form.final_date.data
        new_event = {
            'title': form.title.data,
            'initialDate': initial_date,
            'finalDate': final_date,
            'hour': form.hour.data,
            'link': form.link.data
        }

        dao.find_one_and_update(None, {'$push': {'events': new_event}})

        return redirect(
            url_for('crud_events.add_events',
                    success_msg='Evento adicionado adicionado com sucesso.'))

    return render_template('admin/add_events.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 29
0
def delete_news():

    form = NewsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.news_dao()
    news = pfactory.news_dao().find_one()
    news = dict(news)
    news = dumps(news)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None,
                                {'$set': {
                                    'news.' + index + '.deleted': ''
                                }})

        return redirect(
            url_for('crud_news.delete_news',
                    success_msg='Notícia deletada com sucesso.'))

    return render_template('admin/delete_news.html',
                           news=news,
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 30
0
def delete_staff():
    """
    Render a delete staff form.
    """

    form = StaffForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.boards_of_staffs_dao()
    json = pfactory.boards_of_staffs_dao().find_one()
    json = dict(json)
    json = dumps(json)
    index = '.' + str(form.index.data)
    if form.validate_on_submit():
        dao.find_one_and_update(
            None, {'$set': {
                form.function.data + index + '.deleted': ''
            }})
        return redirect(
            url_for('crud_staff.delete_staff',
                    success_msg='Servidor deletado com sucesso.',
                    staff=json))

    return render_template('admin/delete_staff.html',
                           form=form,
                           success_msg=request.args.get('success_msg'),
                           staff=json)
Exemplo n.º 31
0
def add_news():
    """
    Render a news adding form
    """

    form = NewsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.news_dao()

    if form.validate_on_submit() and form.create.data:
        id = ''.join([
            random.choice(string.ascii_letters + string.digits)
            for n in range(32)
        ])
        new_news = {
            'title': form.title.data,
            'headLine': form.headLine.data,
            'body': form.body.data,
            'id': id,
            'date': time.strftime("%d/%m/%Y")
        }

        dao.find_one_and_update(None, {'$push': {'news': new_news}})

        return redirect(
            url_for('crud_news.add_news',
                    success_msg='Nova notícia adicionada com sucesso.'))

    return render_template('admin/add_news.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 32
0
def add_project():
    """Render project adding form."""

    form = ProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    ownerProgram = pfactory.mongo_id

    if form.validate_on_submit() and form.create.data:
        new_project = {
            'ownerProgram': ownerProgram,
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'description': form.description.data,
            'situation': form.situation.data,
            'year': form.year.data,
            'email': form.email.data,
            'dt_init': form.dt_init.data,
            'dt_end': form.dt_end.data,
            'members': []
        }

        dao.insert_one(None, new_project)

        return redirect(
            url_for('crud_projects.add_project',
                    success_msg='Projeto adicionado adicionado com sucesso.'))
    return render_template('admin/add_project.html',
                           form=form,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 33
0
def delete_participations():
    """
    Render a delete participation form.
    """

    form = ParticipationsInEventsForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.integrations_infos_dao()
    json = pfactory.integrations_infos_dao().find_one()
    json = dict(json)
    json = dumps(json)
    index = str(form.index.data)

    if form.validate_on_submit():
        dao.find_one_and_update(
            None,
            {'$set': {
                'participationsInEvents.' + index + '.deleted': ""
            }})

        return redirect(
            url_for('crud_participation.delete_participations',
                    participations=json,
                    success_msg='Participação deletada com sucesso'))
    return render_template('admin/delete_participations.html',
                           form=form,
                           participations=json,
                           success_msg=request.args.get('success_msg'))
Exemplo n.º 34
0
def view_member():

    form = MemberOfProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if request.args.get('crud_type') == 'Adicionar':
        return render_template('admin/add_member_in_project.html',
                               form=form,
                               projects=projects,
                               crud_type=request.args.get('crud_type'),
                               success_msg=request.args.get('success_msg'))
    if request.args.get('crud_type') == 'Deletar':
        return render_template('admin/delete_member_in_project.html',
                               form=form,
                               projects=projects,
                               crud_type=request.args.get('crud_type'),
                               success_msg=request.args.get('success_msg'))
    else:
        return render_template('admin/edit_member_in_project.html',
                               form=form,
                               projects=projects,
                               crud_type=request.args.get('crud_type'),
                               success_msg=request.args.get('success_msg'))
def delete_events():
    """Render a view for deleting events."""

    form = CalendarForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.calendar_dao()
    json = pfactory.calendar_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'events.' + index + '.deleted' : ""}
        })

        return redirect(
            url_for(
                'crud_events.delete_events',
                events=json,
                success_msg='Evento deletado com sucesso.'
            )
        )

    return render_template(
        'admin/delete_events.html',
        events=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def view_classes(initials):
    """Render a view for classes list."""

    form = FindClass()
    
    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation
    now = datetime.datetime.now()
    if now.month <= 7:
        semester = 1
    else:
        semester = 2
    classes=pfactory.classes_dao(now.year,semester,100).find()
    if form.validate_on_submit():
        return redirect(
            url_for(
                'public.find_classes',
                initials=initials,
                year=form.year.data,
                period=form.period.data
            )
        )

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/subjectsinclasses.html',
        std=get_std_for_template(post_graduation),
        form=form,
        classes=classes
    )
Exemplo n.º 37
0
def delete_chapter():
    """
    Render a chapter delete form
    """

    form = ChapterForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    publications = pfactory.publications_dao().find_one()
    publications = dict(publications)
    publications = dumps(publications)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(
            None, {'$set': {
                'chapters.' + index + '.deleted': ''
            }})

        return redirect(
            url_for('crud_books.delete_chapter',
                    success_msg='Capítulo deletado com sucesso.'))

    return render_template('admin/delete_chapters.html',
                           publications=publications,
                           form=form,
                           success_msg=request.args.get('success_msg'))
def delete_chapter():
    """
    Render a chapter delete form
    """

    form = ChapterForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    publications = pfactory.publications_dao().find_one()
    publications = dict(publications)
    publications = dumps(publications)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        dao.find_one_and_update(None, {
            '$set': {'chapters.' + index + '.deleted' : ''}
        })

        return redirect(
            url_for(
                'crud_books.delete_chapter',
                success_msg='Capítulo deletado com sucesso.'))

    return render_template(
        'admin/delete_chapters.html',
        publications=publications,
        form=form,
        success_msg=request.args.get('success_msg')
    )
Exemplo n.º 39
0
def view_professors(initials):
    """Render a view for professors list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    board_of_professors = pfactory.boards_of_professors_dao().find_one()

    # manually fill missing lattes
    for professor in board_of_professors['professors']:
        if 'Djalma Freire Borges'.upper() in professor['name'].upper():
            professor['lattes'] = 'http://lattes.cnpq.br/3216184364856265'
        elif 'Káio César Fernandes'.upper() in professor['name'].upper():
            professor['lattes'] = 'http://lattes.cnpq.br/9740792920379789'
        elif 'Richard Medeiros de Araújo'.upper() in professor['name'].upper():
            professor['lattes'] = 'http://lattes.cnpq.br/6158536331515084'
        elif 'Ítalo Fittipaldi'.upper() in professor['name'].upper():
            professor['lattes'] = 'http://lattes.cnpq.br/7626654802346326'
        elif 'Hironobu Sano'.upper() in professor['name'].upper():
            professor['lattes'] = 'http://lattes.cnpq.br/6037766951080411'


    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/professors.html',
        std=get_std_for_template(post_graduation),
        board_of_professors=board_of_professors
    )
Exemplo n.º 40
0
def scheduled_reports():
    """
    Render a report scheduling form.
    """

    form = ScheduledReportForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.final_reports_dao()

    if form.validate_on_submit():
        new_report = {
            'time': form.time.data,
            'title': form.title.data,
            'author': form.author.data,
            'location': form.location.data
        }

        dao.find_one_and_update(None,
                                {'$push': {
                                    'scheduledReports': new_report
                                }})

        return index()
    else:
        return render_template('admin/scheduled_reports.html', form=form)
def view_member():

    form = MemberOfProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if request.args.get('crud_type') == 'Adicionar':
        return render_template(
            'admin/add_member_in_project.html',
            form=form,
            projects=projects,
            crud_type=request.args.get('crud_type'),
            success_msg=request.args.get('success_msg')
        )
    if request.args.get('crud_type') == 'Deletar':
        return render_template(
            'admin/delete_member_in_project.html',
            form=form,
            projects=projects,
            crud_type=request.args.get('crud_type'),
            success_msg=request.args.get('success_msg')
        )
    else:
        return render_template(
            'admin/edit_member_in_project.html',
            form=form,
            projects=projects,
            crud_type=request.args.get('crud_type'),
            success_msg=request.args.get('success_msg')
        )
Exemplo n.º 42
0
def edit_documents():
    """Render document editing form."""

    allowed_extensions = ['docx', 'pdf']

    form = EditDocumentForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.official_documents_dao()
    ownerProgram = pfactory.mongo_id
    json = pfactory.official_documents_dao().find()
    json = list(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        document_id = form.document_id.data
        if form.document.data:
            if allowedFile(form.document.data.filename, allowed_extensions):
                insertedOn = datetime.datetime.now()
                insertedBy = current_user._full_name
                document = form.document.data
                path = os.path.normpath("static/upload_files/" +
                                        current_user.pg_initials.lower())
                filename = uploadFiles(document, path, document.filename)
                new_document = {
                    'title': form.title.data,
                    'cod': form.cod.data,
                    'file': filename,
                    'insertedBy': insertedBy,
                    'insertedOn': insertedOn,
                    'category': form.category.data
                }

                dao.find_one_and_update(
                    {'_id': ObjectId(form.document_id.data)},
                    {'$set': new_document})
            else:
                return redirect(
                    url_for('admin.edit_documents',
                            success_msg='Tipo de documento inválido'))

        else:
            new_document = {
                'title': form.title.data,
                'cod': form.cod.data,
                'category': form.category.data
            }
            dao.find_one_and_update({'_id': ObjectId(form.document_id.data)},
                                    {'$set': new_document})

        return redirect(
            url_for('admin.edit_documents',
                    success_msg='Documento editado com sucesso.'))

    return render_template('admin/edit_documents.html',
                           documents=json,
                           form=form,
                           success_msg=request.args.get('success_msg'))
def edit_staff():
    """
    Render a staff form.
    """

    form = StaffForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.boards_of_staffs_dao()
    json = pfactory.boards_of_staffs_dao().find_one()
    json = dict(json)
    json = dumps(json)

    dao = pfactory.boards_of_staffs_dao()

    if form.validate_on_submit():
        index = '.' + str(form.index.data)
        if form.photo.data == '':
            photo = None
        else:
            photo = form.photo.data
        if form.function.data == 'coordination':
            new_staff = {
                'name': form.name.data,
                'rank': form.rank.data,
                'abstract': form.abstract.data,
                'photo': photo
            }

        else:
            new_staff = {
                'name': form.name.data,
                'function': {
                    'rank': form.rank.data,
                    'description': form.abstract.data
                },
                'photo': photo
            }
        dao.find_one_and_update(None, {
            '$set': {form.function.data + index: new_staff}
            })
        return redirect(
            url_for(
                'crud_staff.edit_staff',
                success_msg='Servidor editado com sucesso.',
                staff=json
                )
        )

    return render_template(
        'admin/edit_staff.html',
        form=form,
        success_msg=request.args.get('success_msg'),
        staff=json
    )
def find_classes():
    form = FindClass()
    pfactory = PosGraduationFactory(request.args['initials'])
    post_graduation = pfactory.post_graduation
    classes_2 =pfactory.classes_dao(request.args['year'], request.args['period'], 100).find()
    return render_template(
        'public/subjectsinclasses.html',
        std=get_std_for_template(post_graduation),
        form=form,
        classes=classes_2
    )
def edit_attendance():

    form = AttendanceForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.attendances_dao()
    json = pfactory.attendances_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        new_attendance = {
            'location' : {
                'building' : form.building.data,
                'floor' : form.floor.data,
                'room' : form.room.data,
                'opening' : form.opening.data
            },
            'email': form.email.data,
            'calendar': form.calendar.data,
            'phones' : {
                '0' : {
                    'type' : form.type1.data,
                    'number': form.phone1.data
                },
                '1' : {
                    'type': form.type2.data,
                    'number': form.phone2.data
                },
                '2' : {
                    'type': form.type3.data,
                    'number': form.phone3.data
                }
            }
        }

        dao.find_one_and_update({'_id' : ObjectId(form.attendance_id.data)}, {
            '$set': new_attendance
        })

        return redirect(
            url_for(
                'crud_attendances.edit_attendance',
                success_msg='Contato editado com sucesso.'))

    return render_template(
        'admin/edit_attendance.html',
        attendance=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def view_news_list(initials):
    """Render a view for a list of news viewing."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    news = pfactory.news_dao().find_one()['news']

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/news_list.html',
        std=get_std_for_template(post_graduation),
        news=news
    )
def view_staffs(initials):
    """Render a view for staff list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    board_of_staffs = pfactory.boards_of_staffs_dao().find_one()

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/staffs.html',
        std=get_std_for_template(post_graduation),
        board_of_staffs=board_of_staffs
    )
def view_subjects(initials):
    """Render a view for subjects."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    grades_of_subjects = pfactory.grades_of_subjects_dao().find({ '$or': [ { 'title': 'Eletivas' }, { 'title':'Obrigatórias' } ] })

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/subjects.html',
        std=get_std_for_template(post_graduation),
        grades_of_subjects=grades_of_subjects
    )
def view_covenants(initials):
    """Render a view for integrations lists."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    integrations_infos = pfactory.integrations_infos_dao().find_one()

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/covenants.html',
        std=get_std_for_template(post_graduation),
        integrations_infos=integrations_infos
    )
def view_documents_others(initials):
    """Render a view for documents list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    documents = pfactory.official_documents_dao().find({'category':'outros'})

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/documents_others.html',
        std=get_std_for_template(post_graduation),
        documents=documents
    )
def view_calendar(initials):
    """Render a view for calendar."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    calendar_info = pfactory.calendar_dao().find_one()

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/calendar.html',
        std=get_std_for_template(post_graduation),
        calendar_info=calendar_info
    )
def view_chapters(initials):
    """Render a view for chapters list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    publications = pfactory.publications_dao().find_one()

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/chapters.html',
        std=get_std_for_template(post_graduation),
        publications=publications
    )
def view_news(initials):
    """Render a view for news viewing."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    id = request.args.get('id')
    news = pfactory.news_dao().find_one()['news']
    fullNews = next(piece for piece in news if piece['id'] == id)

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/news.html',
        std=get_std_for_template(post_graduation),
        fullNews=fullNews 
    )
def edit_events():
    """Render a view for editing events."""

    form = CalendarForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.calendar_dao()
    json = pfactory.calendar_dao().find_one()
    json = dict(json)
    json = dumps(json)
    index = str(form.index.data)

    if form.validate_on_submit() and form.create.data:
        initial_date = datetime.datetime.combine(form.initial_date.data, datetime.datetime.min.time())
        if form.final_date.data != "":
            final_date = datetime.datetime.strptime(form.final_date.data, '%d/%m/%Y')
            final_date = datetime.datetime.combine(final_date, datetime.datetime.min.time())
        else:
            final_date = form.final_date.data
        new_event = {
            'title': form.title.data,
            'initialDate': initial_date,
            'finalDate': final_date,
            'hour': form.hour.data,
            'link': form.link.data
        }

        dao.find_one_and_update(None, {
            '$set': {'events.' + index : new_event}
        })

        return redirect(
            url_for(
                'crud_events.edit_events',
                events=json,
                success_msg='Evento editado com sucesso.'
            )
        )

    return render_template(
        'admin/edit_events.html',
        events=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def delete_member():

    form = MemberOfProjectForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.projects_database_dao()
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    projects = dumps(projects)
    if form.validate_on_submit():
        index = str(form.index.data)
        dao.find_one_and_update({'_id' : ObjectId(form.project_id.data)}, {
            '$set': {'members.' + index + '.deleted' : '' }})
        projects = pfactory.projects_database_dao().find()
        projects = list(projects)
        projects = dumps(projects)
        return jsonify(projects=projects)
    else:
        return jsonify({'error':'Houve um erro'})
def edit_article():
    """
    Render a article editing form
    """

    form = ArticleForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    json = pfactory.publications_dao().find_one()
    json = dict(json)
    json = dumps(json)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        new_article = {
            'title': form.title.data,
            'subtitle': form.subtitle.data,
            'authors': form.authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'number': form.number.data,
            'pages': form.pages.data,
            'date': form.date.data
        }

        dao.find_one_and_update(None, {
            '$set': {'articles.' + index : new_article}
        })

        return redirect(
            url_for(
                'crud_articles.edit_article',
                success_msg='Livro editado com sucesso.'))

    return render_template(
        'admin/edit_articles.html',
        publications=json,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def edit_chapter():
    """
    Render a chapter editing form
    """

    form = ChapterForm()

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.publications_dao()
    publications = pfactory.publications_dao().find_one()
    publications = dict(publications)
    publications = dumps(publications)

    if form.validate_on_submit() and form.create.data:
        index = str(form.index.data)
        new_chapter = {
            'bookTitle': form.book_title.data,
            'bookAuthors': form.book_authors.data,
            'chapterTitle': form.chapter_title.data,
            'chapterAuthors': form.chapter_authors.data,
            'edition': form.edition.data,
            'location': form.location.data,
            'publisher': form.publisher.data,
            'pages': form.pages.data,
            'year': form.year.data
        }

        dao.find_one_and_update(None, {
            '$set': {'chapters.' + index : new_chapter}
        })

        return redirect(
            url_for(
                'crud_books.edit_chapter',
                success_msg='Capítulo editado com sucesso.'))

    return render_template(
        'admin/edit_chapters.html',
        publications=publications,
        form=form,
        success_msg=request.args.get('success_msg')
    )
def add_first_class():

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.classes_database_dao()
    now = datetime.datetime.now()
    if now.month <= 7:
        semester = 1
    else:
        semester = 2
    classes=pfactory.classes_dao(now.year,semester,100).find()
    dao.find_one_and_update(None, {
        '$set': { 'firstClasses': classes}
    })

    return redirect(
        url_for(
            'admin.index',
            success_msg='Primeiras turmas modificadas com sucesso.'
        )
    )
def view_projects(initials):
    """Render a view for projects list."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation
    projects = pfactory.projects_database_dao().find()
    projects = list(projects)
    for project in projects:
        coordinators_names = []
        for member in project['members']:
            if 'Coordenador(a)' in member['project_role']:
                coordinators_names.append(member)
                project['members'].remove(member)
        project['coordinators_names'] = coordinators_names

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/projects.html',
        std=get_std_for_template(post_graduation),
        projects=projects
    )