def perform_command(command): """ Performs the command by name. Stores the result in `Storage()`. :param command: command name, selected by user. """ command = command.lower() routes = get_routes() try: command_class = routes[command] command_inst = command_class() storage = Storage() command_inst.perform(storage.items) except KeyError: print('Bad command, try again.') except UserExitException as ex: print(ex) raise
def storage_crud(): if request.method == 'POST': new_warehouse_id = request.form['warehouse_id'] new_container_id = request.form['container_number'] new_product_code = request.form['product_code'] new_quantity = float(request.form['quantity']) try: product_id = get_id_by_product_code(new_product_code) new_storage = Storage(container_id=new_container_id, product_id=product_id, quantity=new_quantity).create() return redirect('/storage_crud') except: return redirect('/storage_crud') # return 'There was an issue adding information about storage of product. \n\nPerhaps such a product is already stored in this container or there is no product with this code.' else: warehouses = get_all_warehouses() res = get_product_storage_inf() return render_template('storage.html', storages=res, warehouses=warehouses)
def show(self): print(self.header) storage = Storage() input_func = get_option_input() def get_input(): selected_option = input_func('Enter option: ') if selected_option not in self.next_menus: raise UserInputOptionException return selected_option while True: print('Starting test...') self.test(storage) print(self.options) selected_option = self.input_secure_wrap(get_input) if selected_option == '2': break
def main(): """ Main method, works infinitelly until user runs `exit` command. Or hits `Ctrl+C` in the console. """ storage = Storage() try: with open('storage.dat', 'rb') as stor: storage.items = pickle.load(stor) except IOError: pass while True: try: command = parse_user_input() perform_command(command) except UserExitException: break except KeyboardInterrupt: print('Shutting down, bye!') break
def test_files(self): # Attempting to access a FileField from the class raises a descriptive # error self.assertRaises(AttributeError, lambda: Storage.normal) # An object without a file has limited functionality. obj1 = Storage() self.assertEqual(obj1.normal.name, "") self.assertRaises(ValueError, lambda: obj1.normal.size) # Saving a file enables full functionality. obj1.normal.save("django_test.txt", ContentFile("content")) self.assertEqual(obj1.normal.name, "tests/django_test.txt") self.assertEqual(obj1.normal.size, 7) self.assertEqual(obj1.normal.read(), "content") obj1.normal.close() # File objects can be assigned to FileField attributes, but shouldn't # get committed until the model it's attached to is saved. obj1.normal = SimpleUploadedFile("assignment.txt", "content") dirs, files = temp_storage.listdir("tests") self.assertEqual(dirs, []) self.assertEqual(sorted(files), ["default.txt", "django_test.txt"]) obj1.save() dirs, files = temp_storage.listdir("tests") self.assertEqual( sorted(files), ["assignment.txt", "default.txt", "django_test.txt"] ) # Files can be read in a little at a time, if necessary. obj1.normal.open() self.assertEqual(obj1.normal.read(3), "con") self.assertEqual(obj1.normal.read(), "tent") self.assertEqual(list(obj1.normal.chunks(chunk_size=2)), ["co", "nt", "en", "t"]) obj1.normal.close() # Save another file with the same name. obj2 = Storage() obj2.normal.save("django_test.txt", ContentFile("more content")) self.assertEqual(obj2.normal.name, "tests/django_test_1.txt") self.assertEqual(obj2.normal.size, 12) # Push the objects into the cache to make sure they pickle properly cache.set("obj1", obj1) cache.set("obj2", obj2) self.assertEqual(cache.get("obj2").normal.name, "tests/django_test_1.txt") # Deleting an object does not delete the file it uses. obj2.delete() obj2.normal.save("django_test.txt", ContentFile("more content")) self.assertEqual(obj2.normal.name, "tests/django_test_2.txt") # Multiple files with the same name get _N appended to them. objs = [Storage() for i in range(3)] for o in objs: o.normal.save("multiple_files.txt", ContentFile("Same Content")) self.assertEqual( [o.normal.name for o in objs], ["tests/multiple_files.txt", "tests/multiple_files_1.txt", "tests/multiple_files_2.txt"] ) for o in objs: o.delete() # Default values allow an object to access a single file. obj3 = Storage.objects.create() self.assertEqual(obj3.default.name, "tests/default.txt") self.assertEqual(obj3.default.read(), "default content") obj3.default.close() # But it shouldn't be deleted, even if there are no more objects using # it. obj3.delete() obj3 = Storage() self.assertEqual(obj3.default.read(), "default content") obj3.default.close() # Verify the fix for #5655, making sure the directory is only # determined once. obj4 = Storage() obj4.random.save("random_file", ContentFile("random content")) self.assertTrue(obj4.random.name.endswith("/random_file")) # Clean up the temporary files and dir. obj1.normal.delete() obj2.normal.delete() obj3.default.delete() obj4.random.delete()
def main(): storage = Storage() storage.fill_storage() main_menu = MainMenu() main_menu.show()
from datetime import datetime from helpers import get_oder_class from models import Storage import json storage = Storage() orderbook = storage.orderbook def create_order(request): data_in = request.json keys = sorted(list(data_in.keys())) if keys != ['price', 'size', 'type']: output = { "error": "Missing keys", } return 400, json.dumps(output) _class = get_oder_class(data_in['type']) order = _class(data_in['price'], data_in['size']) orderbook.add_order(order) output = {"order_id": order.id} return 200, json.dumps(output) def get_order(request, id): for o in storage.orderbook.get_all_orders(): if o.id == id: order = o break
def perform(self, objects, *args, **kwargs): from models import Storage storage = Storage() for i in storage.items: i.done = self._done_flag
def isoS(): if request.method == 'POST': monsel, oder, peep, serv, invo, inco, cache, modata, modlink, fdata, invooder = init_storage_zero( ) invojo, filesel, docref, search11, search12, search21, search31 = init_storage_blank( ) leftscreen = 1 docref = ' ' err = ['All is well', ' ', ' ', ' ', ' '] ldata = None #today = datetime.datetime.today().strftime('%Y-%m-%d') today = datetime.date.today() invodate = datetime.date.today() leftsize = 10 monvec = [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] monlvec = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] match = request.values.get('Match') modify = request.values.get('Modify') vmod = request.values.get('Vmod') minvo = request.values.get('MakeI') mpack = request.values.get('MakeP') viewo = request.values.get('ViewO') viewi = request.values.get('ViewI') viewp = request.values.get('ViewP') analyze = request.values.get('Analyze') print = request.values.get('Print') addE = request.values.get('addentity') addS = request.values.get('addservice') recpay = request.values.get('RecPay') hispay = request.values.get('HisPay') monsel = request.values.get('monsel') returnhit = request.values.get('Return') deletehit = request.values.get('Delete') # hidden values update = request.values.get('Update') invoupdate = request.values.get('invoUpdate') recupdate = request.values.get('recUpdate') modlink = request.values.get('passmodlink') emailnow = request.values.get('emailnow') emailinvo = request.values.get('emailInvo') newjob = request.values.get('NewJ') thisjob = request.values.get('ThisJob') oder = request.values.get('oder') invo = request.values.get('invo') invooder = request.values.get('invooder') cache = request.values.get('cache') peep = request.values.get('peep') serv = request.values.get('serv') inco = request.values.get('inco') modlink = nonone(modlink) oder = nonone(oder) invo = nonone(invo) invooder = nonone(invooder) peep = nonone(peep) serv = nonone(serv) monsel = nonone(monsel) inco = nonone(inco) modal = 0 if returnhit is not None: modlink = 0 invo = 0 invooder = 0 inco = 0 # ____________________________________________________________________________________________________________________B.UpdateDatabases.Storage if update is not None and modlink == 1: if oder > 0: modata = Storage.query.get(oder) desc = request.values.get('desc') amount = request.values.get('amount') thiscomp = request.values.get('thiscomp') dstart = request.values.get('dstart') balfwd = request.values.get('pybal') modata.Description = desc modata.Amount = amount modata.Date = dstart modata.BalFwd = balfwd ldat = People.query.filter(People.Company == thiscomp).first() if ldat is not None: acomp = ldat.Company aid = ldat.id else: acomp = None aid = None modata.Company = acomp modata.Pid = aid modata.Label = modata.Jo + ' ' + thiscomp + ' ' + amount db.session.commit() err[3] = 'Modification to Storage JO ' + modata.Jo + ' completed.' modlink = 0 if peep > 0: modata = People.query.get(peep) modata.Ptype = 'Storage' vals = [ 'company', 'fname', 'mnames', 'lname', 'addr1', 'addr2', 'addr3', 'idtype', 'tid', 'tel', 'email', 'assoc1', 'assoc2', 'date1' ] a = list(range(len(vals))) i = 0 for v in vals: a[i] = request.values.get(v) i = i + 1 modata.Company = a[0] modata.First = a[1] modata.Middle = a[2] modata.Last = a[3] modata.Addr1 = a[4] modata.Addr2 = a[5] modata.Addr3 = a[6] modata.Idtype = a[7] modata.Idnumber = a[8] modata.Telephone = a[9] modata.Email = a[10] modata.Associate1 = a[11] modata.Associate2 = a[12] modata.Date1 = a[13] db.session.commit() err = [ ' ', ' ', 'Modification to Entity ID ' + str(modata.id) + ' completed.', ' ', ' ' ] modlink = 0 # And now update the crossover to Storage in case the Company info changed: cross = Storage.query.filter(Storage.Pid == peep) for cros in cross: cros.Company = a[0] db.session.commit() if serv > 0: modata = Services.query.get(serv) vals = ['service', 'price'] a = list(range(len(vals))) i = 0 for v in vals: a[i] = request.values.get(v) i = i + 1 modata.Service = a[0] modata.Price = a[1] db.session.commit() err = [ ' ', ' ', 'Modification to Services Data with ID ' + str(modata.id) + ' completed.', ' ', ' ' ] modlink = 0 if inco > 0: modata = Income.query.get(inco) vals = ['desc', 'recamount', 'custref', 'recdate'] i = 0 for v in vals: a[i] = request.values.get(v) i = i + 1 modata.Description = a[0] modata.Amount = a[1] modata.Ref = a[2] modata.Date = a[3] db.session.commit() err = [ ' ', ' ', 'Modification to Income Data with ID ' + str(modata.id) + ' completed.', ' ', ' ' ] # ____________________________________________________________________________________________________________________E.UpdateDatabases.Storage # ____________________________________________________________________________________________________________________B.UpdateInvoice.Storage if invoupdate is not None and monsel != 0: leftsize = 8 odata1 = Storage.query.get(invooder) invojo = popjo(invooder, monsel) ldata = Invoices.query.filter(Invoices.SubJo == invojo).all() invodate = request.values.get('invodate') total = 0 for data in ldata: iqty = request.values.get('qty' + str(data.id)) iqty = nononef(iqty) data.Description = request.values.get('desc' + str(data.id)) deach = request.values.get('cost' + str(data.id)) if deach is not None: deach = "{:.2f}".format(float(deach)) amount = iqty * float(deach) else: deach = "{:.2f}".format(0.00) amount = 0.00 total = total + amount amount = "{:.2f}".format(amount) data.Qty = iqty data.Ea = deach data.Amount = amount data.Total = 0.00 data.Date = invodate db.session.commit() if total > 0 and ldata is not None: for data in ldata: data.Total = "%0.2f" % total db.session.commit() odata1.Amount = "%0.2f" % total db.session.commit() #Remove zeros from invoice in case a zero was the mod Invoices.query.filter(Invoices.Qty == 0).delete() db.session.commit() #Create invoice code for order err = [ ' ', ' ', 'Invoice created for Storage JO: ' + invojo, ' ', ' ' ] ldata = Invoices.query.filter(Invoices.SubJo == invojo).all() # ____________________________________________________________________________________________________________________E.UpdateInvoice.Storage odata = Storage.query.order_by(Storage.Jo).all() cdata = People.query.filter(People.Ptype == 'Storage').order_by( People.Company).all() sdata = Services.query.all() oder, peep, serv, numchecked = numcheck(3, odata, cdata, sdata, 0, 0, ['oder', 'peep', 'serv']) # ____________________________________________________________________________________________________________________E.SearchFilters.Storage # ____________________________________________________________________________________________________________________B.EmailInvoice.Storage if emailinvo is not None: leftsize = 10 leftscreen = 1 modlink = 0 modata = Storage.query.get(invooder) invojo = popjo(invooder, monsel) ldata = Invoices.query.filter(Invoices.SubJo == invojo).order_by( Invoices.Ea.desc()).all() pdata1 = People.query.filter(People.id == modata.Pid).first() ldat = Invoices.query.filter(Invoices.SubJo == invojo).first() if pdata1 is None: err = [ ' ', ' ', 'There is no Billing information for this selection', ' ', ' ' ] else: email = pdata1.Email company = pdata1.Company docref = ldat.Original if 'vinvoice' not in docref: err = [ ' ', ' ', 'There is no document available for this selection', ' ', ' ' ] else: if email is not None: import invoice_mimemail_S invoice_mimemail_S.main(invojo, docref, email, monsel, inco, company) if inco == 0: for data in ldata: data.Status = "E" db.session.commit() else: for data in ldata: data.Status = "P" db.session.commit() invooder = 0 invo = 0 inco = 0 # ____________________________________________________________________________________________________________________E.EmailInvoice.Storage # ____________________________________________________________________________________________________________________B.Viewers.Storage if viewo is not None and numchecked == 1: err = [ ' ', ' ', 'There is no document available for this selection', ' ', ' ' ] if oder > 0: modata = Storage.query.get(oder) if modata.Original is not None: if len(modata.Original) > 5: docref = modata.Original leftscreen = 0 leftsize = 8 modlink = 0 err = [ ' ', ' ', 'Viewing document ' + docref, ' ', ' ' ] if (viewo is not None or viewi is not None or viewp is not None) and numchecked != 1: err = [ 'Must check exactly one box to use this option', ' ', ' ', ' ', ' ' ] if viewi is not None and numchecked == 1: err = [ 'There is no document available for this selection', ' ', ' ', ' ', ' ' ] if monsel == 0: err[1] = 'Need to select the month' if oder > 0 and monsel > 0: invooder = oder modata = Storage.query.get(oder) invojo = popjo(oder, monsel) ldat = Invoices.query.filter(Invoices.SubJo == invojo).first() if ldat.Original is not None: docref = ldat.Original leftscreen = 0 leftsize = 8 modlink = 5 err = [' ', ' ', 'Viewing document ' + docref, ' ', ' '] # ____________________________________________________________________________________________________________________E.Viewers.Storage # ____________________________________________________________________________________________________________________B.ModifyEntries.Storage if (modify is not None or vmod is not None) and numchecked == 1: modlink = 1 leftsize = 8 if oder > 0: modata = Storage.query.get(oder) if vmod is not None: err = [ ' ', ' ', 'There is no document available for this selection', ' ', ' ' ] if modata.Original is not None: if len(modata.Original) > 5: leftscreen = 0 docref = modata.Original err = ['All is well', ' ', ' ', ' ', ' '] if serv > 0: modata = Services.query.get(serv) if vmod is not None: err = [ ' ', ' ', 'There is no document available for this selection', ' ', ' ' ] if peep > 0: modata = People.query.get(peep) if vmod is not None: err = [ ' ', ' ', 'There is no document available for this selection', ' ', ' ' ] if (modify is not None or vmod is not None) and numchecked != 1: modlink = 0 err[0] = ' ' err[2] = 'Must check exactly one box to use this option' # ____________________________________________________________________________________________________________________E.ModifyEntries.Storage # ____________________________________________________________________________________________________________________B.AddEntries.Storage if addS is not None and serv > 0 and numchecked == 1: leftsize = 8 modlink = 2 modata = Services.query.get(serv) if addS is not None and numchecked == 0: leftsize = 8 modlink = 1 #We will create a blank line and simply modify that by updating: input = Services(Service='New', Price=0.00) db.session.add(input) db.session.commit() modata = Services.query.filter(Services.Service == 'New').first() serv = modata.id err = [' ', ' ', 'Enter Data for New Service', ' ', ' '] if addS is not None and numchecked > 1: modlink = 0 err[0] = ' ' err[2] = 'Must check exactly one box to use this option' if addE is not None and peep > 0 and numchecked == 1: leftsize = 8 modlink = 3 modata = People.query.get(peep) if addE is not None and numchecked == 0: leftsize = 8 modlink = 1 #We will create a blank line and simply modify that by updating: input = People(Company='New', First='', Middle='', Last='', Addr1='', Addr2='', Addr3='', Idtype='', Idnumber='', Telephone='', Email='', Associate1='', Associate2='', Date1=today, Date2=None, Original=None, Ptype='Storage', Temp1=None, Temp2=None) db.session.add(input) db.session.commit() modata = People.query.filter((People.Company == 'New') & (People.Ptype == 'Storage')).first() peep = modata.id modata.Company = '' db.session.commit() modata = People.query.get(peep) err = [' ', ' ', 'Enter Data for New Company', ' ', ' '] if addE is not None and numchecked > 1: modlink = 0 err[0] = ' ' err[2] = 'Must check exactly one box to use this option' # ____________________________________________________________________________________________________________________E.AddEntries.Storage # ____________________________________________________________________________________________________________________B.ReceivePayment.Storage if (recpay is not None and oder > 0 and numchecked == 1 and monsel > 0) or recupdate is not None: leftsize = 8 if recpay is not None: invooder = oder odat = Storage.query.get(invooder) invojo = popjo(invooder, monsel) ldat = Invoices.query.filter(Invoices.SubJo == invojo).first() err = ['Have no Invoice to Receive Against', ' ', ' ', ' ', ' '] if ldat is not None: invodate = ldat.Date if ldat.Original is not None: docref = ldat.Original leftscreen = 0 leftsize = 8 incdat = Income.query.filter(Income.SubJo == invojo).first() if incdat is None: err = ['Creating New Payment on SubJo', ' ', ' ', ' ', ' '] paydesc = 'Received payment on Invoice ' + invojo + ' for month of ' + monvec[ monsel] recamount = str(ldat.Amount) custref = 'ChkNo' recdate = datetime.date(today.year, monsel, 28) input = Income(Jo=odat.Jo, SubJo=invojo, Pid=odat.Pid, Description=paydesc, Amount=recamount, Ref=custref, Date=recdate, Original=None) db.session.add(input) payment = 0 else: recamount = request.values.get('recamount') custref = request.values.get('custref') desc = request.values.get('desc') recdate = request.values.get('recdate') incdat.Amount = recamount incdat.Ref = custref incdat.Description = desc incdat.Date = recdate db.session.commit() payment = [recamount, custref, recdate] modata = Income.query.filter(Income.SubJo == invojo).first() inco = modata.id err = [' ', ' ', 'Amend Payment for Invoice', ' ', ' '] ldata = Invoices.query.filter( Invoices.SubJo == invojo).order_by( Invoices.Ea.desc()).all() pdata1 = People.query.filter(People.id == odat.Pid).first() cache = nonone(odat.Cache) + 1 basejo = odat.Jo involine, paidline, refline, balline = money12(basejo) balduenow = balline[monsel] try: balduenow = float[balduenow] except: balduenow = 0.00 if balduenow < .001: for data in ldata: data.Status = "P" db.session.commit() import make_S_invoice make_S_invoice.main(odat, ldata, pdata1, invojo, involine, paidline, refline, balline, invodate, cache, payment) if cache > 1: docref = f'tmp/{scac}/data/vinvoice/INV' + invojo + 'c' + str( cache) + '.pdf' # Store for future use else: docref = f'tmp/{scac}/data/vinvoice/INV' + invojo + '.pdf' odat.Cache = cache idat = Invoices.query.filter(Invoices.SubJo == invojo).first() idat.Original = docref db.session.commit() leftscreen = 0 err[4] = 'Viewing ' + docref if recpay is not None and (oder == 0 or numchecked != 1 or monsel == 0): err = ['Invalid selections:', '', '', '', ''] if oder == 0: err[1] = 'Must select a Storage Job' if numchecked != 1: err[2] = 'Must select exactly one Storage Job' if monsel == 0: err[3] = 'Must select a month to apply payment' # ____________________________________________________________________________________________________________________E.ReceivePayment.Storage # ____________________________________________________________________________________________________________________B.PaymentHistory.Storage if hispay is not None or modlink == 7: if oder == 0 and invooder == 0: err[1] = 'Must select a Storage Job' else: if oder != 0: invooder = oder modata = Storage.query.get(invooder) ldata = Invoices.query.filter( Invoices.Jo == modata.Jo).order_by(Invoices.SubJo).all() fdata = Income.query.filter(Income.Jo == modata.Jo).order_by( Income.SubJo).all() #Check to see if we need to delete anything from history killthis = request.values.get('killthis') if killthis is not None and modlink == 7: for data in ldata: testone = request.values.get('bill' + str(data.id)) if testone: kill = int(testone) Invoices.query.filter(Invoices.id == kill).delete() db.session.commit() for data in fdata: testone = request.values.get('pay' + str(data.id)) if testone: kill = int(testone) Income.query.filter(Income.id == kill).delete() db.session.commit() ldata = Invoices.query.filter( Invoices.Jo == modata.Jo).order_by( Invoices.SubJo).all() fdata = Income.query.filter( Income.Jo == modata.Jo).order_by(Income.SubJo).all() leftsize = 8 modlink = 7 # ____________________________________________________________________________________________________________________E.PaymentHistory.Storage # ____________________________________________________________________________________________________________________B.Delete.Storage if deletehit is not None and numchecked == 1: if oder > 0: Storage.query.filter(Storage.id == oder).delete() odata = Storage.query.all() if peep > 0: People.query.filter(People.id == peep).delete() cdata = People.query.filter( People.Ptype == 'Storage').order_by(People.Company).all() if serv > 0: Services.query.filter(Services.id == serv).delete() sdata = Services.query.all() db.session.commit() if deletehit is not None and numchecked != 1: err = [ ' ', ' ', 'Must have exactly one item checked to use this option', ' ', ' ' ] # ____________________________________________________________________________________________________________________E.Delete.Storage # ____________________________________________________________________________________________________________________B.Invoicing.Storage if ((minvo is not None and oder > 0) or invoupdate is not None) and monsel > 0: err = ['Could not create invoice', ' ', ' ', ' ', ' '] # First time through: have an order to invoice if oder > 0: invooder = oder myo = Storage.query.get(invooder) fee = myo.Amount #Check to see if we have the required data to make an invoice: invojo = popjo(invooder, monsel) thismonth = calendar.month_name[monsel] invodate = request.values.get('invodate') invo = 1 leftsize = 8 cache = nonone(myo.Cache) + 1 mys = Services.query.get(serv) if mys is not None: addserv = mys.Service price = mys.Price qty = 1 d = datetime.date(today.year, monsel, 1) descript = 'Monthly Storage Fee for Month of ' + thismonth input = Invoices(Jo=myo.Jo, SubJo=invojo, Pid=myo.Pid, Service=addserv, Description=descript, Ea=price, Qty=qty, Amount=price, Total=price, Date=d, Original=None, Status='New') db.session.add(input) db.session.commit() ldata = Invoices.query.filter(Invoices.SubJo == invojo).first() if ldata is None: invodate = datetime.date(today.year, monsel, 1) #See if there is an invoice from previous month to copy from try: invojoprev = popjo(invooder, monsel - 1) invodate = datetime.date(today.year, monsel, 1) ldata2 = Invoices.query.filter( Invoices.SubJo == invojoprev).all() for data in ldata2: mydescript = data.Description newdescript = data.Description for i in range(12): if monlvec[i] in newdescript: j = i + 1 if j == 12: j = 0 mydescript = newdescript.replace( monlvec[i], monlvec[j]) input = Invoices(Jo=myo.Jo, SubJo=invojo, Pid=myo.Pid, Service=data.Service, Description=mydescript, Ea=data.Ea, Qty=data.Qty, Amount=data.Amount, Date=invodate, Total=data.Total, Original=None, Status='New') db.session.add(input) db.session.commit() except: if mys is None: addserv = 'Monthly Storage' price = fee else: addserv = mys.Service price = mys.Price qty = 1 invodate = datetime.date(today.year, monsel, 1) descript = 'Monthly Storage Fee for Month of ' + thismonth input = Invoices(Jo=myo.Jo, SubJo=invojo, Pid=myo.Pid, Service=addserv, Description=descript, Ea=price, Qty=qty, Amount=price, Date=invodate, Total=price, Original=None, Status='New') db.session.add(input) db.session.commit() else: ldat = Invoices.query.filter( Invoices.SubJo == invojo).first() if ldat is None: if mys is None: addserv = 'Monthly Storage' price = fee else: addserv = mys.Service price = mys.Price qty = 1 invodate = datetime.date(today.year, monsel, 1) descript = 'Monthly Storage Fee for Month of ' + thismonth input = Invoices(Jo=myo.Jo, SubJo=invojo, Pid=myo.Pid, Service=addserv, Description=descript, Ea=price, Qty=qty, Amount=price, Date=invodate, Total=price, Original=None, Status='New') db.session.add(input) db.session.commit() ldat = Invoices.query.filter( Invoices.SubJo == invojo).first() invodate = ldat.Date # If have ldata: err = [' ', ' ', 'Created invoice for JO= ' + invojo, ' ', ' '] ldata = Invoices.query.filter(Invoices.SubJo == invojo).order_by( Invoices.Ea.desc()).all() pdata1 = People.query.filter(People.id == myo.Pid).first() odat = Storage.query.get(invooder) basejo = odat.Jo involine, paidline, refline, balline = money12(basejo) import make_S_invoice make_S_invoice.main(odat, ldata, pdata1, invojo, involine, paidline, refline, balline, invodate, cache, 0) if cache > 1: docref = f'tmp/{scac}/data/vinvoice/INV' + invojo + 'c' + str( cache) + '.pdf' # Store for future use else: docref = f'tmp/{scac}/data/vinvoice/INV' + invojo + '.pdf' odat.Path = docref odat.Cache = cache idat = Invoices.query.filter(Invoices.SubJo == invojo).first() idat.Original = docref db.session.commit() leftscreen = 0 err[4] = 'Viewing ' + docref modata = Storage.query.get(invooder) elif minvo is not None and monsel == 0: err = [' ', ' ', 'Choose a Month for the Invoice', ' ', ' '] elif minvo is not None: err = [ ' ', ' ', 'Must select at least 1 Job for this selection', ' ', ' ' ] # ____________________________________________________________________________________________________________________E.Invoicing.Storage # ____________________________________________________________________________________________________________________B.NewJob.Storage if newjob is not None: err = ['Select Source Document from List'] fdata = myoslist(f'tmp/{scac}/data/vunknown') modlink = 4 leftsize = 8 leftscreen = 0 docref = f'tmp/{scac}/data/vunknown/NewJob.pdf' if newjob is None and modlink == 4: filesel = request.values.get('FileSel') if filesel != '1': fdata = myoslist(f'tmp/{scac}/data/vunknown') leftsize = 8 leftscreen = 0 docref = f'tmp/{scac}/data/vunknown/' + filesel if thisjob is not None: modlink = 0 #Create the new database entry for the source document filesel = request.values.get('FileSel') if filesel != '1': docold = f'tmp/{scac}/data/vunknown/' + filesel docref = f'tmp/{scac}/data/vorders/' + filesel shutil.move(addpath(docold), addpath(docref)) else: docref = '' sdate = request.values.get('dstart') if sdate is None: sdate = today jtype = 'S' nextjo = newjo(jtype, sdate) thisdesc = request.values.get('thisdesc') thisamt = request.values.get('thisamt') thiscomp = request.values.get('thiscomp') pybal = request.values.get('pybal') ldat = People.query.filter(People.Company == thiscomp).first() if ldat is not None: acomp = ldat.Company aid = ldat.id else: acomp = None aid = None label = nextjo + ' ' + thiscomp + ' ' + thisamt input = Storage(Jo=nextjo, Description=thisdesc, BalFwd=pybal, Amount=thisamt, Status='New', Cache=1, Original=docref, Path=None, Pid=aid, Company=thiscomp, Date=sdate, Label=label) db.session.add(input) db.session.commit() modata = Storage.query.filter(Storage.Jo == nextjo).first() csize = People.query.filter(People.Ptype == 'Storage').order_by( People.Company).all() oder = modata.id leftscreen = 1 err = ['All is well', ' ', ' ', ' ', ' '] odata = Storage.query.all() # ____________________________________________________________________________________________________________________E.New Job.Storage # ____________________________________________________________________________________________________________________B.Matching.Storage if match is not None: if oder > 0 and peep > 0 and numchecked == 2: myo = Storage.query.get(oder) myp = People.query.get(peep) myo.Pid = peep myo.Company = myp.Company db.session.commit() if numchecked != 2: err[1] = 'Must select exactly 2 boxes to use this option.' err[0] = ' ' # ____________________________________________________________________________________________________________________E.Matching.Storage # Create the time oriented data for the columns bm, cm = timedata(odata) #This is the else for 1st time through else: # ____________________________________________________________________________________________________________________B.STORAGEnotPost odata = Storage.query.order_by(Storage.Jo).all() cdata = People.query.filter(People.Ptype == 'Storage').order_by( People.Company).all() sdata = Services.query.all() ldata = None today = datetime.datetime.today().strftime('%Y-%m-%d') invodate = today monsel, oder, peep, serv, invo, inco, cache, modata, modlink, fdata, invooder = init_storage_zero( ) invojo, filesel, docref, search11, search12, search21, search31 = init_storage_blank( ) monvec = [ 'All', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] leftscreen = 1 leftsize = 10 docref = ' ' err = ['All is well', ' ', ' ', ' ', ' '] bm, cm = timedata(odata) docref = docref.replace('tmp/vinvoice', f'tmp/{scac}/data/vinvoice') return odata, cdata, sdata, oder, peep, serv, err, modata, modlink, fdata, today, inco, leftscreen, docref, leftsize, ldata, monsel, monvec, invo, invooder, invojo, cache, filesel, bm, cm, invodate
class Game(object): """Ядро игры""" __obj = None input_function = get_input_function() storage = Storage() @classmethod def __new__(cls, *args): if cls.__obj is None: cls.__obj = object.__new__(cls) return cls.__obj @classmethod def start(cls, *args): """запуск игры""" clear_screen() #инициализация 2-х игроков while (len(cls.storage.players) < 2): player = cls.construct_player(len(cls.storage.players) + 1) cls.storage.players.append(player) clear_screen() player = cls.storage.players[0] enemy = cls.storage.players[1] if player is None or enemy is None: raise Exception('Игроки не были созданы!') hit_result_message = '' while True: try: if hit_result_message != '': clear_screen() print(hit_result_message + '\n') hit_result_message = '' cls.print_field(enemy.field.data, True) coord = cls.get_coords('Игрок {}, Ваш ход: '.format( player.name)) hit = enemy.hit(coord) if hit == 2: if enemy.total_hits() == 0: print('Игрок {} победил!'.format(player.name)) return hit_result_message = 'Игрок {} потопил корабль противника!!! Можете сделать еще один выстрел!'.format( player.name) elif hit == 1: hit_result_message = 'Игрок {} попал по кораблю противника!!! Можете сделать еще один выстрел!'.format( player.name) else: hit_result_message = 'Игрок {} промахнулся и ход переходит к {}!!!'.format( player.name, enemy.name) player, enemy = enemy, player except Exception as e: clear_screen() print(e + '\n') @staticmethod def get_name(number): """ Запрос имени игрока number - номер игрока """ while True: name = Game.input_function( 'Игрок № {}, введите свое имя: '.format(number)) if name == '': continue return name @staticmethod def get_coords(input_message): """ Запрос координат input_message - отображаемое сообщение """ while (True): user_input = Game.input_function(input_message) try: coords = user_input.split(",") if len(coords) != 2: raise Exception( "Некорректные данные. Слишко много, или мало координат." ) return Coord(int(coords[0]) - 1, int(coords[1]) - 1) except ValueError: print("Некорректные данные. Для ввода допустимы только цифры") except Exception as e: print(e) print() @staticmethod def get_direction(input_message): """ Запрос ориентации корабля input_message - отображаемое сообщение """ while (True): user_input = Game.input_function(input_message) try: if user_input not in ('В', 'Г'): raise Exception("Некорректные данные.") return user_input except Exception as e: print(e) print() def get_printable_row(row, hidden): """ Возвращает представление строки поля row - строка (данные) hidden - прятать корабли, или нет """ mask = [' ', ' ', 'X', '*', ' ' ] if hidden else [' ', '$', 'X', '*', ' '] r = [] for i in row: r.append(mask[i]) return r @staticmethod def print_field(field, hidden): """ Печать игрового поля field - поле hidden - прятать корабли, или нет """ print(' ' * 6 + ('{:4}' * 10).format(*tuple(range(1, Storage.field_size + 1)))) print(' ' * 7 + '-' * 41) for y in range(Storage.field_size): print(' {:3} |'.format(y + 1) + (' {} |' * 10).format( *tuple(Game.get_printable_row(field[y], hidden)))) print(' ' * 7 + '-' * 41) @classmethod def construct_player(cls, *args): """Создание игрока""" name = cls.get_name(args[0]) player = Player(name) print('Привет, {}, давай заполним твое поле'.format(name)) for s in cls.storage.ships: i = 0 while (i < s.quantity): try: #запрашиваем левую верхнюю координату корабля coord1 = cls.get_coords( 'Введите координаты для корабля {} № {} в формате "столбец,строка":' .format(s.name, i + 1)) coord2 = Coord(coord1.x, coord1.y) #запрашиваем способ расположения корабля только для многоклеточных if s.size > 1: direction = cls.get_direction( 'Укажите расположение корабля, вертикальное (В), или горизонтальное (Г): [В|Г]' ) if direction == 'В': coord2.y += s.size elif direction == 'Г': coord2.x += s.size #создаем корабль игрока ship = Ship(s.name, s.size, coord1, coord2) player.add_ship(ship) i += 1 clear_screen() Game.print_field(player.field.data, False) except Exception as e: print(e) player.field.clean_aura() return player
__author__ = 'sobolevn' app = Flask(__name__, template_folder='templates') app.config.from_object(config) @app.route('/', methods=['GET', 'POST']) def home(): storage = Storage() if request.method == 'POST': form = BlogPostForm(request.form) if form.validate(): model = BlogPostModel(form.data) storage.appending(model.model_to_dict()) else: logger.error('Someone have submitted an incorrect form!') else: form = BlogPostForm() return render_template( 'home.html', form=form, items=storage.posts, ) if __name__ == '__main__': Storage() app.run()
def test_object_without_file(self): # An object without a file has limited functionality. obj = Storage() self.assertEqual(repr(obj.normal), '<FieldFile: None>') self.assertRaises(ValueError, getattr, obj.normal, 'size')
def test_directory_determined_once(self): # Verify the fix for #5655, making sure the directory is only # determined once. obj = Storage() obj.random.save('random_file', ContentFile('random content')) self.assertEqual(obj.random.read(), 'random content')
def make_obj(): obj = Storage() obj.normal.save('django_test.txt', ContentFile('content')) return obj
def post(self): data = request.json url = Storage(url=data['url'], limit=data['limit']) db.session.add(url) db.session.commit() return id_schema.dump(url)
from models import Storage, Event from base import Base # initialize mysql storage Storage().init_storage() # get events base = Base() operation = 'listEvents/' payload = '{"filter":{"eventTypeIds":["1"]}}' data = base.retrieve(operation, payload) # list of dicts events = [] for event in data: events.append(Event(event))