aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2016-11-02 21:01:46 +0200
committerFilipp Lepalaan <filipp@mac.com>2016-11-02 21:01:46 +0200
commit9666c7aecd0867b17c0a03d8a24ea6ce733c85b2 (patch)
tree3a29d4d14ab13230b57d46980a9ae510a148848c /servo
parentf525019dc1dab61ae19ec493796083ebed492dab (diff)
downloadServo-9666c7aecd0867b17c0a03d8a24ea6ce733c85b2.tar.gz
Servo-9666c7aecd0867b17c0a03d8a24ea6ce733c85b2.tar.bz2
Servo-9666c7aecd0867b17c0a03d8a24ea6ce733c85b2.zip
Only show enabled locations in checkin
Diffstat (limited to 'servo')
-rw-r--r--servo/forms/checkin.py63
-rw-r--r--servo/models/common.py26
2 files changed, 39 insertions, 50 deletions
diff --git a/servo/forms/checkin.py b/servo/forms/checkin.py
index fdadb8e..31d28b5 100644
--- a/servo/forms/checkin.py
+++ b/servo/forms/checkin.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import gsxws
-import phonenumbers
from django import forms
from datetime import date
@@ -11,26 +10,29 @@ from django.core.validators import RegexValidator
from django.utils.translation import ugettext_lazy as _
from django.forms.extras.widgets import SelectDateWidget
-from servo.validators import apple_sn_validator, phone_validator, file_upload_validator
+from servo.validators import (apple_sn_validator,
+ phone_validator,
+ file_upload_validator,)
from servo.forms.base import SearchFieldInput
-from servo.models import (Configuration, Device,
+from servo.models import (Configuration, Device,
Attachment, Location,
Customer,)
# Generate list of years for purchase date picker
y = date.today().year
-YEARS = [x+1 for x in xrange(y-10, y)]
+YEARS = [x + 1 for x in xrange(y - 10, y)]
def get_checkin_locations(user):
+ """Return possible checkin location choices for this user."""
from servo.models import User
if user.is_authenticated():
- return user.locations.all()
+ return user.locations.enabled()
else:
user_id = Configuration.conf('checkin_user')
- return User.objects.get(pk=user_id).locations.all()
+ return User.objects.get(pk=user_id).locations.enabled()
class ConfirmationForm(forms.Form):
@@ -107,7 +109,7 @@ class DeviceForm(forms.ModelForm):
del(self.fields['imei'])
if not prod.is_mac:
del(self.fields['username'])
-
+
if Configuration.true('checkin_password'):
self.fields['password'].widget = forms.TextInput(attrs={'class': 'span12'})
@@ -115,17 +117,11 @@ class DeviceForm(forms.ModelForm):
class CustomerForm(forms.Form):
from django.utils.safestring import mark_safe
-
+
required_css_class = 'required'
- fname = forms.CharField(
- label=_('First name'),
- #initial='Filipp'
- )
- lname = forms.CharField(
- label=_('Last name'),
- #initial='Lepalaan'
- )
+ fname = forms.CharField(label=_('First name'))
+ lname = forms.CharField(label=_('Last name'))
company = forms.CharField(
required=False,
@@ -133,40 +129,31 @@ class CustomerForm(forms.Form):
)
email = forms.EmailField(
label=_('Email address'),
- widget=forms.TextInput(attrs={'class': 'span12'}),
- #initial='filipp@fps.ee'
+ widget=forms.TextInput(attrs={'class': 'span12'})
)
phone = forms.CharField(
label=_('Phone number'),
- validators=[phone_validator],
- #initial='12345678790'
- )
- address = forms.CharField(
- label=_('Address'),
- #initial='Example street'
+ validators=[phone_validator]
)
- country = forms.ChoiceField(label=_('Country'),
+ address = forms.CharField(label=_('Address'))
+ country = forms.ChoiceField(
+ label=_('Country'),
choices=Customer.COUNTRY_CHOICES,
- initial=settings.INSTALL_COUNTRY)
- city = forms.CharField(
- label=_('City'),
- #initial='Helsinki'
- )
- postal_code = forms.CharField(
- label=_('Postal Code'),
- #initial='000100'
+ initial=settings.INSTALL_COUNTRY
)
+ city = forms.CharField(label=_('City'))
+ postal_code = forms.CharField(label=_('Postal Code'))
checkin_location = forms.ModelChoiceField(
empty_label=None,
label=_(u'Check-in location'),
- queryset=Location.objects.all(),
+ queryset=Location.objects.enabled(),
widget=forms.Select(attrs={'class': 'span12'}),
help_text=_('Choose where you want to leave the device')
)
checkout_location = forms.ModelChoiceField(
empty_label=None,
label=_(u'Check-out location'),
- queryset=Location.objects.all(),
+ queryset=Location.objects.enabled(),
widget=forms.Select(attrs={'class': 'span12'}),
help_text=_('Choose where you want to pick up the device')
)
@@ -195,10 +182,9 @@ class CustomerForm(forms.Form):
def __init__(self, request, *args, **kwargs):
super(CustomerForm, self).__init__(*args, **kwargs)
- user = request.user
location = request.session['checkin_location']
- locations = get_checkin_locations(user)
+ locations = get_checkin_locations(request.user)
self.fields['checkin_location'].queryset = locations
self.fields['checkin_location'].initial = location
@@ -213,7 +199,6 @@ class CustomerForm(forms.Form):
class AppleSerialNumberForm(forms.Form):
sn = forms.CharField(
min_length=8,
- #initial='C34JTVKYDTWF',
validators=[apple_sn_validator],
label=_(u'Serial number or IMEI')
)
@@ -226,7 +211,6 @@ class AppleSerialNumberForm(forms.Form):
class SerialNumberForm(forms.Form):
sn = forms.CharField(
min_length=8,
- initial='C34JTVKYDTWF',
label=_(u'Serial number')
)
@@ -277,4 +261,3 @@ class AttachmentForm(forms.ModelForm):
class Meta:
model = Attachment
exclude = []
-
diff --git a/servo/models/common.py b/servo/models/common.py
index 7a1c79c..1f9af7c 100644
--- a/servo/models/common.py
+++ b/servo/models/common.py
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
-import re
import gsxws
import os.path
-from decimal import Decimal
from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify
from pytz import common_timezones, country_timezones
@@ -386,10 +384,17 @@ class Tag(MPTTModel):
order_insertion_by = ['title']
+class LocationManager(models.Manager):
+ """Custom model manager for enabled locations."""
+
+ def enabled(self, **kwargs):
+ """Only locations that are marked as enabled."""
+ return self.filter(enabled=True, **kwargs)
+
+
class Location(models.Model):
- """
- A Service Location within a company
- """
+ """A Service Location within a company."""
+
site = models.ForeignKey(
Site,
editable=False,
@@ -465,8 +470,8 @@ class Location(models.Model):
notes = models.TextField(
blank=True,
- default='9:00 - 18:00',
verbose_name=_('Notes'),
+ default=_('Business hours between 9:00 - 18:00'),
help_text=_('Will be shown on print templates')
)
@@ -488,6 +493,8 @@ class Location(models.Model):
verbose_name=_('Use for check-in')
)
+ objects = LocationManager()
+
@classmethod
def get_checkin_list(cls):
results = []
@@ -648,7 +655,7 @@ class Configuration(models.Model):
config = super(Configuration, self).save(*args, **kwargs)
# Using cache instead of session since it's shared among
# all the users of the instance
- cache.set('config', config, 60*60*24*1)
+ cache.set('config', config, 60 * 60 * 24 * 1)
class Meta:
app_label = 'servo'
@@ -764,9 +771,8 @@ class Template(models.Model):
class Attachment(BaseItem):
- """
- A file attached to something
- """
+ """A file attached to something."""
+
mime_type = models.CharField(max_length=64, editable=False)
content = models.FileField(
upload_to='attachments',