Exemplo n.º 1
0
def report_event_post():
    form = ReportForm(CombinedMultiDict((request.files, request.form)))

    if form.validate():
        image_extension = form.image.data.filename.split('.')[-1] if form.image.data else None

        ev = Event(
            timestamp=str(form.timestamp.data),
            latitude=form.latitude.data,
            longitude=form.longitude.data,
            alert_code=AlertCode.from_name(form.type.data),
            description=form.description.data,
            image_extension=image_extension
        )

        MongoDatabase.insert_event(ev)
        if ev.has_image():
            MongoDatabase.insert_photo(ev.get_image_name(), form.image.data)

        msg = EvrMail.create_new_event_message(Config.ADMIN_EMAILS, ev)
        EvrMail.send_message(msg)

        flash('Event reported')
        return redirect(url_for('event.show_events'))
    return render_template('event/report.html', form=form)
Exemplo n.º 2
0
def report():
    form = ReportForm()
    if form.validate_on_submit():
        session["startdate"] = form.startdate.data
        session["enddate"] = form.enddate.data
        return redirect(url_for("expense"))
    return render_template("report.html", form=form)
Exemplo n.º 3
0
def report(cert_id):
    """
    Return template for report page
    """
    cert = Cert.query.get(cert_id)
    if cert.file_id is None:
        urls = [url_for('static', filename=os.path.join('img', "missing.png"))]
    else:
        if not cert.file.converted:
            cert.file.convert()
        urls = cert.file.pngs

    form = ReportForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            form_completed = False
            for key, value in form.data.items():
                if value != "" and key is not 'csrf_token' and key is not 'submit':
                    form_completed = True
            if not form_completed:
                flash("Please complete at least one form field.",
                      category="warning")
                return render_template('report_issue.html',
                                       form=form,
                                       cert=cert,
                                       urls=urls)
            else:
                form_fields = {
                    name: data
                    for name, data in {
                        'county': form.county.data,
                        'month': form.month.data,
                        'day': form.day.data,
                        'year': form.year.data,
                        'age': form.age.data,
                        'number': form.number.data,
                        'soundex': form.soundex.data,
                        'first_name': form.first_name.data,
                        'last_name': form.last_name.data,
                        'comments': form.comments.data
                    }.items() if data
                }
                report = Report(cert_id=cert_id,
                                user_id=current_user.id,
                                values=form_fields)
                db.session.add(report)
                db.session.commit()
                flash("Your report has been submitted.", category="success")
                return redirect('/')
        else:
            flash("An error has occurred.")
            print(form.errors)
    return render_template('report_issue.html',
                           form=form,
                           cert=cert,
                           urls=urls)
Exemplo n.º 4
0
def report_article():
    form = ReportForm()
    if request.method == 'POST':
        if form.validate() == False:
            return 'Vul alstublieft alle velden in <p><a href="/contact">Probeer het opnieuw!!! </a></p>'
        else:
            mail.send(msg)
            return redirect(url_for('count_logins'))
    elif request.method == 'GET':
        url = request.args.to_dict()['article']
        form.lead.data = "Probleem met artikel " + url
        return render_template('report_article.html', form=form, url=url)
Exemplo n.º 5
0
def report(user_id):
    user = User.query.get(user_id)
    form = ReportForm()
    if form.validate_on_submit():
        report = Report(title = form.title.data, username = current_user.username, body = form.body.data)
        db.session.add(report)
        db.session.commit()
        report.add_report(user, current_user)
        db.session.commit()
        flash('Your report has been recorded.')
        return redirect('/clear_search')
    return render_template('report.html', title='Report User', form=form)
Exemplo n.º 6
0
 def create(data, ascii_url_code) -> JsonResponse:
     """
     Create "Report"
     :param data: data for the ReportForm.
     :param ascii_url_code: url code for "GeneratedASCII" object, passed from url.
     :return: Fully built JsonResponse with errors if occurred.
     """
     form = ReportForm(data)
     try:
         generated_ascii = GeneratedASCII.objects.get(url_code=ascii_url_code)
     except GeneratedASCII.DoesNotExist:
         return JsonResponse({'errors': {'captcha': [_("Can't find object to report.")]}}, status=400)
     if form.is_valid():
         Report.objects.create(text=form.cleaned_data['text'],
                               email=form.cleaned_data['email'],
                               generated_ascii=generated_ascii)
         return JsonResponse({}, status=200)
     return JsonResponse({'errors': form.errors}, status=400)
