Skip to content

Commit

Permalink
Merge branch 'develop' into release_2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
octomike committed Sep 15, 2019
2 parents 31eef07 + 692f283 commit 1d426c0
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 113 deletions.
9 changes: 6 additions & 3 deletions devicegroups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
context["breadcrumbs"] = [
(reverse("devicegroup-list"), _("Devicegroups"))]
context["viewform"] = DepartmentViewForm(initial={"sorting": self.viewsorting,
"department": self.departmentfilter})
(reverse("devicegroup-list"), _("Devicegroups"))
]
context["viewform"] = DepartmentViewForm(initial={
"sorting": self.viewsorting,
"department": self.departmentfilter,
})

# filtering
if self.filterstring:
Expand Down
77 changes: 49 additions & 28 deletions devices/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def get(self, request):
else:
return HttpResponse("")
if len(objects) > 0:
retobjects = ["<li><a href='{0}' class='alert-link'>{1}</a></li>".format(
reverse(urlname, kwargs={"pk": obj[0]}), obj[1])
for obj in objects.values_list("pk", "name")]
retobjects = [
"<li><a href='{0}' class='alert-link'>{1}</a></li>".format(
reverse(urlname, kwargs={"pk": obj[0]}), obj[1]
) for obj in objects.values_list("pk", "name")
]
return HttpResponse(json.dumps(retobjects), content_type='application/json')
else:
return HttpResponse("")
Expand Down Expand Up @@ -216,30 +218,42 @@ def get(self, request):
return HttpResponse("")
user = get_object_or_404(Lageruser, pk=user)
data = {}
data["devices"] = [[device["device__name"] if device["device__name"] else device["smalldevice"],
device["device__inventorynumber"], device["device__serialnumber"],
device["duedate"].strftime("%d.%m.%y") if device["duedate"] else "", device["pk"]]
for device in user.lending_set.filter(returndate=None).values("pk", "device__name",
"device__inventorynumber",
"device__serialnumber",
"smalldevice", "duedate")]
data["devices"] = [
[
device["device__name"] if device["device__name"] else device["smalldevice"],
device["device__inventorynumber"],
device["device__serialnumber"],
device["duedate"].strftime("%d.%m.%y") if device["duedate"] else "",
device["pk"],
]
for device in user.lending_set.filter(returndate=None).values(
"pk", "device__name", "device__inventorynumber",
"device__serialnumber", "smalldevice", "duedate",
)
]

return HttpResponse(json.dumps(data), content_type='application/json')


class PuppetDetails(View):

def get(self, request, device):
params = urllib.parse.urlencode({'query': '["in", "certname",["extract", "certname",'
+ '["select_facts",["and",["=", "name","'
+ settings.PUPPETDB_SETTINGS['query_fact'] + '"],'
+ '["=","value","' + str(device) + '"]]]]]'})
query = (
'["in", "certname", ["extract", "certname", ["select_facts", '
'["and", ["=", "name", "{}"], ["=", "value", "{}"]]]]]'
).format(settings.PUPPETDB_SETTINGS['query_fact'], str(device))
params = urllib.parse.urlencode({'query': query})

context = ssl.create_default_context(cafile=settings.PUPPETDB_SETTINGS['cacert'])
context.load_cert_chain(certfile=settings.PUPPETDB_SETTINGS['cert'],
keyfile=settings.PUPPETDB_SETTINGS['key'])
conn = http.client.HTTPSConnection(settings.PUPPETDB_SETTINGS['host'],
settings.PUPPETDB_SETTINGS['port'],
context=context)
context.load_cert_chain(
certfile=settings.PUPPETDB_SETTINGS['cert'],
keyfile=settings.PUPPETDB_SETTINGS['key'],
)
conn = http.client.HTTPSConnection(
settings.PUPPETDB_SETTINGS['host'],
settings.PUPPETDB_SETTINGS['port'],
context=context,
)
conn.request("GET", settings.PUPPETDB_SETTINGS['req'] + params)
res = conn.getresponse()
if res.status != http.client.OK:
Expand All @@ -257,16 +271,23 @@ def get(self, request, device):
software_fact = settings.PUPPETDB_SETTINGS['software_fact']
query_fact = settings.PUPPETDB_SETTINGS['query_fact']

