Beispiel #1
0
def addcategories(componentid=None):
    if request.method == 'POST':
        # first delete existing categories defined
        # now save any that have been checked
        session.query(Definitions).filter(Definitions.ComponentID == componentid).delete()
        tmpcomponent = ComponentObject(session, Components)
        tmpcompdata = tmpcomponent.getdatabyid(componentid)
        tmpcategory = CategoryObject(session, Categories)
        tmpcatdata = tmpcategory.getdatabyname(tmpcompdata.Name)
        listcount = 1
        for addid in request.form.keys():
            listorder = request.form[addid]
            if listorder != '':
                additem = Definitions(ComponentID=componentid, CategoriesID=addid[3:], CategoryOrder=listorder)
                session.add(additem)
                category = session.query(Categories).filter(Categories.ID == addid[3:]).one()
                flash('Attached category {} to component {}.'.format(category.Name, tmpcompdata.Name))
                listcount += 1
        additem = Definitions(ComponentID=componentid, CategoriesID=tmpcatdata.ID, CategoryOrder=listcount)
        session.add(additem)
        session.commit()
        option = 'component'
        (option, pagetitle, form, deleteoptions, addfeatureoptions, categoriesopt, updateoption) = populatelist(option)
        return render_template('maintstatic.html', statictitle=pagetitle, form=form,
                               numrows=len(form), option=option, deleteoption=deleteoptions,
                               featureoption=addfeatureoptions, categoryoption=categoriesopt,
                               updateoption=updateoption)
    else:
        option = 'addcategories'
        (option, pagetitle, form, deleteoptions, addfeatureoptions, categoriesopt, updateoption) = populatelist(option, componentid)
    return render_template('addcategories.html', form=form, statictitle=pagetitle, componentid=componentid)
Beispiel #2
0
def showcomponents(componentid=None):
    if request.method == 'POST':
        pass

    componentobj = ComponentObject(session, Components)
    componentdata = session.query(Components). \
        filter(Components.ID == componentid).one()
    form = componentobj.loadform(componentdata, False)
    categorytree = []
    catsearch.reset()
    catsearchindex = 0
    for category in session.query(Definitions, Categories). \
            join(Categories, Definitions.CategoriesID == Categories.ID). \
            filter(Definitions.ComponentID == componentid).order_by(Definitions.CategoryOrder):
        categorytree.append(CategoryTree())
        categorytree[-1].id = category.Categories.ID
        categorytree[-1].name = category.Categories.Name
        categorytree[-1].listorder = catsearchindex + 1
        catsearch.listorder.append(catsearchindex + 1)
        catsearch.id.append(category.Categories.ID)
        catsearch.name.append(category.Categories.Name)
        catsearchindex += 1

    return render_template('componentform.html', form=form, categories=categorytree,
                           numfeatures=0, readlock='True')
Beispiel #3
0
def updelement(componentid=None):
    option = 'component'
    form = setform(option, request.form, modify=True)
    tmcomponent = ComponentObject(session, Components)
    if request.method == 'POST':
        # Update the component
        flash(tmcomponent.update(componentid, request.form))
        (option, pagetitle, form, deleteoptions, addfeatureoptions, categoriesopt, updateoption) = populatelist(option)
        return render_template('maintstatic.html', statictitle=pagetitle, form=form,
                               numrows=len(form), option=option, deleteoption=deleteoptions,
                               featureoption=addfeatureoptions, categoryoption=categoriesopt,
                               updateoption=updateoption)
    else:
        # form = setform(option, None, modify=True)
        compdata = tmcomponent.getdatabyid(componentid)
        form = tmcomponent.loadform(compdata, False)
        if option == 'component':
            # Add suppliers choices
            form.supplier.choices = [(a.ID, a.Name) for a in session.query(Suppliers).order_by('Name')]
            # Add location choices
            form.location.choices = \
                [(a.ID, a.Name+'::'+a.Sublocation) for a in session.query(Locations).order_by('Name')]

    return render_template('updatecomponent.html', form=form, statictitle=option, componentid=componentid)