Ejemplo n.º 1
0
def add():
    """

    :return:
    """
    form = AddForm(request.form)
    if request.method == 'POST' and form.validate():
        data = request.form
        filename = 'item-10.jpg'
        if 'image' in request.files:
            photo = request.files['image']
            try:
                check_fold = os.path.isfile(
                    os.path.abspath(os.getcwd()) + '/' +
                    app.config['UPLOADED_PHOTOS_DEST'] + '/' + photo.filename)
                if check_fold is not False:
                    filename = str(photo.filename)
                else:
                    filename = photos.save(photo)
            except UploadNotAllowed:
                return redirect(url_for('error',
                                        message='INVALID FILE UPLOAD'))
        good = Goods(name=data['name'].title(),
                     price=data['price'],
                     quantity=data['quantity'],
                     image=filename)
        db.session.add(good)
        db.session.commit()
        return redirect(url_for('index'))
    else:
        print(form.errors)
    return render_template('add.html', form=form)
Ejemplo n.º 2
0
def adddevice():
    form = AddForm()

    # Eingabe
    if request.method == 'GET':
        # get args from home
        if request.args.get('servername'):
            sn = request.args.get('servername')
            print(sn)
            dn = "(servername=%s)" % sn
            print(dn)
            vms = ldap_search(dn)
            print(vms)

            form.servername.data = (vms[0][0][1]["servername"][0])
            form.internalname.data = (vms[0][0][1]["internalname"][0])
            form.mainresponsible.data = (vms[0][0][1]["mainresponsible"][0])
            form.substitute.data = (vms[0][0][1]["substitute"][0])
            form.costcenter.data = (int(vms[0][0][1]["costcenter"][0]))
            form.location.data = (vms[0][0][1]["location"][0])
            form.department.data = (vms[0][0][1]["department"][0])
            form.servertype.data = bool(vms[0][0][1]["servertype"][0])
            form.serverdescription.data = (
                vms[0][0][1]["serverdescription"][0])
            form.serverservice.data = (vms[0][0][1]["serverservice"][0])
            form.workloadservice.data = int(vms[0][0][1]["workloadservice"][0])
            form.workloadintime.data = (vms[0][0][1]["workloadintime"][0])
            form.privacyrelatedfiles.data = bool(
                vms[0][0][1]["privacyrelatedfiles"][0])
            form.dependencies.data = (vms[0][0][1]["dependencies"][0])
            form.redundancy.data = (vms[0][0][1]["redundancy"][0])
            form.bootorder.data = (vms[0][0][1]["bootorder"][0])
            form.impactforotherserver.data = (
                vms[0][0][1]["impactforotherserver"][0])
            form.departmentaffected.data = (
                vms[0][0][1]["departmentaffected"][0])
            form.furtherwork.data = bool(vms[0][0][1]["furtherwork"][0])
            form.cost.data = float(vms[0][0][1]["cost"][0])
            form.serviceaccount.data = (vms[0][0][1]["serviceaccount"][0])
            form.purposeaccount.data = (vms[0][0][1]["purposeaccount"][0])
            form.manuallyrestart.data = (vms[0][0][1]["manuallyrestart"][0])
            form.otherinformation.data = (vms[0][0][1]["otherinformation"][0])
            return render_template('add.html', form=form)
        else:
            return render_template('add.html', form=form)

    elif request.method == 'POST':
        # Fehler
        if not form.validate():
            flash('Error, validation faild.')
            return render_template('add.html', form=form)
        else:
            print(form.servername.data)
            return render_template('add.html', form=form)
Ejemplo n.º 3
0
def create():
    """
    create page: get sentences from users via form
    if the information is valid then redirect back to index page
    """
    form = AddForm(request.form)
    # check if the information entered in the form is valid
    # if valid then store the sentence in the database
    if request.method == 'POST' and form.validate():
        sentence = Sentences(sentence=form.sentence.data)
        db.session.add(sentence)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('create.html', form=form)