params = urllib.parse.urlencode({'query': '["and", [ "=", "name", "' + software_fact + '"],'
+ '["in", "certname",["extract", "certname",'
+ '["select_facts",["and",["=", "name","' + query_fact + '"],'
+ '["=","value","' + str(device) + '"]]]]]]'})
query = (
'["and", ["=", "name", "{}"], ["in", "certname", '
'["extract", "certname", ["select_facts", ["and", '
'["=", "name", "{}"], ["=", "value", "{}"]]]]]]'
).format(software_fact, query_fact, str(device))
params = urllib.parse.urlencode({'query': query})

context = ssl.create_default_context(cafile=settings.PUPPETDB_SETTINGS['cacert'])
context.load_cert_chain(certfile=settings.PUPPETDB_SETTINGS['cert'],
keyfile=settings.PUPPETDB_SETTINGS['key'])
conn = http.client.HTTPSConnection(settings.PUPPETDB_SETTINGS['host'],
settings.PUPPETDB_SETTINGS['port'],
context=context)
context.load_cert_chain(
certfile=settings.PUPPETDB_SETTINGS['cert'],
keyfile=settings.PUPPETDB_SETTINGS['key'],
)
conn = http.client.HTTPSConnection(
settings.PUPPETDB_SETTINGS['host'],
settings.PUPPETDB_SETTINGS['port'],
context=context,
)
conn.request("GET", settings.PUPPETDB_SETTINGS['req'] + params)
res = conn.getresponse()
if res.status != http.client.OK:
Expand Down
20 changes: 10 additions & 10 deletions devices/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ def get_emailrecipientlist(special=None):
objects = []

if special:
objects.append((_("Special"),
[(value, key) for key, value in special.items()]
))

objects.append((_("Groups"),
[("g" + str(group.id), group.name) for group in Group.objects.all().order_by("name")],
))
objects.append((_("People"),
[("u" + str(user.id), user) for user in Lageruser.objects.all().order_by("last_name")],
))
objects.append(
(_("Special"), [(value, key) for key, value in special.items()])
)

objects.append(
(_("Groups"), [("g" + str(group.id), group.name) for group in Group.objects.all().order_by("name")])
)
objects.append(
(_("People"), [("u" + str(user.id), user) for user in Lageruser.objects.all().order_by("last_name")])
)
return objects


Expand Down
6 changes: 3 additions & 3 deletions devices/management/commands/ldapimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def handle(self, *args, **options):
print("You have to enable the USE_LDAP setting to use the ldap import.")
return
# ldap.set_option(ldap.OPT_DEBUG_LEVEL, 4095)
l = PagedResultsSearchObject(settings.AUTH_LDAP_SERVER_URI)
l.simple_bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
search = PagedResultsSearchObject(settings.AUTH_LDAP_SERVER_URI)
search.simple_bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
created_users = 0
updated_users = 0
skipped_users = 0
page_count, users = l.paged_search_ext_s(*settings.LDAP_USER_SEARCH)
page_count, users = search.paged_search_ext_s(*settings.LDAP_USER_SEARCH)
attr_map = settings.AUTH_LDAP_USER_ATTR_MAP
attr_map.update({'main_department': settings.AUTH_LDAP_DEPARTMENT_FIELD})

Expand Down
35 changes: 21 additions & 14 deletions devices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ def post(self, request):
class DeviceDetail(PermissionRequiredMixin, DetailView):
# get related data to chosen device
queryset = Device.objects \
.select_related("manufacturer", "devicetype", "currentlending", "currentlending__owner", "department",
"room", "room__building") \
.prefetch_related("pictures", )
.select_related(
"manufacturer", "devicetype", "currentlending",
"currentlending__owner", "department", "room", "room__building",
)\
.prefetch_related("pictures")
context_object_name = 'device'
object = None
permission_required = 'devices.view_device'
Expand Down Expand Up @@ -226,15 +228,20 @@ def get_context_data(self, **kwargs):
context['tagform'].fields["tags"].queryset = Devicetag.objects.exclude(devices=context["device"])

