Skip to content

Commit

Permalink
Fix CI (#394)
Browse files Browse the repository at this point in the history
* rm defunct tests

* fix Building/Room imports

* add missing requirement

* fix invalid syntax

* fix misc lint issues

* add missing migration

* fix invalid HTML

* avoid inline JavaScript

* alter_lageruser_timezone

to make CI happy

see #222
  • Loading branch information
xi authored Feb 22, 2022
1 parent f898f8f commit 9060858
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Lagerregal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
("linux", "Linux")
]

LABEL_PAGESIZE = (83*mm, 25*mm)
LABEL_PAGESIZE = (83 * mm, 25 * mm)
LABEL_ICON = "pdf_forms/minerva.jpg"
LABEL_TITLE = "Information Services & Technology"

Expand Down
4 changes: 2 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

from api.serializers import *
from devices.models import Bookmark
from devices.models import Building
from devices.models import Device
from devices.models import Lending
from devices.models import Manufacturer
from devices.models import Note
from devices.models import Picture
from devices.models import Room
from devices.models import Template
from devicetypes.models import Type
from locations.models import Building
from locations.models import Room
from mail.models import MailTemplate
from network.models import IpAddress
from users.models import Lageruser
Expand Down
4 changes: 2 additions & 2 deletions devices/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

from devicegroups.models import Devicegroup
from devices.forms import AddForm
from devices.models import Building
from devices.models import Device
from devices.models import Lending
from devices.models import Manufacturer
from devices.models import Room
from devicetypes.models import Type
from locations.models import Building
from locations.models import Room
from mail.models import MailTemplate
from users.models import Lageruser

Expand Down
1 change: 0 additions & 1 deletion devices/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def __init__(self, *args, **kwargs):
emailbody = forms.CharField(widget=forms.Textarea(), required=False, label=_("Body"))



class DeviceTrashForm(forms.Form):
error_css_class = 'has-error'
send_mail = forms.BooleanField(required=False, initial=True, label=_("Send E-Mail"))
Expand Down
21 changes: 21 additions & 0 deletions devices/migrations/0015_alter_device_room.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.3 on 2021-10-20 17:32

import django.db.models.deletion
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
('locations', '0004_building_room'),
('devices', '0014_auto_20210628_1406'),
]

operations = [
migrations.AlterField(
model_name='device',
name='room',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='locations.room'),
),
]
4 changes: 1 addition & 3 deletions devices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from devicegroups.models import Devicegroup
from devicetypes.models import Type
from Lagerregal import utils
from locations.models import Building
from locations.models import Room
from locations.models import Section
from users.models import Department
from users.models import Lageruser

Expand Down Expand Up @@ -120,7 +118,7 @@ def is_overdue(self):

@property
def is_active(self):
return self.archived == None and self.trashed == None
return self.archived is None and self.trashed is None

def archive_device(self):
self.archived = datetime.datetime.utcnow().replace(tzinfo=utc)
Expand Down
8 changes: 4 additions & 4 deletions devices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from model_mommy import mommy

from devices import views as device_views
from devices.models import Building
from devices.models import Device
from devices.models import DeviceInformation
from devices.models import DeviceInformationType
Expand All @@ -18,6 +17,7 @@
from devices.models import Note
from devices.models import Picture
from devices.models import Template
from locations.models import Building
from locations.models import Room
from network.models import IpAddress
from users.models import Lageruser
Expand Down Expand Up @@ -47,9 +47,9 @@ def test_device_creation(self):
"devicetype": device.devicetype,
"room": device.room,
})
self.assertFalse(device.is_overdue))
self.assertTrue(mommy.make(Device, currentlending=lending_past).is_overdue))
self.assertFalse(mommy.make(Device, currentlending=lending_future).is_overdue))
self.assertFalse(device.is_overdue)
self.assertTrue(mommy.make(Device, currentlending=lending_past).is_overdue)
self.assertFalse(mommy.make(Device, currentlending=lending_future).is_overdue)

def test_list_view(self):
mommy.make(Device, _quantity=40)
Expand Down
21 changes: 9 additions & 12 deletions devices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.db import models
from django.db.models import Q
from django.db.transaction import atomic
from django.http import FileResponse
from django.http import Http404
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
Expand All @@ -25,7 +24,6 @@
from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.timesince import timesince
from django.utils.timezone import utc
from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView
from django.views.generic import DeleteView
Expand All @@ -41,9 +39,7 @@
import pdfrw
from reportlab.graphics.barcode import code128
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
from reportlab.pdfgen import canvas
from rest_framework.renderers import JSONRenderer
from reversion import revisions as reversion
from reversion.models import Version

