Skip to content

Commit

Permalink
Merge pull request #11 from moshthepitt/ikigai-fixes
Browse files Browse the repository at this point in the history
Ikigai fixes
  • Loading branch information
moshthepitt authored Jun 25, 2018
2 parents 44ae7ba + ef1dcfa commit 040277d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion small_small_hr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Main init file for small_small_hr
"""
VERSION = (0, 0, 6)
VERSION = (0, 0, 7)
__version__ = '.'.join(str(v) for v in VERSION)
85 changes: 74 additions & 11 deletions small_small_hr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def clean(self):
# pylint: disable=no-member
overlap_qs = OverTime.objects.filter(
date=date, staff=staff, status=OverTime.APPROVED).filter(
Q(start__gte=start) | Q(end__lte=end))
Q(start__gte=start) & Q(end__lte=end))

if self.instance is not None:
overlap_qs = overlap_qs.exclude(id=self.instance.id)
Expand Down Expand Up @@ -190,8 +190,17 @@ class Meta: # pylint: disable=too-few-public-methods
]

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
self.request = kwargs.pop('request', None)
if self.request:
# pylint: disable=no-member
try:
self.request.user.staffprofile
except StaffProfile.DoesNotExist:
pass
else:
self.fields['staff'].queryset = StaffProfile.objects.filter(
id=self.request.user.staffprofile.id)
self.helper = FormHelper()
self.helper.form_tag = True
self.helper.form_method = 'post'
Expand All @@ -200,7 +209,7 @@ def __init__(self, *args, **kwargs):
self.helper.html5_required = True
self.helper.form_id = 'overtime-application-form'
self.helper.layout = Layout(
Field('staff',),
Field('staff', type="hidden"),
Field('date',),
Field('start',),
Field('end',),
Expand Down Expand Up @@ -323,7 +332,7 @@ def clean(self):
staff=staff,
status=Leave.APPROVED,
leave_type=leave_type).filter(
Q(start__gte=start) | Q(end__lte=end))
Q(start__gte=start) & Q(end__lte=end))

if self.instance is not None:
overlap_qs = overlap_qs.exclude(id=self.instance.id)
Expand Down Expand Up @@ -353,8 +362,17 @@ class Meta: # pylint: disable=too-few-public-methods
]

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
self.request = kwargs.pop('request', None)
if self.request:
# pylint: disable=no-member
try:
self.request.user.staffprofile
except StaffProfile.DoesNotExist:
pass
else:
self.fields['staff'].queryset = StaffProfile.objects.filter(
id=self.request.user.staffprofile.id)
self.helper = FormHelper()
self.helper.form_tag = True
self.helper.form_method = 'post'
Expand All @@ -363,7 +381,7 @@ def __init__(self, *args, **kwargs):
self.helper.html5_required = True
self.helper.form_id = 'leave-application-form'
self.helper.layout = Layout(
Field('staff',),
Field('staff', type="hidden"),
Field('leave_type',),
Field('start',),
Field('end',),
Expand Down Expand Up @@ -412,6 +430,53 @@ def __init__(self, *args, **kwargs):
)


class UserStaffDocumentForm(forms.ModelForm):
"""
Form used when managing one's own StaffDocument objects
"""

class Meta: # pylint: disable=too-few-public-methods
"""
Class meta options
"""
model = StaffDocument
fields = [
'staff',
'name',
'description',
'file',
]

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
if self.request:
# pylint: disable=no-member
try:
self.request.user.staffprofile
except StaffProfile.DoesNotExist:
pass
else:
self.fields['staff'].queryset = StaffProfile.objects.filter(
id=self.request.user.staffprofile.id)
self.helper = FormHelper()
self.helper.form_tag = True
self.helper.form_method = 'post'
self.helper.render_required_fields = True
self.helper.form_show_labels = True
self.helper.html5_required = True
self.helper.form_id = 'staffdocument-form'
self.helper.layout = Layout(
Field('staff', type="hidden"),
Field('name',),
Field('description',),
Field('file',),
FormActions(
Submit('submitBtn', _('Submit'), css_class='btn-primary'),
)
)


class StaffProfileAdminForm(forms.ModelForm):
"""
Form used when managing StaffProfile objects
Expand Down Expand Up @@ -509,7 +574,7 @@ def clean_nssf(self):
"""
value = self.cleaned_data.get('nssf')
# pylint: disable=no-member
if StaffProfile.objects.exclude(
if value and StaffProfile.objects.exclude(
id=self.instance.id).filter(data__nssf=value).exists():
raise forms.ValidationError(
_('This NSSF number is already in use.'))
Expand All @@ -521,7 +586,7 @@ def clean_nhif(self):
"""
value = self.cleaned_data.get('nhif')
# pylint: disable=no-member
if StaffProfile.objects.exclude(
if value and StaffProfile.objects.exclude(
id=self.instance.id).filter(data__nhif=value).exists():
raise forms.ValidationError(
_('This NHIF number is already in use.'))
Expand All @@ -533,7 +598,7 @@ def clean_pin_number(self):
"""
value = self.cleaned_data.get('pin_number')
# pylint: disable=no-member
if StaffProfile.objects.exclude(
if value and StaffProfile.objects.exclude(
id=self.instance.id).filter(data__pin_number=value).exists():
raise forms.ValidationError(
_('This PIN number is already in use.'))
Expand Down Expand Up @@ -658,7 +723,6 @@ class Meta: # pylint: disable=too-few-public-methods
'id_number',
'phone',
'sex',
'role',
'nhif',
'nssf',
'pin_number',
Expand All @@ -685,7 +749,6 @@ def __init__(self, *args, **kwargs):
Field('phone',),
Field('id_number',),
Field('sex',),
Field('role',),
Field('nhif',),
Field('nssf',),
Field('pin_number',),
Expand Down

0 comments on commit 040277d

Please sign in to comment.