Ejemplo n.º 4
0
def adddevice():
    form = AddForm()

    # Eingabe
    if request.method == 'GET':
        # get args from home
        if request.args.get('servername'):
            sn = request.args.get('servername')
            print(sn)
            dn = "(servername=%s)" % sn
            print(dn)
            vms = ldap_search(dn)
            print(vms)

            form.servername.data = (vms[0][0][1]["servername"][0])
            form.internalname.data = (vms[0][0][1]["internalname"][0])
            form.mainresponsible.data = (vms[0][0][1]["mainresponsible"][0])
            form.substitute.data = (vms[0][0][1]["substitute"][0])
            form.costcenter.data = (int(vms[0][0][1]["costcenter"][0]))
            form.location.data = (vms[0][0][1]["location"][0])
            form.department.data = (vms[0][0][1]["department"][0])
            form.servertype.data = bool(vms[0][0][1]["servertype"][0])
            form.serverdescription.data = (vms[0][0][1]["serverdescription"][0])
            form.serverservice.data = (vms[0][0][1]["serverservice"][0])
            form.workloadservice.data = int(vms[0][0][1]["workloadservice"][0])
            form.workloadintime.data = (vms[0][0][1]["workloadintime"][0])
            form.privacyrelatedfiles.data = bool(vms[0][0][1]["privacyrelatedfiles"][0])
            form.dependencies.data = (vms[0][0][1]["dependencies"][0])
            form.redundancy.data = (vms[0][0][1]["redundancy"][0])
            form.bootorder.data = (vms[0][0][1]["bootorder"][0])
            form.impactforotherserver.data = (vms[0][0][1]["impactforotherserver"][0])
            form.departmentaffected.data = (vms[0][0][1]["departmentaffected"][0])
            form.furtherwork.data = bool(vms[0][0][1]["furtherwork"][0])
            form.cost.data = float(vms[0][0][1]["cost"][0])
            form.serviceaccount.data = (vms[0][0][1]["serviceaccount"][0])
            form.purposeaccount.data = (vms[0][0][1]["purposeaccount"][0])
            form.manuallyrestart.data = (vms[0][0][1]["manuallyrestart"][0])
            form.otherinformation.data = (vms[0][0][1]["otherinformation"][0])
            return render_template('add.html', form=form)
        else:
            return render_template('add.html', form=form)

    elif request.method == 'POST':
        # Fehler
        if not form.validate():
            flash('Error, validation faild.')
            return render_template('add.html', form=form)
        else:
            print (form.servername.data)
            return render_template('add.html', form=form)
Ejemplo n.º 5
0
def add():
    form = AddForm(request.form)
    if request.method != "POST" or not form.validate():
        return render_template("admin_add.html", add_form=form)

    shortcode = form.shortcode.data
    target_url = form.target_url.data
    random = form.is_random.data

    if (not shortcode or len(shortcode) == 0) and not random:
        return abort("No shortcode specified.", 400)

    if random:
        # Make sure the target doesn't already have a random shortcode
        target = database_helper.find_by_target(target_url)
        if target and target.is_random:
            flash("Shortcode '%s' for this URL already exists. %s" % (target.shortcode, url_for_code(target.shortcode, target.target_url)), category="info")
            return render_template("admin_add.html", add_form=form)

        # Find an unused random shortcode
        count = 0
        while True:
            shortcode = get_random_shortcode(current_app.config["SHORTCODE_LENGTH"])
            if database_helper.get_shortcode_target(shortcode) is None:
                break
                
            # Make sure we don't loop endlessly
            count = count + 1
            if count > 4:
                flash("Could not find usable shortcode after 5 tries.", category="danger")
                return render_template("admin_add.html", add_form=form)
    else:
        # Make sure this shortcode doesn't already exist
        target = database_helper.get_shortcode_target(shortcode)
        if target:
            flash("Shortcode '%s' already exists to %s." % (shortcode, target.target_url), category="warning")
            return render_template("admin_add.html", add_form=form)

    if database_helper.insert_shortcode(shortcode, target_url, random):
        msg = "Shortcode '%s' added successfully. %s" % (shortcode, url_for_code(shortcode, target_url))
        category = "success"
    else:
        msg = "Failed to create shortcode."
        category = "danger"

    flash(msg, category)
    return redirect(url_for(".add"))
Ejemplo n.º 6
0
 def add(self):
     from uliweb.utils import date
     from forms import AddForm
     
     form = AddForm()
     if request.method == 'GET':
         today = date.today()
         form.bind({'begin_date':today})
         return {'form':form}
     elif request.method == 'POST':
         #对提交的数据进行校验
         if form.validate(request.POST):
             obj = self.model(**form.data)
             obj.save()
             return redirect(url_for(self.__class__.index))
         else:
             return {'form':form}
Ejemplo n.º 7
0
def add_pupp():

    form = AddForm(request.form)

    if request.method == 'POST' and form.validate():

        name = form.name.data
        color = form.color.data
        owner = form.owner.data

        new_puppy = Puppy(name, color, owner)
        db.session.add(new_puppy)
        db.session.commit()

        flash('Puppy successfully added to our database')

        return redirect(url_for('list_pup'))

    return render_template('add.html', form=form)
Ejemplo n.º 8
0
def edit(shortcode):
    result = database_helper.get_shortcode_target(shortcode)
    if result is None:
        return abort(404)

    form = AddForm(request.form, obj=result)
    if request.method != "POST" or not form.validate():
        return render_template("admin_edit.html", add_form=form, data=result)

    target_url = form.target_url.data

    if database_helper.update_shortcode(shortcode, target_url):
        msg = "Shortcode '%s' updated successfully. %s" % (shortcode, url_for_code(shortcode, target_url))
        category = "success"
    else:
        msg = "Failed to update shortcode."
        category = "danger"

    flash(msg, category)
    return redirect(url_for(".list"))