Skip to content

Commit

Permalink
Refactor select2 (#242)
Browse files Browse the repository at this point in the history
use django-select2
  • Loading branch information
xi authored and octomike committed Oct 9, 2018
1 parent 3344248 commit a0faf57
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 730 deletions.
4 changes: 4 additions & 0 deletions Lagerregal/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
'permission',
'debug_toolbar',
'oauth2_provider',
'django_select2',
)

LANGUAGES = (
Expand Down Expand Up @@ -194,6 +195,9 @@

FAVICON_PATH = STATIC_URL + 'images/favicon.ico'

SELECT2_JS = ''
SELECT2_CSS = ''

TEST_RUNNER = 'Lagerregal.utils.DetectableTestRunner'
TEST_MODE = False
DEMO_MODE = False
1 change: 1 addition & 0 deletions dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ django-casper
django-permission
django_auth_ldap
django-favicon
django-select2
psycopg2-binary
37 changes: 20 additions & 17 deletions devices/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from django.utils.translation import ugettext_lazy as _
from django.db.utils import OperationalError, ProgrammingError

from django_select2.forms import Select2Widget
from django_select2.forms import Select2MultipleWidget

from network.models import IpAddress
from devices.models import Device, Type, Room, Manufacturer
from devicetypes.models import TypeAttribute, TypeAttributeValue
Expand Down Expand Up @@ -100,7 +103,7 @@ class IpAddressForm(forms.Form):
error_css_class = 'has-error'
ipaddresses = forms.ModelMultipleChoiceField(
IpAddress.objects.filter(device=None, user=None),
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;", "data-token-separators": '[",", " "]'}))
device = forms.ModelChoiceField(Device.objects.all())


Expand All @@ -114,55 +117,55 @@ class SearchForm(forms.Form):
searchname = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search name", "class": "form-control input-sm"}), required=False)
namemodifier = forms.ChoiceField(choices=CHARMODIFIER,
widget=forms.Select(attrs={"class": "form-control input-sm"}))
widget=Select2Widget(attrs={"class": "form-control input-sm"}))

inventorynumber = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search inventorynumber", "class": "form-control input-sm"}),
required=False)
inventorynumbermodifier = forms.ChoiceField(choices=CHARMODIFIER,
widget=forms.Select(attrs={"class": "form-control input-sm"}),
widget=Select2Widget(attrs={"class": "form-control input-sm"}),
required=False)

serialnumber = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search serialnumber", "class": "form-control input-sm"}),
required=False)
serialnumbermodifier = forms.ChoiceField(choices=CHARMODIFIER,
widget=forms.Select(attrs={"class": "form-control input-sm"}),
widget=Select2Widget(attrs={"class": "form-control input-sm"}),
required=False)

macaddress = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search MAC-Address", "class": "form-control input-sm"}),
required=False)
macaddressmodifier = forms.ChoiceField(choices=CHARMODIFIER,
widget=forms.Select(attrs={"class": "form-control input-sm"}),
widget=Select2Widget(attrs={"class": "form-control input-sm"}),
required=False)

