diff --git a/embark/embark/settings/deploy.py b/embark/embark/settings/deploy.py index 7b6f8f157..e8a8e2ca7 100644 --- a/embark/embark/settings/deploy.py +++ b/embark/embark/settings/deploy.py @@ -178,7 +178,7 @@ }, 'reporter': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], - 'level': 'DEBUG', + 'level': 'INFO', }, 'tracker': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], @@ -186,7 +186,7 @@ }, 'porter': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], - 'level': 'DEBUG', # TODO change to INFO + 'level': 'INFO', }, 'embark': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], diff --git a/embark/reporter/views.py b/embark/reporter/views.py index cb8c9629e..46baafcbf 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -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 diff --git a/embark/uploader/forms.py b/embark/uploader/forms.py index 809c7255e..9e2955ed0 100644 --- a/embark/uploader/forms.py +++ b/embark/uploader/forms.py @@ -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 = [ diff --git a/embark/uploader/views.py b/embark/uploader/views.py index dfefad16e..a28acd3a2 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -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__) @@ -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('..') @@ -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('..') @@ -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('..')