Beispiel #1
0
def edit(event_id):
    event = Event.query.filter_by(event_id=event_id).first_or_404()
    user = User.query.filter_by(id=event.user_id, username=session['username']).first_or_404() # only access their own events

    form = SellForm(obj=event)
    f_name = ""
    extension = ""
    app.config['UPLOAD_FOLDER'] = os.getcwd() + '/static/images/'
    if form.validate_on_submit():
        original_image = event.imgpath
        form.populate_obj(event)
        # Handle event image uploads
        if form.imgpath.has_file():
            f = request.files.get('imgpath')
            try:
                extension = os.path.splitext(f.filename)[1]
                f_name = str(uuid.uuid4()) + extension #encoding the image name + adding extension like jpg, png etc.
                f_path = os.path.join(app.config['UPLOAD_FOLDER'], f_name)
                f.save(f_path) #saving the image to static/images
                event.imgpath = '/static/images/' + f_name
            except:
                flash("The image was not uploaded")
                event.imgpath = original_image # "static/images/"+f_name
        else:
            event.imgpath = original_image
        # Commit changes to event and return to homepage
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('event/edit.html', form=form, event=event, action="edit")
Beispiel #2
0
def edit(event_id):
  event = Event.query.filter_by(event_id=event_id).first_or_404()
  form = SellForm(obj=event)
  if form.validate_on_submit():
    form.populate_obj(event)
    #Update form information to database
    if request.method == 'POST':
        event.name = request.form['name']
        event.
    """
    
    def editpost(id):
    post = db.session.query(Post).filter(Post.id==id).first()

    if request.method == 'POST':
        title = request.form['title']
        text = request.form['content']

        post.title = title
        post.body = content

        db.session.commit()

        return redirect(url_for('post', id=id))
    else:
        return render_template('something.html', post=post)
    """
    db.session.commit()
    return redirect(url_for('index'))
  return render_template('event/edit.html',form=form, event=event, action='edit')
Beispiel #3
0
def sell():
  form = SellForm() 
  if form.validate_on_submit():
    #Save image to static/images
    app.config['UPLOAD_FOLDER'] = 'static/images'
    file = request.files.get('imgpath')
    extension = os.path.splitext(file.filename)[1]
    f_name = str(uuid.uuid4()) + extension #encoding the image name + adding extension like jpg, png etc.
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], f_name)) #saving the image to static/images
    event = Event(
        form.name.data,
        form.genre.data,
        form.venue.data,
        form.location.data,
        form.date.data,
        form.starttime.data,
        form.endtime.data,
        "static/images/"+f_name,
        User.query.filter_by(username=session['username']).first(),
        form.price.data,
        form.quantity.data)
   
    db.session.add(event)
    db.session.commit()
    return redirect(url_for('index'))
  return render_template('event/sell.html',form=form)
def confirmation():
    form = SellForm(obj=p)
    # if not isinstance(request.args['event_id'], int):
    #     return "Invalid event id '{}' is not a number!".format(request.args['event_id'])
    user = User.query.filter_by(username=session['username']).first().__dict__
    event = Event.query.filter_by(event_id=request.args.get('event_id')).first()
    
    name = user['fullname'].split(' ')
    user.update(dict(
        firstname=name[0],
        lastname=name[1],
        address=parseaddr(user['address']),
    ))
    
    commission = round(Decimal(event.price * Decimal(0.05)), 2)
    shipping = round(Decimal(5.00), 2)
    total = round(event.price + commission + shipping, 2)
    pricing = dict(
        commission=commission,
        shipping=shipping,
        total=total,
    )

    return render_template('user/confirmation.html', user=user, pricing=pricing, event=event)
Beispiel #5
0
def sell():
    form = SellForm()
    error = None
    if form.validate_on_submit():
        #Save image to static/images
        app.config['UPLOAD_FOLDER'] = 'static/images'
        file = request.files.get('imgpath')
        # image uploaded
        if file.__bool__():
            print("uploaded file")
            extension = os.path.splitext(file.filename)[1]
            f_name = str(uuid.uuid4()) + extension  #encoding the image name + adding extension like jpg, png etc.
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], f_name))  #saving the image to static/images
        # No image
        else:
            print("use placeholder")
            error = "Upload an image for the event"
            f_name = "Background.png"
        date = form.date.data
        try: 
                valid_date = time.strptime(date, '%m/%d/%Y')
        except:
            error = "Invalid date, please try again"
            return render_template('event/sell.html', form=form, error=error)
        
        try: 
            am_pm_1 = ""
            am_pm_2 = ""
            start_time = ""
            end_time = ""
            
            am_pm_1 = form.starttime.data[-2:].upper() 
            am_pm_2 = form.starttime.data[-2:].upper()
            start_time = form.starttime.data[:-2]
            end_time = form.endtime.data[:-2]
            valid_start_time = start_time + " " + am_pm_1
            valid_end_time = end_time + " " + am_pm_2
            print (valid_start_time)
            print (valid_end_time)
            time.strptime(valid_start_time, "%I:%M %p")
            time.strptime(valid_end_time, "%I:%M %p")
        except:
            error = "Invalid times, please try again"
            return render_template('event/sell.html', form=form, error=error)
            
        if not isinstance(form.quantity.data, int):
            error = "Invalid input under quantity, please try again"
            return render_template('event/sell.html', form=form, error=error)
        event = Event(
            form.name.data,
            form.genre.data,
            form.venue.data,
            form.location.data,
            form.date.data,
            form.starttime.data,
            form.endtime.data,
            "static/images/" + f_name,
            User.query.filter_by(username=session['username']).first(),
            form.price.data,
            form.quantity.data
        )
        db.session.add(event)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('event/sell.html', form=form, error=error)