Exemple #1
0
def update(reportID):
    conn = reports.getConn("eshumadi_db")
    reportDict = reports.buildInfoDict(conn, reportID)
    if request.method == 'GET':
        return render_template('new_report.html',
                                title='Update | ' + reportDict['name'],
                                info=reportDict)
    else: # form submitted
        reportResults = buildFormDict(request.form, request)
        
        if not reportResults: # bad selection
            return render_template('new_report.html',
                                    title='Update | ' + reportDict['name'],
                                    info=reportDict)
        
        conn = reports.getConn("eshumadi_db")
        changed = False
        for key in ['name','served','meal','hall']:
            if str(reportResults[key]) != str(reportDict[key]):
                changed = True
        unique = reports.updateReport(conn, reportResults, reportID, changed)
        if not unique: # submission failed due to duplicate entry
            flash('report already exists')
            return render_template('new_report.html', 
                                    title='Update | ' + reportDict['name'],
                                    info=reportDict)
        else:
            pathname = os.path.join(os.path.join('static',app.config['UPLOADS']),reportResults['imagefile'])
            reportResults['image'].save(pathname)
            flash('form submitted')
            return redirect(url_for('view_report', reportID=reportID))
Exemple #2
0
def view_report(reportID):
    conn = reports.getConn("eshumadi_db")
    if request.method == 'GET':
        reportDict = reports.buildInfoDict(conn, reportID)

        conn = reports.getConn("eshumadi_db")
        imagefile = reports.getImage(conn, reportID)
        if not imagefile:
            return render_template('view_report.html', 
                                    title=reportDict['name'], 
                                    info=reportDict)
        else:
            pathname = os.path.join(app.config['UPLOADS'],imagefile['imagefile'])
            return render_template('view_report.html', 
                                    title=reportDict['name'], 
                                    imagesource=pathname, 
                                    info=reportDict)
    else: # form submitted
        if 'delete' in request.form:
            err = reports.deleteReport(conn, reportID)
            if not err:
                flash("Something went wrong.")
                reportDict = reports.buildInfoDict(conn, reportID)
                return render_template('view_report.html', 
                                        title=reportDict['name'], 
                                        info=reportDict)
            else:
                os.remove(os.path.join(os.path.join('static',app.config['UPLOADS']),err))
                flash("Successfully deleted.")
                return redirect(url_for("homepage"))
        else: # update
            return redirect(url_for("update", reportID=reportID))
Exemple #3
0
def view_report(reportID):
    conn = reports.getConn("eshumadi_db")
    username = None
    if 'CAS_USERNAME' in session:
        username = session['CAS_USERNAME']

    if request.method == 'GET':
        reportDict = reports.buildInfoDict(conn, reportID)

        conn = reports.getConn("eshumadi_db")
        imagefile = reports.getImage(conn, reportID)
        if not imagefile['imagefile']:
            return render_template('view_report.html',
                                   title=reportDict['name'],
                                   info=reportDict,
                                   username=username,
                                   owner=(username == reports.getOwner(
                                       conn, reportID)))
        else:
            pathname = os.path.join(app.config['UPLOADS'],
                                    imagefile['imagefile'])
            return render_template('view_report.html',
                                   title=reportDict['name'],
                                   imagesource=pathname,
                                   info=reportDict,
                                   username=username,
                                   owner=(username == reports.getOwner(
                                       conn, reportID)))
    else:  # form submitted
        if 'delete' in request.form:
            if username:
                if username != reports.getOwner(conn, reportID):
                    flash('Permission denied.')
                    return render_template('view_report.html',
                                           title=reportDict['name'],
                                           info=reportDict,
                                           username=username,
                                           owner=(username == reports.getOwner(
                                               conn, reportID)))
            else:
                err = reports.deleteReport(conn, reportID)
                if not err:
                    flash("Something went wrong.")
                    reportDict = reports.buildInfoDict(conn, reportID)
                    return render_template('view_report.html',
                                           title=reportDict['name'],
                                           info=reportDict,
                                           username=username,
                                           owner=(username == reports.getOwner(
                                               conn, reportID)))
                else:
                    os.remove(
                        os.path.join(
                            os.path.join('static', app.config['UPLOADS']),
                            err))
                    flash("Successfully deleted.")
                    return redirect(url_for("homepage"))
        else:  # update
            return redirect(url_for("update", reportID=reportID))
Exemple #4
0
def listSome(startDate, numReports):
    '''Returns a dictionary of lists with a total of numReports existing reports 
    from most recent to least recent relative to startDate
    and the next start date if there are reports remaining.'''
    conn = reports.getConn("eshumadi_db")
    results = reports.listReports(conn, startDate, numReports + 1)

    nextDate = None
    if len(results) <= numReports:
        dates = set([report['served'] for report in results])
        dateDict = {
            datetime.datetime.strftime(date, '%Y-%m-%d'): []
            for date in dates
        }
        for report in results:
            dateDict[datetime.datetime.strftime(report['served'],
                                                '%Y-%m-%d')].append(report)
    else:
        dates = set([report['served'] for report in results[:-1]])
        if results[-1][
                'served'] in dates:  # we don't want to display partial results for any dates
            dates = dates.difference([results[-1]['served']])
        dateDict = {
            datetime.datetime.strftime(date, '%Y-%m-%d'): []
            for date in dates
        }
        nextDate = (min(dates) - datetime.timedelta(days=1))
        for report in results[:-1]:
            date = datetime.datetime.strftime(report['served'], '%Y-%m-%d')
            if date in dateDict:
                dateDict[date].append(report)
    return (dateDict, nextDate)
Exemple #5
0
def image(reportID):
    conn = reports.getConn("eshumadi_db")
    imagefile = reports.getImage(conn, reportID)
    if not imagefile:
        flash('no file found')
        return redirect(url_for(homepage))
    else:
        return send_from_directory(os.path.join('static',app.config['UPLOADS']),imagefile['imagefile'])
Exemple #6
0
def search():
    conn = reports.getConn("eshumadi_db")
    results = reports.searchReports(conn, request.args.get('query'), request.args.get('hall'))
    return render_template('search.html', title="Search", 
                                          query=request.args.get('query'), 
                                          hall=request.args.get('hall'), 
                                          numResults=len(results), 
                                          results=results)
Exemple #7
0
def search():
    conn = reports.getConn("eshumadi_db")
    results = reports.searchReports(conn, request.args.get('query'),
                                    request.args.get('hall'))
    username = None
    if 'CAS_USERNAME' in session:
        username = session['CAS_USERNAME']

    return render_template('search.html',
                           title="Search",
                           query=request.args.get('query'),
                           hall=request.args.get('hall'),
                           numResults=len(results),
                           results=results,
                           username=username)
Exemple #8
0
def new_report():
    if request.method == 'GET':
        return render_template('new_report.html', title='Make a Report')
    elif request.method == 'POST':
        # build dictionary
        reportResults = buildFormDict(request.form, request)
        if not reportResults: # bad selection
            return render_template('new_report.html', title='Make a Report')

        # insert and redirect
        conn = reports.getConn("eshumadi_db")
        reportID = reports.insertReport(conn, reportResults)
        if reportID == -1: # submission failed due to duplicate entry
            flash('report already exists')
            return render_template('new_report.html', title='Make a Report')
        else:
            pathname = os.path.join(os.path.join('static',app.config['UPLOADS']),reportResults['imagefile'])
            reportResults['image'].save(pathname)
            flash('form submitted')
            return redirect(url_for('view_report', reportID=reportID))
    else:
        return render_template('new_report.html', title='Make a Report')