# lending history, eidt history, mail history
context["lending_list"] = Lending.objects.filter(device=context["device"])\
.select_related("owner").order_by("-pk")[:10]
context["version_list"] = Version.objects.filter(object_id=context["device"].id,
content_type_id=ContentType.objects.get(
model='device').id) \
.select_related("revision", "revision__user").order_by("-pk")[:10]
context["lending_list"] = Lending.objects\
.filter(device=context["device"])\
.select_related("owner")\
.order_by("-pk")[:10]
context["version_list"] = Version.objects\
.filter(object_id=context["device"].id,
content_type_id=ContentType.objects.get(model='device').id) \
.select_related("revision", "revision__user")\
.order_by("-pk")[:10]
context['content_type'] = ContentType.objects.get(model='device').id
context["mail_list"] = MailHistory.objects.filter(device=context["device"])\
.select_related("sent_by").order_by("-pk")[:10]
context["mail_list"] = MailHistory.objects\
.filter(device=context["device"])\
.select_related("sent_by")\
.order_by("-pk")[:10]

context["today"] = datetime.date.today()
context["weekago"] = context["today"] - datetime.timedelta(days=7)
Expand Down Expand Up @@ -1677,7 +1684,7 @@ def get_context_data(self, **kwargs):
context["breadcrumbs"] = [("", _("Search"))]
context["searchstring"] = self.get_searchstring()
context["keys"] = sorted(list(self.STRING_FIELDS.keys())
+ list(self.DATE_FIELDS.keys()))
+ list(self.DATE_FIELDS.keys()))
return context


Expand All @@ -1703,8 +1710,8 @@ def get_queryset(self):
if self.groupfilter != "all":
devices = devices.filter(group__id=self.groupfilter)
return devices.values("id", "name", "inventorynumber", "devicetype__name", "room__name",
"room__building__name",
"group__name", "currentlending__owner__username", "currentlending__duedate")
"room__building__name",
"group__name", "currentlending__owner__username", "currentlending__duedate")

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down
22 changes: 16 additions & 6 deletions history/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@


class Globalhistory(PermissionRequiredMixin, PaginationMixin, ListView):
queryset = Revision.objects.select_related("user").prefetch_related("version_set", "version_set__content_type"
).filter().order_by("-date_created")
queryset = Revision.objects\
.select_related("user")\
.prefetch_related("version_set", "version_set__content_type")\
.order_by("-date_created")
context_object_name = "revision_list"
template_name = 'history/globalhistory.html'
permission_required = 'devices.change_device'
Expand Down Expand Up @@ -84,9 +86,13 @@ class HistoryDetail(PermissionRequiredMixin, UpdateView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
model = apps.get_model(
context["this_version"].content_type.app_label,
context["this_version"].content_type.model,
)
context["current_version"] = get_object_or_404(
apps.get_model(context["this_version"].content_type.app_label, context["this_version"].content_type.model),
id=context["this_version"].object_id)
model, id=context["this_version"].object_id
)

context["this_version"] = cleanup_fielddict(context["this_version"])

Expand Down Expand Up @@ -135,8 +141,12 @@ def post(self, request, *args, **kwargs):
TypeAttributeValue.objects.filter(device=version.object_id).delete()
reversion.set_comment("Reverted to version from {0}".format(version.revision.date_created))

messages.success(self.request,
_('Successfully reverted Device to revision {0}').format(version.revision.id))
messages.success(
self.request,
_('Successfully reverted Device to revision {0}').format(
version.revision.id
),
)

return HttpResponseRedirect(object.get_absolute_url())

Expand Down
6 changes: 4 additions & 2 deletions mail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def send(self, request, recipients=None, data=None):
"inventorynumber": data["device"].inventorynumber,
"manufacturer": data["device"].manufacturer,
"name": str(data["device"]),
"room": (data["device"].room.name + " (" + data["device"].room.building.name + ")" if data[
"device"].room is not None else ""),
"room": '' if data["device"].room is None else '{} ({})'.format(
data["device"].room.name,
data["device"].room.building.name,
),
"serialnumber": data["device"].serialnumber,
"templending": data["device"].templending,
"trashed": data["device"].trashed,
Expand Down
Loading

0 comments on commit 1d426c0

Please sign in to comment.