Skip to content

Commit

Permalink
Merge pull request #5 from moshthepitt/issue-2
Browse files Browse the repository at this point in the history
Disconnect create_staffprofile
  • Loading branch information
moshthepitt authored Jun 19, 2018
2 parents 73bda23 + 6f9569e commit 2c56a68
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 41 deletions.
73 changes: 73 additions & 0 deletions small_small_hr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _

import pytz
Expand Down Expand Up @@ -484,6 +485,78 @@ def save(self, commit=True): # pylint: disable=unused-argument
return staffprofile


class StaffProfileAdminCreateForm(StaffProfileAdminForm):
"""
Form used when creating new Staff Profiles
"""
user = forms.ModelChoiceField(
label=_('User'), queryset=User.objects.filter(staffprofile=None))

class Meta: # pylint: disable=too-few-public-methods
"""
Class meta options
"""
model = StaffProfile
fields = [
'user',
'first_name',
'last_name',
'id_number',
'phone',
'sex',
'role',
'nhif',
'nssf',
'pin_number',
'address',
'birthday',
'leave_days',
'sick_days',
'overtime_allowed',
'start_date',
'end_date',
'emergency_contact_name',
'emergency_contact_number',
]

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
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 = 'staffprofile-form'
self.helper.layout = Layout(
Field('user',),
Field('first_name',),
Field('last_name',),
Field('phone',),
Field('id_number',),
Field('sex',),
Field('role',),
Field('nhif',),
Field('nssf',),
Field('pin_number',),
Field('emergency_contact_name',),
Field('emergency_contact_number',),
Field('address',),
Field('birthday',),
Field('leave_days',),
Field('sick_days',),
Field('overtime_allowed',),
Field('start_date',),
Field('end_date',),
Field('emergency_contact_name',),
Field('emergency_contact_number',),
FormActions(
Submit('submitBtn', _('Submit'), css_class='btn-primary'),
)
)


class StaffProfileUserForm(StaffProfileAdminForm):
"""
Form used when the user is updating their own data
Expand Down
5 changes: 2 additions & 3 deletions small_small_hr/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
Small small HR signals module
"""
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from small_small_hr.models import StaffProfile

USER = settings.AUTH_USER_MODEL


@receiver(post_save, sender=USER)
# pylint: disable=unused-argument
def create_staffprofile(sender, instance, created, **kwargs):
"""
Create staffprofile when a user object is created
This signal is not connected by default
"""
if created or not instance.staffprofile:
# pylint: disable=unused-variable
Expand Down
Loading

0 comments on commit 2c56a68

Please sign in to comment.