コード例 #1
0
def add_employee_xrequest():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    # add employee request to database
    # declare the Request Form
    form = RequestForm(request.form)
    form.stock_item.choices = [(x.id, x) for x in Stock.query.all()]
    msg = None
    # check if both http method is POST and form is valid on submit
    if form.validate_on_submit():
        # assign form data to variables
        stock_item = request.form.get('stock_item', '', type=int)
        quantity = request.form.get('quantity', '', type=int)
        # see if request already exists
        # TODO: filter by datecreated as well
        # request = Request.query.filter_by(user_id=current_user.id, product_id=stock_item, quantity = quantity).first()
        xrequest = Request(current_user.id, stock_item, 1, quantity, 1)
        # check if request is in bounds
        stock = Stock.query.filter_by(id=stock_item).first()
        if quantity <= stock.stocklevel:
            xrequest.save()
            flash('Request successfully created!')
        else:
            flash(
                f'I am sorry but we have only {stock.quantity} {stock} available'
            )
    else:
        flash('I am sorry but the details you entered cannot be saved :(')
    return redirect('/psalm2vs8/employee-requests')
コード例 #2
0
ファイル: routes.py プロジェクト: milkgoblin/feature-requests
def index():
    form = RequestForm()
    requests = Request.query.order_by(Request.client_priority).all()
    sameClientRequestsA = Request.query.filter_by(client=form.client.data).order_by(Request.client_priority).all()
    sameClientRequestsD = Request.query.filter_by(client=form.client.data).order_by(Request.client_priority.desc()).all()

    if form.validate_on_submit():
        request = Request(title=form.title.data, description=form.description.data, client=form.client.data, 
            client_priority=form.client_priority.data, product_area=form.product_area.data, target_date=form.target_date.data, reporter=current_user)

        # Check through all priority numbers for the given client looking for a duplicate value
        duplicate = "no"
        for check in sameClientRequestsA:
            if check.client_priority == form.client_priority.data:
                duplicate = "yes"

        # If a duplicate was found, move through the exisitng list of requests and increase priority of all items by one to reorder list
        if duplicate == "yes":
            for item in sameClientRequestsD:
                if item.client_priority >= form.client_priority.data:
                    item.client_priority = item.client_priority +1
                    db.session.add(item)
                    db.session.commit()                

        db.session.add(request)
        db.session.commit()
        flash('Your request has been posted!')
        return redirect(url_for('index'))
    return render_template("index.html", title='Home Page', form=form, requests=requests)
コード例 #3
0
def request_goods():
    form = RequestForm()
    formDict = {}
    if (form.validate_on_submit()):
        formDict['product1'] = form.product1.data
        formDict['quantity1'] = form.quantity1.data
        formDict['product2'] = form.product2.data
        formDict['quantity2'] = form.quantity2.data
        url = 'http://' + userdata[form.To.data]['host'] + ':' + str(
            userdata[form.To.data]['port']) + '/update'
        request_hash = hash(formDict)
        #update requested_hash for the current user
        userdata[session['username']]['requested_hash'].append(request_hash)
        from_to_hash = concat(form.To.data, session['username'])
        hashr = post(url=validater_data + '/Manu/Request',
                     data={
                         'supplier_manu': from_to_hash,
                         'requested_hash': request_hash
                     })
        formDict['Type'] = 'goods_request'
        formDict['From'] = session['username']
        formDict['To'] = form.To.data
        r = post(url=url, data=formDict)
        if (r.status_code == 200):
            return 'Goods Request Sent'
        else:
            return 'Error in Sending'
    return render_template('request.html', title='Request', form=form)
コード例 #4
0
def request_form():
    form = RequestForm()
    form.origin_city.choices = app.config['CITIES']
    form.origin.choices = app.config['LOCATIONS']
    form.destination_city.choices = app.config['CITIES']
    form.destination.choices = app.config['LOCATIONS']

    if form.validate_on_submit():
        request = Request(origin_city=form.origin_city.data,
                          origin=form.origin.data,
                          destination_city=form.destination_city.data,
                          destination=form.destination.data,
                          date=form.date.data,
                          time=form.time.data,
                          author=current_user,
                          description=form.description.data)

        if form.destination.data == form.origin.data:
            flash("Origin and Destination cannot be the same")
        else:
            db.session.add(request)
            db.session.commit()
            flash('Your request has been posted!')
            # return redirect(url_for('index'))
    return render_template('requestForm.html', title='Request', form=form)