Expand Down Expand Up @@ -75,7 +71,6 @@
from devicetypes.models import TypeAttribute
from devicetypes.models import TypeAttributeValue
from Lagerregal.utils import PaginationMixin
from locations.models import Building
from locations.models import Room
from mail.models import MailHistory
from mail.models import MailTemplate
Expand Down Expand Up @@ -531,7 +526,7 @@ def get_initial(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["form"].fields["department"].queryset = self.request.user.departments.filter(short_name__isnull=False)
context["form"].fields["ipaddresses"].queryset = IpAddress.objects.filter(device = None, user = None).filter(Q(department__in=self.request.user.departments.all()) | Q(department=None))
context["form"].fields["ipaddresses"].queryset = IpAddress.objects.filter(device=None, user=None).filter(Q(department__in=self.request.user.departments.all()) | Q(department=None))
existing_id = self.request.GET.get("id", None)
if existing_id is not None:
device = get_object_or_404(Device, pk=existing_id)
Expand Down Expand Up @@ -763,7 +758,7 @@ def form_valid(self, form):
device.currentlending = lending
device.save()
url = reverse("device-detail", kwargs={"pk": device.pk})
if device.trashed != None and self.request.POST.get("generate_pdf", True):
if device.trashed is not None and self.request.POST.get("generate_pdf", True):
url += "?generate_pdf=handover"
if "comment" in self.request.POST:
url += "&comment={0}".format(self.request.POST["comment"])
Expand Down Expand Up @@ -938,7 +933,7 @@ def post(self, request, **kwargs):
messages.success(request, _("Device was trashed"))

url = reverse("device-detail", kwargs={"pk": device.pk})
if device.trashed != None and request.POST.get("generate_pdf", False):
if device.trashed is not None and request.POST.get("generate_pdf", False):
url += "?generate_pdf=trashed"
if "reason" in request.POST:
url += "&comment={0}".format(request.POST["reason"])
Expand Down Expand Up @@ -1555,7 +1550,7 @@ def generate_label_pdf(request, pk):
size = (size[0] - icon_size, size[1])
offset += icon_size + offset

barcode = code128.Code128('{:06d}'.format(pk), barHeight=size[1]/2, barWidth=2)
barcode = code128.Code128('{:06d}'.format(pk), barHeight=size[1] / 2, barWidth=2)
barcode._calculate()
width, height = barcode._width, barcode._height
barcode.drawOn(p, offset + (size[0] - width) / 2, (size[1] - height) / 2)
Expand All @@ -1575,6 +1570,7 @@ def generate_label_pdf(request, pk):
response['Content-Disposition'] = "filename=label_{0}.pdf".format(pk)
return response


def merge(overlay_canvas: io.BytesIO, template_path: str) -> io.BytesIO:
template_pdf = pdfrw.PdfReader(template_path)
overlay_pdf = pdfrw.PdfReader(overlay_canvas)
Expand All @@ -1586,6 +1582,7 @@ def merge(overlay_canvas: io.BytesIO, template_path: str) -> io.BytesIO:
form.seek(0)
return form


def generate_device_protocol(request, pk, purpose):
device = get_object_or_404(Device, pk=pk)

Expand Down Expand Up @@ -1615,9 +1612,9 @@ def generate_device_protocol(request, pk, purpose):
"department": str(device.department),
"comment": str(request.GET.get("comment", ""))
}
if device.currentlending != None:
if device.currentlending is not None:
data_map["recipient_name"] = str(device.currentlending.owner)

wrapper = textwrap.TextWrapper()
for (key, location) in text_locations.items():
if key in data_map:
Expand All @@ -1641,4 +1638,4 @@ def generate_device_protocol(request, pk, purpose):
# present the option to save the file.
response = HttpResponse(buffer, content_type='application/pdf')
response['Content-Disposition'] = "filename={0}_{1}.pdf".format(_("{0}_protocol".format(purpose)), pk)
return response
return response
32 changes: 0 additions & 32 deletions devices/views.test.py

This file was deleted.

2 changes: 1 addition & 1 deletion locations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def get_absolute_url(self):
return reverse('room-detail', kwargs={'pk': self.pk})

def get_edit_url(self):
return reverse('room-edit', kwargs={'pk': self.pk})
return reverse('room-edit', kwargs={'pk': self.pk})
2 changes: 1 addition & 1 deletion locations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,4 @@ def post(self, request, *args, **kwargs):
room.building = newobject
room.save()
oldobject.delete()
return HttpResponseRedirect(newobject.get_absolute_url())
return HttpResponseRedirect(newobject.get_absolute_url())
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ psycopg2-binary
faker~=4.1.1
reportlab
requests
pdfrw
5 changes: 5 additions & 0 deletions static/js/lagerregal.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@
event.preventDefault();
}
});

