def handle(self, *args, **kwargs): with open( '/Users/alexanderwarnes/Documents/abw_codes/Git/5E Rules CSVs/5E Rules CSVs/Items-Table 1.csv' ) as f: items = pd.read_csv(f, delimiter=',') items = items.dropna() for item in items.iterrows(): item_entry = Item( name=item[1][0], item_type=item[1][1], description=item[1][2], weight=item[1][3], material=item[1][4], cost_copper=item[1][5], cost_silver=item[1][6], cost_gold=item[1][7], cost_platinum=item[1][8], special=item[1][9], uses=item[1][10], space=item[1][11], ) item_entry.save()
def process_data(number_list, options): """ Take a list of numbers and create a new equipment item for each. ItemType is specified in options.itemtype. """ check_data(number_list, options) added_count = 0 for number in number_list: number = number.upper() # Normalize to upper case if options.hipnumber: new_item = Item(itemtype=options.itemtype, hip_number=number) else: new_item = Item(itemtype=options.itemtype, serialnumber=number) if options.add: new_item.log_this("Added from %s" % options.datafile) new_item.save() added_count += 1 print "Added %s new items (%s)" % (added_count, options.itemtype)
def check_out(request, person_id=None, due_timestamp=None): """ This view handles all stages of the checkout operation. In order for checkout to begin, a person_id must be in the URL. Optional due_timestamp is also in the URL. Those are designed to persist; i.e. if you change the person the custom due date (if any) is kept, and if you change the due date the person (if any) is kept. """ # Set default due date values for use in "Change due date" form dummy_item = Item() dummy_item.set_due_datetime() example_due_date = dummy_item.due.date() example_due_time = dummy_item.due.time() # If a specific due-date was requested, set it if due_timestamp: custom_due_datetime = datetime.datetime.strptime( due_timestamp, "%Y-%m-%d-%H-%M") else: custom_due_datetime = None title = "Scan ID" try: # If a change is requested for person or due date, update the URL if set(["due_date", "due_time", "person_id"]).intersection(request.GET): url = checkout_url(request, due_timestamp, person_id) return HttpResponseRedirect(url) if person_id: person = Person.objects.get(id_number=person_id) if not person.is_active(): raise Person.DoesNotExist("ID EXPIRED") title = "Checking out equipment to %s" % person recent_checkouts = recent_transactions(person, kind=Transaction.CHECKOUT) if request.method == "POST" and request.POST['number']: try: item = Item.find_by_number(request.POST['number']) item.check_out(person, custom_due_datetime) message = "Checked out %s" % item soundfile = "Glass.aiff" except (ItemError, TransactionError), error_message: soundfile = "error.mp3" except Person.DoesNotExist, reason: title = "Bad ID" id_number = person_id or request.GET['person_id'] error_message = "%s: %s" % (id_number, reason) person = None soundfile = "error.mp3"