Skip to content

Commit

Permalink
Merge pull request #100 from BenediktMKuehne/95-different-lengths-of-…
Browse files Browse the repository at this point in the history
…labels-on-x-axis

truncate linux-strings
  • Loading branch information
m-1-k-3 authored Mar 30, 2023
2 parents abfbe1a + f17e0fe commit 7c70218
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions embark/embark/settings/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
},
'reporter': {
'handlers': ['debug_handler', 'info_handler', 'console_handler'],
'level': 'DEBUG',
'level': 'INFO',
},
'tracker': {
'handlers': ['debug_handler', 'info_handler', 'console_handler'],
'level': 'INFO',
},
'porter': {
'handlers': ['debug_handler', 'info_handler', 'console_handler'],
'level': 'DEBUG', # TODO change to INFO
'level': 'INFO',
},
'embark': {
'handlers': ['debug_handler', 'info_handler', 'console_handler'],
Expand Down
11 changes: 6 additions & 5 deletions embark/reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,17 @@ def get_accumulated_reports(request):
strcpy_bins[key] += int(strcpy_bin[key])

for charfield in charfields:
# clean-up for linux extensive os-descriptions
if charfield.startswith("Linux"):
charfield = charfield.split("/", 2)[:2]
charfield = f"{charfield[0]}{charfield[1]}"
charfield = (charfield[:16] + '..') if len(charfield) > 18 else charfield

if charfield not in data:
data[charfield] = {}

value = result.pop(charfield)

# clean-up for linux extensive os-descriptions
if value.startswith("Linux"):
value = value.split("/", 2)[:2]
value = (value[:16] + '..') if len(value) > 18 else value

if value not in data[charfield]:
data[charfield][value] = 0

Expand Down
9 changes: 9 additions & 0 deletions embark/uploader/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class Meta:

fields = ['device_name', 'device_label', 'device_vendor']

def clean(self):
cleaned_data = super().clean()
name = cleaned_data.get('device_name')
vendor = cleaned_data.get('device_vendor')
if name and vendor:
if models.Device.objects.filter(device_name=name, device_vendor=vendor).exists():
self.add_error('device_name', 'device already created')
return cleaned_data


class FirmwareAnalysisForm(forms.ModelForm):
MODULE_CHOICES = [
Expand Down
35 changes: 14 additions & 21 deletions embark/uploader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from uploader.boundedexecutor import BoundedExecutor
from uploader.forms import DeviceForm, FirmwareAnalysisForm, DeleteFirmwareForm, LabelForm, VendorForm
from uploader.models import Device, FirmwareFile, Label, Vendor
from uploader.models import FirmwareFile

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,17 +63,16 @@ def device_setup(request):
form = DeviceForm(request.POST)
if form.is_valid():
logger.info("User %s tryied to create device", request.user.username)

new_device = form.save(commit=False)
new_device.device_user = request.user
if Device.objects.filter(device_name=request.device_name, device_vendor=request.device_vendor).exists():
messages.error(request, 'Device already exists')
return redirect('..')
new_device = form.save()
messages.info(request, 'creation successful of ' + str(new_device))
return redirect('..')
logger.error("device form invalid %s ", request.POST)
messages.error(request, 'creation failed.')
if 'device_name' in form.errors:
messages.error(request, 'Device already exists')
else:
messages.error(request, 'creation failed.')
return redirect('..')


Expand All @@ -84,17 +83,14 @@ def vendor(request):
form = VendorForm(request.POST)
if form.is_valid():
logger.info("User %s tryied to create vendor %s", request.user.username, request.POST['vendor_name'])

new_vendor = form.save(commit=False)
if Vendor.objects.filter(vendor_name=request.vendor_name).exists():
messages.error(request, 'Vendor already exists')
return redirect('..')
new_vendor = form.save()

messages.info(request, 'creation successful of ' + str(new_vendor))
return redirect('..')
logger.error("vendor form invalid %s ", request.POST)
messages.error(request, 'creation failed.')
if 'vendor_name' in form.errors:
messages.error(request, 'Vendor already exists')
else:
messages.error(request, 'creation failed.')
return redirect('..')


Expand All @@ -105,17 +101,14 @@ def label(request):
form = LabelForm(request.POST)
if form.is_valid():
logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name'])

new_label = form.save(commit=False)
if Label.objects.filter(label_name=request.label_name).exists():
messages.error(request, 'Label already exists')
return redirect('..')
new_label = form.save()

messages.info(request, 'creation successful of' + str(new_label))
messages.info(request, 'creation successful of ' + str(new_label))
return redirect('..')
logger.error("label form invalid %s ", request.POST)
messages.error(request, 'creation failed.')
if 'label_name' in form.errors:
messages.error(request, 'Label already exists')
else:
messages.error(request, 'creation failed.')
return redirect('..')


Expand Down

0 comments on commit 7c70218

Please sign in to comment.