Пример #1
0
def edit_vendor(id):
    """
    Edit a vendor
    """
    check_admin()

    add_vendor = False

    vendor = Vendor.query.get_or_404(id)
    form = VendorForm(obj=vendor)
    if form.validate_on_submit():
        vendor.name = form.name.data
        vendor.description = form.description.data
        db.session.commit()
        flash('You have successfully edited the vendor.')

        # redirect to the vendors page
        return redirect(url_for('admin.list_vendors'))

    form.description.data = vendor.description
    form.name.data = vendor.name
    return render_template('admin/vendors/vendor.html',
                           action="Edit",
                           add_vendor=add_vendor,
                           form=form,
                           vendor=vendor,
                           title="Edit Vendor")
Пример #2
0
def add_vendor():
    """
    Add a vendor to the database
    """
    check_admin()

    add_vendor = True

    form = VendorForm()
    if form.validate_on_submit():
        vendor = Vendor(name=form.name.data, description=form.description.data)
        try:
            # add vendor to the database
            db.session.add(vendor)
            db.session.commit()
            flash('You have successfully added a new vendor.')
        except:
            # in case vendor name already exists
            flash('Error: vendor name already exists.')

        # redirect to vendors page
        return redirect(url_for('admin.list_vendors'))

    # load vendor template
    return render_template('admin/vendors/vendor.html',
                           action="Add",
                           add_vendor=add_vendor,
                           form=form,
                           title="Add Vendor")
Пример #3
0
def vendor_add(request):
  if request.method == 'POST':
    form = VendorForm(request.POST)
    if form.is_valid():
      p = form.save(commit=False)
      p.sn = generate_sn(prefix = 'VDR')
      p = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
  else:
    form = VendorForm()
    return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
Пример #4
0
def vendor_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      c = Vendor.objects.get(sn=postdata.pop('sn')[0])
    except Vendor.DoesNotExist:
      raise Http404(module + ' not found')
    form = VendorForm(postdata, instance=c)
    if form.is_valid():
      c_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c_saved,]))
  else:
    return HttpResponse('Invalid request.')
Пример #5
0
def addvendor():
    form = VendorForm()
    if request.method == "GET":
        return render_template('addvendor.html', form=form)
    if request.method == "POST":
        if form.validate() == True:
            cursor = mysql.connection.cursor()
            query = "INSERT INTO vendor (vendor_name, vendor_phone_number, street, city, state, postal_code) VALUES (%s, %s, %s, %s, %s, %s)"
            variables = [form.vendor_name.data, form.vendor_phone_number.data, form.street.data, form.city.data, form.state.data, form.postal_code.data]
            cursor.execute(query, variables)
            mysql.connection.commit()
            return redirect(url_for("repairs", vendor_name=session["vendor"]["vendor_name"]))
        else:
            return render_template('addvendor.html', form=form)