コード例 #5
0
def edit_request(request_id):
    old_request = Request.query.filter_by(id=request_id).first()
    form = RequestForm(origin_city=old_request.origin_city,
                       origin=old_request.origin,
                       destination_city=old_request.destination_city,
                       destination=old_request.destination,
                       date=old_request.date,
                       time=old_request.time,
                       description=old_request.description)
    form.origin_city.choices = app.config['CITIES']
    form.origin.choices = app.config['LOCATIONS']
    form.destination_city.choices = app.config['CITIES']
    form.destination.choices = app.config['LOCATIONS']

    if form.validate_on_submit():
        request = old_request
        request.origin_city = form.origin_city.data
        request.origin = form.origin.data
        request.destination_city = form.destination_city.data
        request.destination = form.destination.data
        request.date = form.date.data
        request.time = form.time.data
        request.description = form.description.data

        if form.destination.data == form.origin.data:
            flash("Origin and Destination cannot be the same")
        else:
            db.session.add(request)
            db.session.commit()
            flash('Your request has been edited!')
            return redirect(url_for('user', username=current_user.username))
    return render_template('requestForm.html', title='Request', form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: hamzah-shahrin/offline
def index_d():
    global dark
    dark = True

    form = RequestForm()
    if form.validate_on_submit():
        data = request.form['url']
        if data is None:
            flash("No URL entered")
        return redirect('/download/' + data)
    return render_template("index.html", title="Offline", form=form, dark=True)
コード例 #7
0
ファイル: routes.py プロジェクト: drzelin/barista_match
def request():
    form = RequestForm()
    if form.validate_on_submit():
        flash('Barista requested for {}'.format(
            form.cafe_name.data))
        print(form.owner_name.data)
        print(form.cafe_name.data)
        print(form.email.data)
        print(form.phone.data)
        return redirect('/')
    return render_template('barista_request.html', title='Submit Request', form=form)
コード例 #8
0
def accept_request(id):
    form = RequestForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        request = Request(user_id=current_user.id,
                          party_id=party_id,
                          message=form.data["message"])
        db.session.add(request)
        db.session.commit()
        return {"request": {request.id: request.to_dict()}}
    else:
        return "Bad Data"
コード例 #9
0
def add_request(username):
    form = RequestForm()
    if form.validate_on_submit():
        feature = Feature(title=form.title.data,
                          description=form.description.data,
                          product_area=form.product_area.data,
                          clients=form.clients.data,
                          priority=form.priority.data,
                          target_date=form.target_date.data,
                          requestor=current_user)
        db.session.add(feature)
        db.session.commit()
        flash('Your feature request has been recorded.')
        return redirect(url_for('display_requests', user_id=current_user.id))
    return render_template('add_request.html', user=user, form=form)
コード例 #10
0
def request_page():
    form = RequestForm()
    if form.validate_on_submit() and request.method == 'POST':
        demo = DemoRequest(name=request.form['name'],
                           email=request.form['email'],
                           demo=request.form['demo'],
                           date_request=request.form['date_request'],
                           comments=request.form.get('comments'))
        db.session.add(demo)
        db.session.commit()
        flash(
            'Your demo request was successfully submitted. You should receive an email confirmation shortly. If you do not, please contact the demoroom at [email protected]'
        )
    return render_template('request_page.html',
                           title='Request Page',
                           form=form)
コード例 #11
0
def request_results():
    if request.method == 'POST':
        logging.info('posted')
        req = request.form
        try:
            results = get_results(req.get('results_url'))
            logging.info(f"results: {results}")
            return render_template('results.html', title='Results', results=results)
        except:
            logging.exception('exception')
            pass
    else:
        form = RequestForm()
        if form.validate_on_submit():
            flash('Url={}, States={}'.format(
                form.results_url.data, form.state_list.data))
            return redirect('/index')
        return render_template('request.html', title='Get Results', form=form)
コード例 #12
0
def receive_goods():
    form = RequestForm()
    formDict = {}
    if (form.validate_on_submit()):
        formDict['product1'] = form.product1.data
        formDict['quantity1'] = form.quantity1.data
        formDict['product2'] = form.product2.data
        formDict['quantity2'] = form.quantity2.data
        received_hash = hash(formDict)
        supplier_manu = concat(form.To.data, session['username'])
        #update sent_hash for the current user
        userdata[session['username']]['received_hash'].append(received_hash)
        hashr = post(url=validater_data + '/Manu/Received',
                     data={
                         'supplier_manu': supplier_manu,
                         'received_hash': received_hash
                     })
        return 'Goods Recieved. Try sending payment to see if goods received are authentic.'
    return render_template('request.html', title='Receive', form=form)
コード例 #13
0
ファイル: request.py プロジェクト: Sea94/cover
def post_help_request():

    form = RequestForm()
    if form.validate_on_submit():
        address = form.address.data
        location = get_location(address)
        Request.add({
            "name": form.name.data,
            "phone": form.phone.data,
            "address": address,
            "latitude": location["lat"],
            "longitude": location["lng"],
            "category": form.category.data,
            "request": form.request.data
        })
        flash('You request was successfully saved !', "success")
        # return redirect(url_for('login.login'))

    return render_template("get_help.html", form=form)
コード例 #14
0
def new_request():
    """
    Create new request
    """
    form = RequestForm()
    # Get the csrf_token from the request cookie and put it into the
    # form manually to validate_on_submit can be used
    user = None
    if current_user.is_authenticated:
        user = current_user.to_dict()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        # Add the user to the session, we are logged in!
        new_request = Request(title=form.data['title'],
                              active=False,
                              userId=user["id"])
        db.session.add(new_request)
        db.session.commit()
        return new_request.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}, 401