devicetype = forms.ModelMultipleChoiceField(Type.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;"}))
manufacturer = forms.ModelMultipleChoiceField(Manufacturer.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;"}))
devicegroup = forms.ModelMultipleChoiceField(Devicegroup.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;"}))
room = forms.ModelMultipleChoiceField(Room.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;"}))
ipaddress = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search IP-Address", "class": "form-control input-sm"}),
required=False)
overdue = forms.ChoiceField(choices=(('b', 'both'), ('y', 'Yes'), ('n', 'No'),), required=False,
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))

viewfilter = forms.ChoiceField(choices=VIEWFILTER, required=False,
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))
lender = forms.CharField(
widget=forms.TextInput(attrs={"placeholder": "Search Lender", "class": "form-control input-sm"}),
required=False)


class LendForm(forms.Form):
error_css_class = 'has-error'
owner = forms.ModelChoiceField(Lageruser.objects.all(), widget=forms.Select(attrs={"style": "width:100%;"}),
owner = forms.ModelChoiceField(Lageruser.objects.all(), widget=Select2Widget(attrs={"style": "width:100%;"}),
label=_("Lent to"))
device = forms.ModelChoiceField(Device.objects.all(), widget=forms.Select(attrs={"style": "width:100%;"}),
device = forms.ModelChoiceField(Device.objects.all(), widget=Select2Widget(attrs={"style": "width:100%;"}),
label=_("Device"), required=False)
smalldevice = forms.CharField(widget=forms.TextInput(attrs={"class": "form-control input-sm"}), required=False)
duedate = forms.DateField(required=False, input_formats=('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y',
Expand Down Expand Up @@ -256,7 +259,7 @@ class DeviceForm(forms.ModelForm):
uses = forms.MultipleChoiceField(choices=Device.objects.none(), required=False)
emailrecipients = forms.MultipleChoiceField(required=False)
emailtemplate = forms.ModelChoiceField(queryset=MailTemplate.objects.all(), required=False, label=_("Template"),
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))
emailedit = forms.BooleanField(required=False, label=_("Edit template"))
emailsubject = forms.CharField(required=False, label=_("Subject"))
emailbody = forms.CharField(widget=forms.Textarea(), required=False, label=_("Body"))
Expand All @@ -267,11 +270,11 @@ class DeviceForm(forms.ModelForm):
creator = forms.ModelChoiceField(queryset=Lageruser.objects.all(), widget=forms.HiddenInput())
comment = forms.CharField(required=False)
devicetype = forms.ModelChoiceField(Type.objects.all(), required=False,
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))
manufacturer = forms.ModelChoiceField(Manufacturer.objects.all(), required=False,
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))
room = forms.ModelChoiceField(Room.objects.select_related("building").all(), required=False,
widget=forms.Select(attrs={"style": "width:100%;"}))
widget=Select2Widget(attrs={"style": "width:100%;"}))

class Meta:
model = Device
Expand Down
4 changes: 3 additions & 1 deletion devicetags/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django import forms

from django_select2.forms import Select2MultipleWidget

from devicetags.models import Devicetag
from devices.models import Device

Expand All @@ -16,5 +18,5 @@ class DeviceTagForm(forms.Form):
error_css_class = 'has-error'
tags = forms.ModelMultipleChoiceField(
Devicetag.objects.all(),
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;", "data-token-separators": '[",", " "]'}))
device = forms.ModelChoiceField(Device.objects.all())
9 changes: 6 additions & 3 deletions network/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from django import forms
from django.utils.translation import ugettext_lazy as _

from django_select2.forms import Select2Widget
from django_select2.forms import Select2MultipleWidget

from network.models import IpAddress
from users.models import Lageruser
from devices.forms import get_department_options
Expand Down Expand Up @@ -30,16 +33,16 @@ def clean(self):

class ViewForm(forms.Form):
viewfilter = forms.ChoiceField(choices=VIEWFILTER,
widget=forms.Select(attrs={"style": "width:200px;margin-left:10px;",
widget=Select2Widget(attrs={"style": "width:200px;margin-left:10px;",
"class": "pull-right input-sm form-control"}))
departmentfilter = forms.ChoiceField(choices=get_department_options(),
widget=forms.Select(attrs={"style": "width:150px;margin-left:10px;",
widget=Select2Widget(attrs={"style": "width:150px;margin-left:10px;",
"class": "pull-right form-control input-sm"}))


class UserIpAddressForm(forms.Form):
error_css_class = 'has-error'
ipaddresses = forms.ModelMultipleChoiceField(
IpAddress.objects.filter(device=None, user=None),
widget=forms.SelectMultiple(attrs={"style": "width:100%;"}))
widget=Select2MultipleWidget(attrs={"style": "width:100%;", "data-token-separators": '[",", " "]'}))
user = forms.ModelChoiceField(Lageruser.objects.all())
Loading

0 comments on commit a0faf57

Please sign in to comment.