Exemplo n.º 7
0
def general_report():
    form0 = SearchProfileForm()
    form = ReportForm()
    if form.validate_on_submit():
        prev_url = request.args.get('prev')
        if url_parse(prev_url).netloc != '':
            return redirect(url_for('index'))
        report = Report(reason=form.reason.data,
                        page_of_report=prev_url,
                        author=current_user)
        db.session.add(report)
        db.session.commit()
        flash('Your report has been submitted. Thank you for your feedback!')
        return redirect(prev_url)
    return render_template('general_report.html',
                           form=form,
                           form0=form0,
                           title='Report')
Exemplo n.º 8
0
def report_for_month():
    form = ReportForm()
    if form.validate_on_submit():
        orders, global_sum = controllers.count_month(form.year.data,
                                                     form.month.data)
        return render_template('report_for_month.html',
                               year=form.year.data,
                               month=controllers.find_month(form.month.data),
                               orders=orders,
                               global_sum=global_sum,
                               form=form)
    else:
        return render_template('report_for_month.html',
                               year=0,
                               month=0,
                               orders=[],
                               global_sum=0,
                               form=form)
Exemplo n.º 9
0
def createReport(request):
    if request.method == 'POST':
        create_form = ReportForm(request.POST)
        if create_form.is_valid():  # Se va todo bien
            create_form.save()
            return redirect('index')  # redigirir a la página principal
    else:
        create_form = ReportForm()
    return render(request, 'create_form.html', {'create_form': create_form})
Exemplo n.º 10
0
def reports():
    form = ReportForm()
    export = ExportForm()
    if form.validate_on_submit():
        # Make global so we can export these results to CSV
        global report
        report = db_functions.read_from_database(form)
        for rp in report:
            # Convert from 24 hr time (stored in db) to 12 hr time for display
            twenty_four_hr_time = datetime.datetime.strptime(rp.time, "%H:%M")
            # strip leading zeroes from hour for presentation purposes
            rp.time = twenty_four_hr_time.strftime("%I:%M %p").lstrip(
                "0").replace(" 0", "")
        return render_template('reports.html',
                               title="Reports",
                               form=form,
                               report=report,
                               total=len(report),
                               export=export)
    return render_template('reports.html', title="Reports", form=form)
Exemplo n.º 11
0
def editReport(request, id):
    report = MonitoringReports.objects.get(id=id)
    if request.method == 'GET':
        edit_form = ReportForm(instance=report)
    else:
        edit_form = ReportForm(request.POST, instance=report)
        if edit_form.is_valid():
            edit_form.save()
        return redirect('index')  # redigirir a la página principal
    return render(request, 'create_form.html', {'edit_form': report})
