def getPrinters(self, inputs): self.msg = [] if "company" in inputs: self.msg = printer_reg.objects( company=int(inputs["company"])).to_json() elif "brand" in inputs: self.msg = printer_reg.objects( brand__icontains=inputs["brand"]).to_json() return {"status": 200, "value": self.msg, "type": "text/plain"}
def getByUser(self, inputs): # This method gets the data, from the db. profile=login().getProfile({'key':inputs["user_code"]})["value"] storeDict = self.session.query(category, Status.description, company._name).\ filter(Status.code == category.status,Type.code==category.cat_type).\ filter(company.code == category.company).\ filter(company.email ==profile["email"] ) if category.code.name in inputs: storeDict = storeDict.filter(category.code == int(inputs[category.code.name])) if category.cat_type.name in inputs: storeDict = storeDict.filter(category.cat_type == int(inputs[category.cat_type.name])) if category.cat_name.name in inputs: storeDict = storeDict.filter(category.cat_name.ilike("%" + str(inputs[category.cat_name.name]) + "%")) # The next area is in charge to extract the information, # from the store Dict and add it to the dataCol to be returned dataCol = [] for dataLst in storeDict: dicStore = {"status_name": dataLst._asdict()[Status.description.name], "company_name":dataLst._asdict()[company._name.name]} for key in DBProcess(category.category_tbl).getColumnDefinition: dataDict = dataLst._asdict()[category.__name__].__dict__ # Getting the dictionary of the list. colname = key["name"] # Getting the column name. if colname in dataDict: # Just if the column name is on the dictionary, add it to the dictStore. dicStore[colname] = DBProcess(category.category_tbl).parse2publish(dataDict[colname]) product_type = self.session.query(Type).filter_by(code=dicStore[category.type_product.name]).first() if product_type!=None: dicStore["product_type_name"] = product_type.tpname category_type = self.session.query(Type).filter_by(code=dicStore[category.cat_type.name]).first() if category_type != None: dicStore["categorytp_name"] = category_type.tpname if printer_reg.objects(name=dicStore["printer"]).first()!=None: dicStore["printer_id"]=printer_reg.objects(name=dicStore["printer"]).first().code dataCol.append(dicStore) # Appending everything to be returned if "wrap_to" in inputs: dataCol = General().WrapInfo(inputs, dataCol, [{category.code.name: "id"}, {category.cat_name.name: "text"}]) self.session.close() return {"status": 200, "value": dataCol, 'type': 'application/json'}
def Handle(self, inputs): # This method will modify an expanse. item = int(inputs[category.code.name]) category_info=self.session.query(category).filter_by(code=item).first() logo_path=category_info.avatar if category.avatar.name in inputs: if inputs[category.avatar.name]["filename"] != 'da39a3ee5e6b4b0d3255bfef95601890afd80709.': logo_path = inputs[category.avatar.name]["filename"] logo_file = inputs[category.avatar.name]["value"] storeDir = inputs["__documentroot__"] + "/resources/site/" + "products/" inputs[category.avatar.name] = logo_path file = open(storeDir + logo_path, "w", encoding="ISO-8859-1") file.write(logo_file.decode("ISO-8859-1")) file.close() else: del inputs[category.avatar.name] storeDict = {} printer = category_info.printer if category.printer.name in inputs: printer = printer_reg.objects(code=int(inputs[category.printer.name])).first().name inputs[category.printer.name]=printer for column in DBProcess(category.category_tbl).getColumnDefinition: if column["name"] in inputs: storeDict[column["expr"]] = DBProcess(category.category_tbl).parse(column, inputs[column["name"]]) self.session.query(category).filter_by(code=item).update(storeDict) self.session.commit() self.session.close() return {"status": 200, "value": {category.code.name: item}, 'type': 'application/json'}
def create(self, inputs): # This method will create a category. self.code = CodeGen().GenCode({"table": category.__tablename__, "column": category.code.name}) # Generating the code. cat_type = 61 if category.cat_type.name in inputs: cat_type = int(inputs[category.cat_type.name]) status=12 if category.status.name in inputs: status=inputs[category.status.name] prod_type=131 if category.type_product.name in inputs: prod_type =int(inputs[category.type_product.name]) printer="" if category.printer.name in inputs: printer = printer_reg.objects(code=int(inputs[category.printer.name])).first().name logo_path = "" logo_file = "".encode() if category.avatar.name in inputs: logo_path = inputs[category.avatar.name]["filename"] logo_file = inputs[category.avatar.name]["value"] storeDir = inputs["__documentroot__"] + "/resources/site/" + "products/" inputs[category.avatar.name] = logo_path file = open(storeDir + logo_path, "w", encoding="ISO-8859-1") file.write(logo_file.decode("ISO-8859-1")) file.close() self.session.add(category(code=self.code, status=int(status),avatar=logo_path, company=int(inputs[category.company.name]), cat_name=inputs[category.cat_name.name],type_product=prod_type, cat_type=cat_type, printer=printer)) # Saving self.session.commit() self.session.close() return {"status": 200, "value": {category.code.name: self.code}, 'type': 'application/json'}
def HandlePrinter(self, inputs): # First creating or taking the code of the printer printer_obj = None brand = "" model = "" server = "" path = "" username = "" password = "" _type = "" status = 11 name = "" if "code" in inputs: code = int(inputs["code"]) printer_obj = printer_reg.objects(code=code).first() if printer_obj != None: brand = printer_obj.brand model = printer_obj.model server = printer_obj.server path = printer_obj.path username = printer_obj.username password = printer_obj.password _type = printer_obj._type status = printer_obj.status name = printer_obj.name else: code = CodeGen().GenCode({ "table": "printer_reg", "column": "code" }) printer_reg(code=code, company=inputs["company"]).save() if "name" in inputs: name = inputs["name"] if "brand" in inputs: brand = inputs["brand"] if "model" in inputs: model = inputs["model"] if "server" in inputs: server = inputs["server"] if "password" in inputs: password = inputs["password"] if "_type" in inputs: _type = inputs["_type"] if "status" in inputs: status = int(inputs["status"]) if "path" in inputs: path = str(inputs["path"]) if "username" in inputs: username = str(inputs["username"]) category = "" if "category" in inputs: category = inputs["category"] printer_reg.objects(code=code).\ update(set__brand=brand, set__model=model, set__server=server, set__path=path, set__username=username, set__password=password, set___type=_type, set__category=category, set__status=status, set__name=name) self.session.close() self.connORM.dispose() return {"status": 200, "value": code, "type": "application/json"}