Beispiel #1
0
def donation_add():
    form = forms.CreateDonationForm(request.form)
    form.donation_type.choices = mysql_connector.get_types(mysql)
    if request.method == 'POST' and form.validate():
        title = form.title.data
        description = form.description.data
        city = form.city.data
        address = form.address.data
        donation_type = form.donation_type.data
        donation_date = form.donation_date.data.strftime('%y-%m-%d')
        file = request.files['file']
        if file.filename == '':
            filename = 'none.jpg'
        else:
            filename = secure_filename(file.filename)
        args = (session['account_id'], title, description, city, donation_type, donation_date, address, filename)
        offer_id = mysql_connector.add_donation(mysql, args)
        file_path = os.path.join(app.config['UPLOAD_FOLDER_DONATIONS'], str(offer_id) + '.jpg')
        if file.filename != '':
            helpers.upload_file(file, file_path)
        
        return redirect(url_for('index'))
    args = session['account_id']
    n_requests = mysql_connector.view_number_notifications(mysql,session['type'], args)
    myrequests = mysql_connector.view_notifications(mysql,session['type'], args) 
    return render_template('donation_add.html', form=form,myrequests=myrequests ,n_requests=n_requests[0][0])
Beispiel #2
0
def donation(donation_id):
    comments = mysql_connector.get_comments(mysql, donation_id)
    form = forms.PostForm(request.form)
    if request.method == 'POST' and form.validate():
        comment = form.body.data
        args = (comment, session['account_id'], donation_id)
        mysql_connector.add_comment(mysql, args)
        
    offer = mysql_connector.get_donation(mysql, donation_id)
    n_requests = mysql_connector.view_number_notifications(mysql,session['type'], args)
    myrequests = mysql_connector.view_notifications(mysql,session['type'], args)
    return render_template('donation.html',myrequests=myrequests, n_requests=n_requests[0][0], offer=offer, format_date_hour=helpers.format_date_hour, get_username=mysql_connector.get_username, mysql = mysql)
Beispiel #3
0
def index():
    if 'account_id' in session:
        args = session['account_id']
    else:
        args = 0 #dummy variable

    triplets= mysql_connector.generate_index(mysql, args)
    print(triplets)
    n_requests = mysql_connector.view_number_notifications(mysql,session['type'], args)
    myrequests = mysql_connector.view_notifications(mysql,session['type'], args)
    folder = os.path.join(app.config['UPLOAD_FOLDER_DONATIONS'])
    get_username = mysql_connector.get_username
    format_date = helpers.format_date
    return render_template("index.html", triplets=triplets, myrequests=myrequests, n_requests=n_requests[0][0], folder=folder, get_username=get_username, mysql=mysql, format_date=format_date)
Beispiel #4
0
def profile(username):
    args = session['account_id']
    n_requests = mysql_connector.view_number_notifications(mysql,session['type'], args)
    myrequests = mysql_connector.view_notifications(mysql,session['type'], args)
    n_followers = mysql_connector.get_number_followers(mysql, args)
    n_following = mysql_connector.get_number_following(mysql, args)
    user = mysql_connector.get_user(mysql, username)
    user_type = mysql_connector.get_type_user(mysql, username)
    if user_type == 1:
        triplets = mysql_connector.get_donor_donations(mysql, user[0])
    else:
        triplets = mysql_connector.get_organization_donations(mysql, user[0])
    triplets = helpers.group_list(triplets, 2)
    folder = os.path.join(app.config['UPLOAD_FOLDER_DONATIONS'])
    get_username = mysql_connector.get_username
    format_date = helpers.format_date
    return render_template("profile.html", get_username=get_username, format_date=format_date,mysql=mysql,folder=folder, user=user, triplets=triplets, myrequests=myrequests, n_requests=n_requests[0][0])
Beispiel #5
0
def myanswers():
    args = session['account_id']
    n_requests = mysql_connector.view_number_notifications(mysql,session['type'], args)
    myrequests = mysql_connector.view_notifications(mysql,session['type'], args)
    return render_template("myanswers.html", myrequests=myrequests, n_requests=n_requests[0][0])