Exemplo n.º 12
0
def publish(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = ReportForm(request.POST, request.FILES)
        # check whether it's valid:
        if form.is_valid():
            if form.cleaned_data['latitude'] and form.cleaned_data['longitude']:
                instance = form.save(commit=False)
                instance.save()
                report_id = str(instance.id)
                request.session['pp_publish'] = True
                request.session['pp_tweet'] = True
                # redirect to another view where is the report id
                return redirect('success', report_id=report_id)
            else:
                messages.error(request, "Es necesario una ubicación, por favor marque un punto en el mapa")
        else:
            messages.error(request, "Por favor verifique los datos del formulario")
    else:
        form = ReportForm()

    context = {'form': form}

    return render(request, 'publicar.html', context)
Exemplo n.º 13
0
def report():
    if Configuration.query.count() == 0:
        #TODO return 404 somehow
        pass

    form = ReportForm()
    form.config_id.choices =[(c.id, c.config_name) for c in Configuration.\
                     query.with_entities(Configuration.id,
                        Configuration.config_name).all()]
    if form.validate_on_submit():
        report = Report(report_name=form.report_name.data,
                        config_id=form.config_id.data,
                        hour=form.hour.data,
                        day=form.day.data,
                        minute=form.minute.data,
                        query_text=form.query_text.data)
        db.session.add(report)
        db.session.commit()
        # keep this redirect here for a bit till I figure out what to do
        # with it
        return redirect(url_for('index'))
    return render_template('report.html', form=form)
Exemplo n.º 14
0
def specific_report(id):
    form = ReportForm()
    if form.validate_on_submit():
        prev_url = request.args.get('prev')
        report_type = request.args.get('type')
        if url_parse(prev_url).netloc != '':
            return redirect('index')
        if report_type.find('post') != -1:
            report = Report(reason=form.reason.data,
                            author=current_user,
                            post_id=id)
        elif report_type.find('comment') != -1:
            report = Report(reason=form.reason.data,
                            author=current_user,
                            comment_id=id)
        else:
            report = Report(reason=form.reason.data,
                            author=current_user,
                            profile_id=id)
        db.session.add(report)
        db.session.commit()
        flash('Your report has been submitted. Thank you for your feedback!')
        return redirect(prev_url)
    return render_template('specific_report.html', title='Report', form=form)
Exemplo n.º 15
0
def submit_report():
    """
    Create and submit report
    """
    form = ReportForm()
    form.main_teacher.choices = Teacher.get_teachers_for_choices()
    form.assistant_teacher.choices = Teacher.get_teachers_for_choices()
    form.submitted_by.choices = Teacher.get_teachers_for_choices()

    if form.validate_on_submit():
        report = Report(main_teacher_id=form.main_teacher.data,
                        assistant_teacher_id=form.assistant_teacher.data,
                        teaching_date=form.teaching_date.data,
                        teaching_content=form.teaching_content.data,
                        student_attendance=form.student_attendance.data,
                        submitted_by_id=form.submitted_by.data)
        db.session.add(report)
        db.session.commit()
        flash(message='Report is successfully submitted.', category='success')
        return redirect(url_for('index'))

    return render_template('report_submit.html',
                           title='Submit a Report',
                           form=form)
Exemplo n.º 16
0
def report_view(request):
    user_instance = request.user

    if request.method == "POST":
        report = user_instance.report_set.first()
        form = ReportForm(request.POST, instance=report)

        if form.is_valid():
            report = form.save(commit=False)
            report.user = user_instance
            report.save()
            messages.success(request, "Информация о работе сохранена.")
    else:
        form = ReportForm(instance=user_instance.report_set.first())

    return render(request, "report.html", {"form": form})
Exemplo n.º 17
0
def report():
    if not session['logged_in']:
        return redirect(url_for('index'))
    form = ReportForm()
    if request.method == "POST":
        # alpha = request.form['by_cat']
        # alpha = request.form['startdate']
        # beta = request.form['enddate']
        #
        is_checked = request.form.get('by_cat')
        single_cat_id = request.form.get('single_cat_id')
        if is_checked:
            # return render_template('404.html')
            cat_list = Report.expenses_by_cat(request.form['startdate'], request.form['enddate'])
            return render_template('report_cats.html', cats=cat_list, header_text="Category totals")

        elif single_cat_id:
            single_list = Report.expenses_single_cat(request.form['startdate'], request.form['enddate'], single_cat_id)
            # return render_template('report_cats.html', cats=cat_list, header_text="Category totals")
            return render_template('expenses.html', expense_list=single_list,
                                   header_text="Expenses for cat {}".format(single_cat_id))

        else:
            expense_list = Report.expense_report(request.form['startdate'], request.form['enddate'])
            #
            # r = Report(
            #         request.form['startdate'],
            #         request.form['enddate'],
            #         request.form['by_cat']
            #         )
            # cats = [{"cat":"alpha", "total":"111.11"}, {"cat":"beta", "total":"222.2"}]
            # cats = r.exp_report_by_cat()

            return render_template('report_results.html', expense_list=expense_list, bankitems=bankitems,
                                   header_text="Expenses")
    return render_template('report.html', form=form, header_text="Reports")
Exemplo n.º 18
0
 def get_form() -> ReportForm:
     return ReportForm()
Exemplo n.º 19
0
def report_generate():

    form = ReportForm()
    date_list = []
    result = []
    row_count = 0
    end_date = form.enddate.data
    begin_date = form.begindate.data
    query = ''

    for i in range(0, (end_date - begin_date).days + 1):
        date_list.append((begin_date + timedelta(days=i)).strftime('%m-%d'))

        if i == (end_date - begin_date).days:
            query += 'SUM(sr.score) FILTER (where date=\'{0}\') as \"{0}\" '.format(
                begin_date + timedelta(days=i))
        else:
            query += 'SUM(sr.score) FILTER (where date=\'{0}\') as \"{0}\",'.format(
                begin_date + timedelta(days=i))
    query = (
        'select sur.name as sport, sum(sr.score), sr.parameter_1, ' + (query) +
        'from surveyresult as sr join users as u on sr.id_users=u.id join surveys as sur on sr.id_surveys=sur.id '
        + 'where sr.date >=\'{}\' and  sr.date <= \'{}\' and u.id={} '.format(
            begin_date, end_date, current_user.id) +
        'group by (sport, sr.parameter_1) order by 2 desc;')

    colscount = len(date_list) + 2

    result = db.engine.execute(query)

    if form.validate_on_submit():

        end_date = form.enddate.data
        begin_date = form.begindate.data
        query = ''
        date_list = []
        for i in range(0, (end_date - begin_date).days + 1):
            date_list.append(
                (begin_date + timedelta(days=i)).strftime('%m-%d'))

            if i == (end_date - begin_date).days:
                query += 'SUM(sr.score) FILTER (where date=\'{0}\') as \"{0}\" '.format(
                    begin_date + timedelta(days=i))
            else:
                query += 'SUM(sr.score) FILTER (where date=\'{0}\') as \"{0}\",'.format(
                    begin_date + timedelta(days=i))
        query = (
            'select sur.name as sport, sum(sr.score), sr.parameter_1, ' +
            (query) +
            'from surveyresult as sr join users as u on sr.id_users=u.id join surveys as sur on sr.id_surveys=sur.id  '
            + 'where sr.date >=\'{}\' and  sr.date <= \'{}\' and u.id={}  '.
            format(begin_date, end_date, current_user.id) +
            'group by (sport, sr.parameter_1) order by 2 desc;')

        result = db.engine.execute(query)
        row_count = result.rowcount
        colscount = len(date_list) + 2

        return render_template('report.html',
                               title='Report',
                               form=form,
                               result=result,
                               date_list=date_list,
                               rows=row_count,
                               cols=colscount)

    return render_template('report.html',
                           title='Report',
                           form=form,
                           result=result,
                           date_list=date_list,
                           rows=row_count,
                           cols=colscount)
Exemplo n.º 20
0
def reportPrint():
    form = ReportForm()
    return render_template('reportPrint.html', form=form)
Exemplo n.º 21
0
def add_report():
    add_report = True
    form = ReportForm()
    if form.validate_on_submit():
        report = Report(
            title=form.title.data,
            #CEP
            education=form.education.data,
            pss=form.pss.data,
            livelihood=form.livelihood.data,
            spiritual=form.spiritual.data,
            numhomevisit=form.numhomevisit.data,
            homevisit=form.homevisit.data,
            donorbond=form.donorbond.data,
            lifeskill=form.lifeskill.data,
            #BS
            numschool=form.numschool.data,
            numstud=form.numstud.data,
            student=form.student.data,
            numchurch=form.numchurch.data,
            church=form.church.data,

            #Community Development
            igas=form.igas.data,
            numloanstaken=form.numloanstaken.data,
            numloansback=form.numloansback.data,
            notesonloans=form.notesonloans.data,

            #PWDs
            trainings=form.trainings.data,
            newentrants=form.newentrants.data,
            salestracking=form.salestracking.data,

            #CD, PWDs
            saving=form.saving.data,
            dbspartnership=form.dbspartnership.data,

            #DBs
            numdbs=form.numdbs.data,
            numnewdbs=form.numnewdbs.data,
            newdbs=form.newdbs.data,
            attendance=form.attendance.data,
            schministries=form.schministries.data,
            otherministries=form.otherministries.data,

            #BS, CD, PWDs, DBs
            numfollowup=form.numfollowup.data,
            notesfollowup=form.notesfollowup.data,

            #orphanage
            security=form.security.data,
            childdiet=form.childdiet.data,
            childsanitation=form.childsanitation.data,
            childhealth=form.childhealth.data,
            #RM
            activities=form.activities.data,
            policies=form.policies.data,
            implementation=form.implementation.data,

            #Social Work
            numchild=form.numchild.data,
            childphysicalhealth=form.childphysicalhealth.data,
            resettlement=form.resettlement.data,
            legalsupport=form.legalsupport.data,
            fostercare=form.fostercare.data,

            #general fields
            achieved=form.achieved.data,
            challenge=form.challenge.data,
            othernote=form.othernote.data,
            department_id=current_user.department_id,
            user_id=current_user.id)
        db.session.add(report)
        db.session.commit()
        flash('Your report has succesfully been sent.', 'success')

        return redirect(url_for('list_reports'))

    return render_template('report.html',
                           form=form,
                           action="Add",
                           add_report=add_report,
                           title='Write Report')
Exemplo n.º 22
0
def edit_report(id):
    add_report = False
    report = Report.query.get_or_404(id)
    form = ReportForm(obj=report)
    if form.validate_on_submit():
        report.title = form.title.data
        #CEP
        report.education = form.education.data
        report.pss = form.pss.data
        report.livelihood = form.livelihood.data
        report.spiritual = form.spiritual.data
        report.numhomevisit = form.numhomevisit.data
        report.homevisit = form.homevisit.data
        report.donorbond = form.donorbond.data
        report.lifeskill = form.lifeskill.data
        #BS
        report.numschool = form.numschool.data
        report.numstud = form.numstud.data
        report.student = form.student.data
        report.numchurch = form.numchurch.data
        report.church = form.church.data
        #Community Development
        report.igas = form.igas.data
        report.numloanstaken = form.numloanstaken.data
        report.numloansback = form.numloansback.data
        report.notesonloans = form.notesonloans.data
        #PWDs
        report.trainings = form.trainings.data
        report.newentrants = form.newentrants.data
        report.salestracking = form.salestracking.data
        #CD, PWDs
        report.saving = form.saving.data
        report.dbspartnership = form.dbspartnership.data
        #DBs
        report.numdbs = form.numdbs.data
        report.numnewdbs = form.numnewdbs.data
        report.newdbs = form.newdbs.data
        report.attendance = form.attendance.data
        report.schministries = form.schministries.data
        report.otherministries = form.otherministries.data
        #BS, CD, PWDs, DBs
        report.numfollowup = form.numfollowup.data
        report.notesfollowup = form.notesfollowup.data
        #orphanage
        report.security = form.security.data
        report.childdiet = form.childdiet.data
        report.childsanitation = form.childsanitation.data
        report.childhealth = form.childhealth.data
        #RM
        report.activities = form.activities.data
        report.policies = form.policies.data
        report.implementation = form.implementation.data
        #Social Work
        report.numchild = form.numchild.data,
        report.childphysicalhealth = form.childphysicalhealth.data
        report.resettlement = form.resettlement.data
        report.legalsupport = form.legalsupport.data
        report.fostercare = form.fostercare.data
        #general fields
        report.achieved = form.achieved.data
        report.challenge = form.challenge.data
        report.othernote = form.othernote.data
        db.session.add(report)
        db.session.commit()
        flash('You have successfully edited the report', 'success')

        return redirect(url_for('list_reports'))

    form.title.data = report.title
    #CEP
    form.education.data = report.education
    form.pss.data = report.pss
    form.livelihood.data = report.livelihood
    form.spiritual.data = report.spiritual
    form.numhomevisit.data = report.numhomevisit
    form.homevisit.data = report.homevisit
    form.donorbond.data = report.donorbond
    form.lifeskill.data = report.lifeskill
    #BS
    form.numschool.data = report.numschool
    form.numstud.data = report.numstud
    report.student = form.student.data

    return render_template('admin/report.html',
                           add_report=add_report,
                           form=form,
                           title='Edit Report')
Exemplo n.º 23
0
def report_event():
    form = ReportForm()
    return render_template('event/report.html', form=form)