diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index d29f239c..eceb99f0 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -375,7 +375,6 @@ class NewActionForm(FlaskForm): date = DateField(u'Date', validators=(validators.Optional(),)) severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity]) description = TextAreaField(u'Description') - lot = HiddenField() type = HiddenField() def validate(self, extra_validators=None): @@ -384,10 +383,6 @@ class NewActionForm(FlaskForm): if not is_valid: return False - if self.lot.data: - self._lot = Lot.query.filter(Lot.id == self.lot.data).filter( - Lot.owner_id == g.user.id).one() - devices = set(self.devices.data.split(",")) self._devices = OrderedSet(Device.query.filter(Device.id.in_(devices)).filter( Device.owner_id == g.user.id).all()) @@ -400,10 +395,16 @@ class NewActionForm(FlaskForm): def save(self): Model = db.Model._decl_class_registry.data[self.type.data]() self.instance = Model() + devices = self.devices.data + severity = self.severity.data self.devices.data = self._devices self.severity.data = Severity[self.severity.data] self.populate_obj(self.instance) + + self.devices.data = devices + self.severity.data = severity + db.session.add(self.instance) db.session.commit() return self.instance @@ -427,4 +428,8 @@ class AllocateForm(NewActionForm): self.end_time.errors = error is_valid = False + if not self.end_users.data: + self.end_users.errors = ["You need to specify a number of users"] + is_valid = False + return is_valid diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index f9386dc9..8702058d 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -27,14 +27,15 @@ class DeviceListMix(View): devices = [dev for dev in lot.devices if dev.type in filter_types] devices = sorted(devices, key=lambda x: x.updated, reverse=True) form_new_action = NewActionForm(lot=lot.id) + form_new_allocate = AllocateForm(lot=lot.id) else: devices = Device.query.filter( Device.owner_id == current_user.id).filter( Device.type.in_(filter_types)).filter(Device.lots == None).order_by( Device.updated.desc()) form_new_action = NewActionForm() + form_new_allocate = AllocateForm() - form_new_allocate = AllocateForm() self.context = {'devices': devices, 'lots': lots, @@ -179,10 +180,7 @@ class NewActionView(View): self.form = self._form() if self.form.validate_on_submit(): self.form.save() - if self.form.lot.data: - next_url = url_for('inventory.devices.lotdevicelist', id=self.form.lot.data) - - next_url = url_for('inventory.devices.devicelist') + next_url = request.referrer or url_for('inventory.devices.devicelist') return flask.redirect(next_url) @@ -197,9 +195,9 @@ class NewAllocateView(NewActionView, DeviceListMix): if self.form.validate_on_submit(): return dispatch - lot_id = self.form.lot.data - self.get_context(lot_id) - self.context['form_new_allocate'] = self.form + # lot_id = self.form.lot.data + # FIXME + self.get_context(None) return flask.render_template(self.template_name, **self.context)