def inventory_update_view(): if login.current_user.is_anonymous(): abort() # 1 = checkin, 2 = checkout status = int(request.form["status"]) checkout_meta = None # provide meta if status == InventoryItem.CHECKED_OUT: # checkout dtype = int(request.form["duration_type"]) duration = request.form["duration"] try: duration = int(duration) # enforce duration limit if duration > 999: duration = 999 except ValueError: duration = 0 checkout_meta = CheckoutMeta( duration=duration, duration_type=dtype, is_ooo=(True if int(request.form.get("ooo", 0)) else False) ) person = Person.objects(id=request.form["personid"]).get() item = InventoryItem.objects(id=request.form["itemid"]).get() # add a log log = InventoryLog.add_log( person=person, item=item, status=int(request.form["status"]), checkout_meta=checkout_meta ) # update the item status item.status = status item.save() response = { "duration": {"dateAdded": log.get_date_added(), "description": log.get_checkout_description()}, "person": {"name": log.person.name}, } return json.dumps(response)
def __init__(self, formdata=None, obj=None, prefix='', **kwargs): super(InventoryItemForm, self).__init__(request.form, obj, prefix, **kwargs) self.csrf_enabled = False self.group.choices = [(str(grp.id), grp.name) for grp in InventoryGroup.objects] # select the group if request.args.get('id') and not self.is_submitted(): item = InventoryItem.objects(id=request.args.get('id')).get() self.group.data = str(item.group.id)
def create_model(self, form): # only if its set do we care if its unique if form.identifier.data and InventoryItem.objects( identifier=form.identifier.data).count(): flash('Identifier (%s) is already in use' % form.identifier.data) return False # overriden to update the date values of the model now = datetime.now() item = InventoryItem( name=form.name.data, identifier=form.identifier.data, comment=form.comment.data, status=form.status.data, # get the model for the target group group=InventoryGroup.objects.get(id=form.group.data), date_added=now, date_updated=now) try: item.save() except Exception, e: flash('Unable to add the item', category='error') if settings.DEBUG: flash('DEBUG: %s' % e, category='error') return False
def create_model(self, form): # only if its set do we care if its unique if form.identifier.data and InventoryItem.objects(identifier=form.identifier.data).count(): flash('Identifier (%s) is already in use' % form.identifier.data) return False # overriden to update the date values of the model now = datetime.now() item = InventoryItem( name=form.name.data, identifier=form.identifier.data, comment=form.comment.data, status=form.status.data, # get the model for the target group group=InventoryGroup.objects.get(id=form.group.data), date_added=now, date_updated=now ) try: item.save() except Exception, e: flash('Unable to add the item', category='error') if settings.DEBUG: flash('DEBUG: %s' % e, category='error') return False