예제 #1
0
def showcomponent():
    form = ComponentsForm()
    form.name.data = "Test"
    print("Start of test")
    print(form.name.label)
    print(form.name)
    if request.method == 'POST':
        print ("POST method")
        if not form.validate():
            return render_template('componentform.html', form=form)
        else:
            return "[1] Create a new user [2] sign in the user [3] redirect to the user's profile"
    elif request.method == 'GET':
        print ("GET method")
        return render_template('componentform.html', form=form)
예제 #2
0
 def loadform(self, *argv):
     arglst = []
     for arg in argv:
         arglst.append(arg)
     componentdata = arglst[0]
     trim = arglst[1]
     # Add the supplier selectfield
     supplierchoices = [(a.ID, a.Name) for a in self.dbsession.query(Suppliers).order_by('Name')]
     suppliercurrent = str([item[1] for item in supplierchoices if item[0] == componentdata.SuppliersID][0])
     form = ComponentsForm(supplier=componentdata.SuppliersID, location=componentdata.LocationsID)
     form.name.data = componentdata.Name
     form.description.data = componentdata.Description
     form.currentstock.data = componentdata.CurrentStock
     form.reorderlevel.data = componentdata.ReorderLevel
     form.datasheet.data = componentdata.Datasheet
     form.ordercode.data = componentdata.OrderCode
     form.unitprice.data = componentdata.UnitPrice
     form.supplier.choices = supplierchoices
     form.location.choices = \
         [(a.ID, a.Name+'::'+a.Sublocation) for a in self.dbsession.query(Locations).order_by('Name')]
     component = self.getdatabyname(componentdata.Name, componentdata.SuppliersID, componentdata.LocationsID)
     componentid = component.ID
     form.features = []
     for feature in self.dbsession.query(Features).\
             join(DefinedFeatures, DefinedFeatures.FeatureID == Features.ID).\
             filter(DefinedFeatures.ComponentID == componentid).all():
         featureobj = FeatureObject(self.dbsession, Features)
         form.features.append(featureobj.loadform(feature))
         del form.features[-1].components
         form.features[-1].name.label = 'Feature'
     if trim:
         del form.datasheet
         del form.categoryid
         del form.reorderlevel
         del form.id
         del form.unitprice
         del form.ordercode
     del form.components
     return form