add named tags
This commit is contained in:
parent
4e43076c04
commit
849e482d62
|
@ -5,6 +5,7 @@ from flask import g
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceForm(FlaskForm):
|
class LotDeviceForm(FlaskForm):
|
||||||
|
@ -77,6 +78,22 @@ class LotForm(FlaskForm):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
|
class TagForm(FlaskForm):
|
||||||
|
code = StringField(u'Code', [validators.length(min=1)])
|
||||||
|
|
||||||
|
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 NewActionForm(FlaskForm):
|
class NewActionForm(FlaskForm):
|
||||||
name = StringField(u'Name')
|
name = StringField(u'Name')
|
||||||
date = StringField(u'Date')
|
date = StringField(u'Date')
|
||||||
|
|
|
@ -6,7 +6,7 @@ from flask_login import login_required, current_user
|
||||||
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
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm
|
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, TagForm
|
||||||
|
|
||||||
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
||||||
|
|
||||||
|
@ -109,6 +109,21 @@ class TagListView(View):
|
||||||
return flask.render_template(self.template_name, **context)
|
return flask.render_template(self.template_name, **context)
|
||||||
|
|
||||||
|
|
||||||
|
class TagAddView(View):
|
||||||
|
methods = ['GET', 'POST']
|
||||||
|
decorators = [login_required]
|
||||||
|
template_name = 'inventory/tag.html'
|
||||||
|
|
||||||
|
def dispatch_request(self):
|
||||||
|
form = TagForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
form.save()
|
||||||
|
next_url = url_for('inventory.devices.taglist')
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
return flask.render_template(self.template_name, form=form)
|
||||||
|
|
||||||
|
|
||||||
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
||||||
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
|
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
|
||||||
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
|
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
|
||||||
|
@ -117,3 +132,4 @@ devices.add_url_rule('/lot/add/', view_func=LotView.as_view('lot_add'))
|
||||||
devices.add_url_rule('/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del'))
|
devices.add_url_rule('/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del'))
|
||||||
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))
|
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))
|
||||||
devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist'))
|
devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist'))
|
||||||
|
devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add'))
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
{% extends "ereuse_devicehub/base_site.html" %}
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<div class="pagetitle">
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<nav>
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="index.html">Inventory</a></li>
|
||||||
|
<li class="breadcrumb-item">Tag</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div><!-- End Page Title -->
|
||||||
|
|
||||||
|
<section class="section profile">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4">
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="pt-4 pb-2">
|
||||||
|
<h5 class="card-title text-center pb-0 fs-4">Add a new Tag</h5>
|
||||||
|
<p class="text-center small">Please enter a code for the tag.</p>
|
||||||
|
{% if form.form_errors %}
|
||||||
|
<p class="text-danger">
|
||||||
|
{% for error in form.form_errors %}
|
||||||
|
{{ error }}<br/>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post" class="row g-3 needs-validation" novalidate>
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<label for="code" class="form-label">code</label>
|
||||||
|
<div class="input-group has-validation">
|
||||||
|
<input type="text" name="code" class="form-control" required value="{{ form.code.data|default('', true) }}">
|
||||||
|
<div class="invalid-feedback">Please enter a code of the tag.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<a href="{{ url_for('inventory.devices.taglist') }}" class="btn btn-danger">Cancel</a>
|
||||||
|
<button class="btn btn-primary" type="submit">Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xl-8">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock main %}
|
|
@ -22,7 +22,7 @@
|
||||||
<!-- Bordered Tabs -->
|
<!-- Bordered Tabs -->
|
||||||
|
|
||||||
<div class="btn-group dropdown ml-1">
|
<div class="btn-group dropdown ml-1">
|
||||||
<a href="{{ url_for('inventory.devices.devicelist')}}" type="button" class="btn btn-primary">
|
<a href="{{ url_for('inventory.devices.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>
|
||||||
|
@ -45,7 +45,6 @@
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Select all</th>
|
|
||||||
<th scope="col">Code</th>
|
<th scope="col">Code</th>
|
||||||
<th scope="col">Type</th>
|
<th scope="col">Type</th>
|
||||||
<th scope="col">Provider</th>
|
<th scope="col">Provider</th>
|
||||||
|
@ -55,8 +54,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="checkbox" class="deviceSelect" data="{{ tag.id }}"/></td>
|
<td>{{ tag.id }}</td>
|
||||||
<td>{{ tag.code }}</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>{% if tag.device %}{{ tag.device.type }} {{ tag.device.manufacturer }} {{ tag.device.model }}{% endif %}</td>
|
<td>{% if tag.device %}{{ tag.device.type }} {{ tag.device.manufacturer }} {{ tag.device.model }}{% endif %}</td>
|
||||||
|
|
Reference in New Issue