change label for labels
This commit is contained in:
parent
1df6303f21
commit
7a532fb02c
|
@ -25,7 +25,7 @@ from ereuse_devicehub.inventory.forms import (
|
||||||
TradeForm,
|
TradeForm,
|
||||||
UploadSnapshotForm,
|
UploadSnapshotForm,
|
||||||
)
|
)
|
||||||
from ereuse_devicehub.label.forms import PrintLabelsForm
|
from ereuse_devicehub.labels.forms import PrintLabelsForm
|
||||||
from ereuse_devicehub.resources.action.models import Trade
|
from ereuse_devicehub.resources.action.models import Trade
|
||||||
from ereuse_devicehub.resources.device.models import Computer, DataStorage, Device
|
from ereuse_devicehub.resources.device.models import Computer, DataStorage, Device
|
||||||
from ereuse_devicehub.resources.documents.device_row import ActionRow, DeviceRow
|
from ereuse_devicehub.resources.documents.device_row import ActionRow, DeviceRow
|
||||||
|
|
73
ereuse_devicehub/labels/forms.py
Normal file
73
ereuse_devicehub/labels/forms.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
from flask import g
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from wtforms import IntegerField, StringField, validators
|
||||||
|
|
||||||
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
|
|
||||||
|
|
||||||
|
class TagForm(FlaskForm):
|
||||||
|
code = StringField('Code', [validators.length(min=1)])
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
error = ["This value is being used"]
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
if not is_valid:
|
||||||
|
return False
|
||||||
|
tag = Tag.query.filter(Tag.id == self.code.data).all()
|
||||||
|
if tag:
|
||||||
|
self.code.errors = error
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self.instance = Tag(id=self.code.data)
|
||||||
|
db.session.add(self.instance)
|
||||||
|
db.session.commit()
|
||||||
|
return self.instance
|
||||||
|
|
||||||
|
def remove(self):
|
||||||
|
if not self.instance.device and not self.instance.provider:
|
||||||
|
self.instance.delete()
|
||||||
|
db.session.commit()
|
||||||
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
|
class TagUnnamedForm(FlaskForm):
|
||||||
|
amount = IntegerField('amount')
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
num = self.amount.data
|
||||||
|
tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)])
|
||||||
|
tags = [Tag(id=tag_id, provider=g.inventory.tag_provider) for tag_id in tags_id]
|
||||||
|
db.session.add_all(tags)
|
||||||
|
db.session.commit()
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
class PrintLabelsForm(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._devices = (
|
||||||
|
Device.query.filter(Device.id.in_(device_ids))
|
||||||
|
.filter(Device.owner_id == g.user.id)
|
||||||
|
.distinct()
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
# print only tags that are DHID
|
||||||
|
dhids = [x.devicehub_id for x in self._devices]
|
||||||
|
self._tags = (
|
||||||
|
Tag.query.filter(Tag.owner_id == g.user.id).filter(Tag.id.in_(dhids)).all()
|
||||||
|
)
|
||||||
|
|
||||||
|
return is_valid
|
|
@ -7,11 +7,11 @@ from flask_login import current_user, login_required
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
from ereuse_devicehub import __version__, messages
|
from ereuse_devicehub import __version__, messages
|
||||||
from ereuse_devicehub.label.forms import PrintLabelsForm, TagForm, TagUnnamedForm
|
from ereuse_devicehub.labels.forms import PrintLabelsForm, TagForm, TagUnnamedForm
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
from ereuse_devicehub.resources.tag.model import Tag
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
|
|
||||||
label = Blueprint('label', __name__, url_prefix='/label')
|
labels = Blueprint('labels', __name__, url_prefix='/labels')
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||||
class TagListView(View):
|
class TagListView(View):
|
||||||
methods = ['GET']
|
methods = ['GET']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'label/label_list.html'
|
template_name = 'labels/label_list.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
@ -36,7 +36,7 @@ class TagListView(View):
|
||||||
class TagAddView(View):
|
class TagAddView(View):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'label/tag_create.html'
|
template_name = 'labels/tag_create.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
@ -44,7 +44,7 @@ class TagAddView(View):
|
||||||
form = TagForm()
|
form = TagForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.save()
|
form.save()
|
||||||
next_url = url_for('label.label_list')
|
next_url = url_for('labels.label_list')
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
return flask.render_template(self.template_name, form=form, **context)
|
return flask.render_template(self.template_name, form=form, **context)
|
||||||
|
@ -53,7 +53,7 @@ class TagAddView(View):
|
||||||
class TagAddUnnamedView(View):
|
class TagAddUnnamedView(View):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'label/tag_create_unnamed.html'
|
template_name = 'labels/tag_create_unnamed.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
@ -76,7 +76,7 @@ class TagAddUnnamedView(View):
|
||||||
)
|
)
|
||||||
messages.error(msg)
|
messages.error(msg)
|
||||||
|
|
||||||
next_url = url_for('label.label_list')
|
next_url = url_for('labels.label_list')
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
return flask.render_template(self.template_name, form=form, **context)
|
return flask.render_template(self.template_name, form=form, **context)
|
||||||
|
@ -87,7 +87,7 @@ class PrintLabelsView(View):
|
||||||
|
|
||||||
methods = ['POST', 'GET']
|
methods = ['POST', 'GET']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'label/print_labels.html'
|
template_name = 'labels/print_labels.html'
|
||||||
title = 'Design and implementation of labels'
|
title = 'Design and implementation of labels'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
|
@ -113,7 +113,7 @@ class PrintLabelsView(View):
|
||||||
|
|
||||||
class LabelDetailView(View):
|
class LabelDetailView(View):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'label/label_detail.html'
|
template_name = 'labels/label_detail.html'
|
||||||
|
|
||||||
def dispatch_request(self, id):
|
def dispatch_request(self, id):
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
@ -130,13 +130,13 @@ class LabelDetailView(View):
|
||||||
return flask.render_template(self.template_name, **context)
|
return flask.render_template(self.template_name, **context)
|
||||||
|
|
||||||
|
|
||||||
label.add_url_rule('/', view_func=TagListView.as_view('label_list'))
|
labels.add_url_rule('/', view_func=TagListView.as_view('label_list'))
|
||||||
label.add_url_rule('/add/', view_func=TagAddView.as_view('tag_add'))
|
labels.add_url_rule('/add/', view_func=TagAddView.as_view('tag_add'))
|
||||||
label.add_url_rule(
|
labels.add_url_rule(
|
||||||
'/unnamed/add/', view_func=TagAddUnnamedView.as_view('tag_unnamed_add')
|
'/unnamed/add/', view_func=TagAddUnnamedView.as_view('tag_unnamed_add')
|
||||||
)
|
)
|
||||||
label.add_url_rule(
|
labels.add_url_rule(
|
||||||
'/print',
|
'/print',
|
||||||
view_func=PrintLabelsView.as_view('print_labels'),
|
view_func=PrintLabelsView.as_view('print_labels'),
|
||||||
)
|
)
|
||||||
label.add_url_rule('/<string:id>/', view_func=LabelDetailView.as_view('label_details'))
|
labels.add_url_rule('/<string:id>/', view_func=LabelDetailView.as_view('label_details'))
|
|
@ -181,7 +181,7 @@
|
||||||
<li class="nav-heading">Utils</li>
|
<li class="nav-heading">Utils</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link collapsed" href="{{ url_for('label.label_list')}}">
|
<a class="nav-link collapsed" href="{{ url_for('labels.label_list')}}">
|
||||||
<i class="bi bi-tags"></i>
|
<i class="bi bi-tags"></i>
|
||||||
<span>Tags</span>
|
<span>Tags</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -236,7 +236,7 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<form id="print_labels" method="post" action="{{ url_for('label.print_labels') }}">
|
<form id="print_labels" method="post" action="{{ url_for('labels.print_labels') }}">
|
||||||
{% for f in form_print_labels %}
|
{% for f in form_print_labels %}
|
||||||
{{ f }}
|
{{ f }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -346,7 +346,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for t in dev.tags | sort(attribute="id") %}
|
{% for t in dev.tags | sort(attribute="id") %}
|
||||||
<a href="{{ url_for('label.label_details', id=t.id)}}">{{ t.id }}</a>
|
<a href="{{ url_for('labels.label_details', id=t.id)}}">{{ t.id }}</a>
|
||||||
{% if not loop.last %},{% endif %}
|
{% if not loop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<h1>Inventory</h1>
|
<h1>Inventory</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="{{ url_for('label.label_list')}}">Tag management</a></li>
|
<li class="breadcrumb-item"><a href="{{ url_for('labels.label_list')}}">Tag management</a></li>
|
||||||
<li class="breadcrumb-item active">Tag details {{ tag.id }}</li>
|
<li class="breadcrumb-item active">Tag details {{ tag.id }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
|
@ -20,7 +20,7 @@
|
||||||
<!-- Bordered Tabs -->
|
<!-- Bordered Tabs -->
|
||||||
|
|
||||||
<div class="btn-group dropdown ml-1">
|
<div class="btn-group dropdown ml-1">
|
||||||
<a href="{{ url_for('label.tag_add')}}" type="button" class="btn btn-primary">
|
<a href="{{ url_for('labels.tag_add')}}" type="button" class="btn btn-primary">
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Create Named Tag
|
Create Named Tag
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
||||||
<a href="{{ url_for('label.tag_unnamed_add')}}" type="button" class="btn btn-primary">
|
<a href="{{ url_for('labels.tag_unnamed_add')}}" type="button" class="btn btn-primary">
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Create UnNamed Tag
|
Create UnNamed Tag
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ url_for('label.label_details', id=tag.id) }}">{{ tag.id }}</a></td>
|
<td><a href="{{ url_for('labels.label_details', id=tag.id) }}">{{ tag.id }}</a></td>
|
||||||
<td>{% if tag.provider %}Unnamed tag {% else %}Named tag{% endif %}</td>
|
<td>{% if tag.provider %}Unnamed tag {% else %}Named tag{% endif %}</td>
|
||||||
<td>{{ tag.get_provider }}</td>
|
<td>{{ tag.get_provider }}</td>
|
||||||
<td>
|
<td>
|
|
@ -5,7 +5,7 @@
|
||||||
<h1>Print Labels</h1>
|
<h1>Print Labels</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="{{ url_for('label.label_list')}}">Tag management</a></li>
|
<li class="breadcrumb-item"><a href="{{ url_for('labels.label_list')}}">Tag management</a></li>
|
||||||
<li class="breadcrumb-item active">Print Labels</li>
|
<li class="breadcrumb-item active">Print Labels</li>
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
|
@ -5,7 +5,7 @@
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="{{ url_for('label.label_list')}}">Tag management</a></li>
|
<li class="breadcrumb-item"><a href="{{ url_for('labels.label_list')}}">Tag management</a></li>
|
||||||
<li class="breadcrumb-item">{{ page_title }}</li>
|
<li class="breadcrumb-item">{{ page_title }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('label.label_list') }}" class="btn btn-danger">Cancel</a>
|
<a href="{{ url_for('labels.label_list') }}" class="btn btn-danger">Cancel</a>
|
||||||
<button class="btn btn-primary" type="submit">Save</button>
|
<button class="btn btn-primary" type="submit">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
|
@ -5,7 +5,7 @@
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="{{ url_for('label.label_list')}}">Tag management</a></li>
|
<li class="breadcrumb-item"><a href="{{ url_for('labels.label_list')}}">Tag management</a></li>
|
||||||
<li class="breadcrumb-item">{{ page_title }}</li>
|
<li class="breadcrumb-item">{{ page_title }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('label.label_list') }}" class="btn btn-danger">Cancel</a>
|
<a href="{{ url_for('labels.label_list') }}" class="btn btn-danger">Cancel</a>
|
||||||
<button class="btn btn-primary" type="submit">Save</button>
|
<button class="btn btn-primary" type="submit">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
Reference in a new issue