コード例 #15
0
def make_hit_request(id):
    player = Player.query.get(id)

    form = RequestForm()

    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():
        hit_request = Request(date=form.data['date'],
                              requester_id=current_user.id,
                              requestee_id=id,
                              court_id=form.data['court_id'],
                              response=None)
        db.session.add(hit_request)
        db.session.commit()

        return jsonify(hit_request.to_dict())
    else:
        return ({"errors": "errors"})

    return ({"errors": "errors"})
コード例 #16
0
def index():
    top_graded = Movie.query.join(Review)\
        .with_entities(Movie.title, Movie.year, Movie.id, func.round(func.avg(Review.grade), 2)\
        .label('avg'))\
        .group_by(Movie.id).order_by(desc('avg')).limit(10).all()
    newbies = Movie.query.order_by(Movie.timestamp.desc()).limit(10).all()
    form = RequestForm()
    if form.validate_on_submit() and current_user.is_authenticated:
        movreq = MovieRequest(user_id=current_user.id,
                              name=form.name.data,
                              year=form.year.data,
                              other_info=form.other_info.data)
        db.session.add(movreq)
        db.session.commit()
        flash('Request sent!')
        return redirect(url_for('main.index'))
    return render_template('index.html',
                           title='home',
                           top_graded=top_graded,
                           newbies=newbies,
                           form=form)
コード例 #17
0
def send_goods():
    form = RequestForm()
    formDict = {}
    if (form.validate_on_submit()):
        formDict['product1'] = form.product1.data
        formDict['quantity1'] = form.quantity1.data
        formDict['product2'] = form.product2.data
        formDict['quantity2'] = form.quantity2.data
        sent_hash = hash(formDict)
        supplier_manu = concat(form.To.data, session['username'])
        #update sent_hash for the current user
        userdata[session['username']]['sent_hash'].append(sent_hash)
        hashr = post(url=validater_data + '/Supplier/Sent',
                     data={
                         'supplier_manu': supplier_manu,
                         'sent_hash': sent_hash,
                         'requested_payment': form.payment.data
                     })
        payment = {}
        payment['From'] = session['username']
        payment['To'] = form.To.data
        payment['Type'] = 'payment_request'
        payment['payment_request'] = form.payment.data
        url = 'http://' + userdata[form.To.data]['host'] + ':' + str(
            userdata[form.To.data]['port']) + '/update'
        r = post(url=url, data=payment)
        userdata[session['username']]['goods_request'].pop(0)
        if (r.status_code == 200):
            return 'Payment Request Sent'
        else:
            return 'Error in Sending'

    return render_template('request.html',
                           title='Request',
                           form=form,
                           payment=True)
コード例 #18
0
def render_request_done():
    form = RequestForm()
    if form.validate_on_submit():
        goal = int(form.goals.data)

        name = form.clientName.data
        phone = form.clientPhone.data

        client = Client(name=name, phone=phone)

        db.session.add(client)
        db.session.commit()

        db.session.add(
            Request(client=client.id, goals=goal, time=int(form.time.data)))
        db.session.commit()

        return render_template(
            "request_done.html",
            goal=Goal.query.filter(Goal.id == goal).first(),
            form=form,
        )
    else:
        return render_template("request.html", form=form)