diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 5eab3236..3faa8751 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1007,3 +1007,18 @@ class TradeDocumentForm(FlaskForm): db.session.commit() return self._obj + + +class PrintTagsForm(FlaskForm): + devices = StringField(render_kw={'class': "devicesList d-none"}) + + def validate(self, extra_validators=None): + is_valid = super().validate(extra_validators) + + if not self.devices.data: + return False + + device_ids = self.devices.data.split(",") + self._tags = Tag.query.filter(Tag.device_id.in_(device_ids)).all() + + return is_valid diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 4e827be4..a438bf96 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -21,6 +21,7 @@ from ereuse_devicehub.inventory.forms import ( LotForm, NewActionForm, NewDeviceForm, + PrintTagsForm, TagDeviceForm, TagForm, TagUnnamedForm, @@ -118,6 +119,7 @@ class DeviceListMix(GenericMixView): 'form_new_datawipe': form_new_datawipe, 'form_new_trade': form_new_trade, 'form_filter': form_filter, + 'form_print_tags': PrintTagsForm(), 'lot': lot, 'tags': tags, 'list_devices': list_devices, @@ -381,6 +383,35 @@ class TagAddUnnamedView(View): return flask.render_template(self.template_name, form=form, **context) +class PrintTagsView(View): + """This View is used to print labels from multiple devices""" + + methods = ['POST', 'GET'] + decorators = [login_required] + template_name = 'inventory/print_tags.html' + title = 'Design and implementation of labels' + + def dispatch_request(self): + lots = Lot.query.filter(Lot.owner_id == current_user.id) + context = { + 'lots': lots, + 'page_title': self.title, + 'version': __version__, + 'referrer': request.referrer, + } + + form = PrintTagsForm() + if form.validate_on_submit(): + context['form'] = form + context['tags'] = form._tags + return flask.render_template(self.template_name, **context) + else: + messages.error('Error you need select one or more devices') + + next_url = request.referrer or url_for('inventory.devicelist') + return flask.redirect(next_url) + + class TagDetailView(View): decorators = [login_required] template_name = 'inventory/tag_detail.html' @@ -734,3 +765,7 @@ devices.add_url_rule( devices.add_url_rule( '/export//', view_func=ExportsView.as_view('export') ) +devices.add_url_rule( + '/tags/print', + view_func=PrintTagsView.as_view('print_tags'), +) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 157dda05..9c6ced51 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -235,6 +235,17 @@ Remove Tag from selected Device +
  • + +
  • diff --git a/ereuse_devicehub/templates/inventory/print_tags.html b/ereuse_devicehub/templates/inventory/print_tags.html new file mode 100644 index 00000000..421eecde --- /dev/null +++ b/ereuse_devicehub/templates/inventory/print_tags.html @@ -0,0 +1,108 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + +
    +

    Print tags

    + +
    + +
    +
    +
    + +
    +
    +
    +
    Print Tags
    +

    {{ title }}

    +
    + +
    +
    + {% for tag in tags %} +
    +
    +
    +
    +
    +
    +
    +
    {{ tag.id }}
    +
    +
    +
    +
    + {% endfor %} +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + + mm +
    +
    + +
    +
    + + mm +
    +
    +
    +
    +
    +
    + Print +
    +
    + Save +
    +
    + Reset +
    +
    + +
    + +
    +
    +
    + +
    + + + + +{% endblock main %}