Example #1
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)
Example #2
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)
Example #3
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)
Example #4
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')
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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')
Example #11
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')
Example #12
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)