# -*- coding: utf-8 -*- from django import forms from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from servo.models import Tag, Device, Customer from servo.forms import DatepickerInput, AutocompleteCharField product_lines = [(k, x['name']) for k, x in Device.PRODUCT_LINES.items()] class DeviceSearchForm(forms.Form): product_line = forms.MultipleChoiceField( choices=product_lines, required=False ) warranty_status = forms.MultipleChoiceField( choices=Device.WARRANTY_CHOICES, required=False, ) date_start = forms.DateField( required=False, label=_('Created between'), widget=DatepickerInput(attrs={'class': 'input-small'}) ) date_end = forms.DateField( required=False, label=mark_safe(' '), widget=DatepickerInput(attrs={'class': 'input-small'}) ) sn = forms.CharField(required=False, label=_('Serial number contains')) def __init__(self, *args, **kwargs): super(DeviceSearchForm, self).__init__(*args, **kwargs) self.fields['description'] = AutocompleteCharField( '/api/device_models/', max_length=128, required=False, label=_('Description contains') ) class DeviceForm(forms.ModelForm): class Meta: model = Device exclude = ('spec', 'customers', 'files', 'image_url', 'exploded_view_url', 'manual_url', ) widgets = {'purchased_on': DatepickerInput()} tags = forms.ModelMultipleChoiceField( queryset=Tag.objects.filter(type='device'), required=False ) class DeviceUploadForm(forms.Form): datafile = forms.FileField( help_text=_('Device data in Excel format (.xls or .xlsx)') ) customer = forms.IntegerField( required=False, widget=forms.HiddenInput, ) do_warranty_check = forms.BooleanField( required=False, initial=True, help_text=_('Perform warranty check on uploaded serial numbers') ) class DiagnosticsForm(forms.Form): pass