$(document).on('click', '[data-print-pdf]', function(event) {
var url = $(this).data('print-pdf');
printJS({printable: url, type:'pdf'});
});
});
})();
31 changes: 14 additions & 17 deletions templates/devices/detail/device_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@
<ul class="dropdown-menu" role="menu">
{% if display_printbutton %}
<li>
<a class="dropdown-item" href="#" data-target="#printDymoModal" data-toggle="modal">
<button class="dropdown-item" type="button" data-target="#printDymoModal" data-toggle="modal">
<i class="fa fa-print"></i> {% trans "Print Dymo Label" %}
</a>
</button>
</li>
{% endif %}
<li>
<button class="dropdown-item" href="#" onclick="printJS({printable: '{% url "device-generate-label" device.id %}', type:'pdf'})">
<button class="dropdown-item" type="button" data-print-pdf="{% url "device-generate-label" device.id %}">
<i class="fa fa-print"></i> {% trans "Print Label" %}
</button>
</li>
<li>
<button class="dropdown-item" href="#" onclick="printJS({printable: '{% url "device-generate-protocol" device.id "handover" %}', type:'pdf'})">
<button class="dropdown-item" type="button" data-print-pdf="{% url "device-generate-protocol" device.id "handover" %}">
<i class="fa fa-print"></i> {% trans "Print Handover Protocol" %}
</button>
</li>
<li>
<a class="dropdown-item" href="#" data-target="#pictureModal" data-toggle="modal">
<button class="dropdown-item" type="button" data-target="#pictureModal" data-toggle="modal">
<i class="fa fa-picture-o"></i> {% trans "Manage Pictures" %}
</a>
</button>
</li>
{% if can_change_device %}
<li>
Expand All @@ -107,8 +107,7 @@
<form action="{% url "device-storage" object.id %}" method="post"
data-confirm="{% trans "Are you sure?" %}">
{% csrf_token %}
<button class="dropdown-item"><i class="fa fa-folder"></i> {% trans "Move to storage" %}
</button>
<button class="dropdown-item"><i class="fa fa-folder"></i> {% trans "Move to storage" %}</button>
</form>
</li>
<li>
Expand All @@ -119,9 +118,9 @@
</form>
</li>
<li>
<a class="dropdown-item" href="#" data-target="#trashModal" data-toggle="modal">
<button class="dropdown-item" type="button" data-target="#trashModal" data-toggle="modal">
<i class="fa fa-trash-o"></i> {% trans "Trash" %}
</a>
</button>
</li>
{% endif %}
{% if can_delete_device %}
Expand All @@ -141,17 +140,15 @@
<form action="{% url "device-archive" object.id %}" method="post" data-confirm="{% trans "Are you sure?" %}"
class="d-inline-block">
{% csrf_token %}
<button class="btn btn-success btn-sm"><i class="fa fa-folder-open"></i> {% trans "Unarchive" %}
</button>
<button class="btn btn-success btn-sm"><i class="fa fa-folder-open"></i> {% trans "Unarchive" %}</button>
</form>
{% endif %}

{% if can_change_device and device.trashed != None %}
<form action="{% url "device-trash" object.id %}" method="post" data-confirm="{% trans "Are you sure?" %}"
class="d-inline-block">
{% csrf_token %}
<button class="btn btn-success btn-sm"><i class="fa fa-folder-open"></i> {% trans "Remove from Trash" %}
</button>
<button class="btn btn-success btn-sm"><i class="fa fa-folder-open"></i> {% trans "Remove from Trash" %}</button>
</form>
{% endif %}
{% endif %}
Expand Down Expand Up @@ -516,10 +513,10 @@ <h4>{% trans "Installed software from backend providers" %}</h4>
});
}

$("#softwaredetails").load("{% url "device-software" device.pk %}");
$("#softwaredetails").load("{% url "device-software" device.pk %}");

{% if generate_pdf %}
printJS({printable: '{% url "device-generate-protocol" device.id generate_pdf %}?comment={{ pdf_comment|urlencode }}', type:'pdf'})
printJS({printable: '{% url "device-generate-protocol" device.id generate_pdf %}?comment={{ pdf_comment|urlencode }}', type:'pdf'})
{% endif %}
});
{% endblock %}
19 changes: 19 additions & 0 deletions users/migrations/0023_alter_lageruser_timezone.py

Large diffs are not rendered by default.

0 comments on commit 9060858

Please sign in to comment.