Skip to content

Commit

Permalink
Merge pull request #13 from moshthepitt/issue-4
Browse files Browse the repository at this point in the history
Add staff photo
  • Loading branch information
moshthepitt authored Jul 25, 2018
2 parents 040277d + 59f203c commit 93d4a8c
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs=1

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=pylint_django

# Pickle collected data for later comparisons.
persistent=yes
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ipdb = "*"
model-mommy = "*"
"autopep8" = "*"
tblib = "*"
pylint-django = {git = "https://github.com/PyCQA/pylint-django.git", ref = "4316c3d90f4ac6cbbeddfc8d431f5d4e031d5cf1"}
189 changes: 151 additions & 38 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
'phonenumberslite',
'django-phonenumber-field',
'django-crispy-forms',
'djangorestframework'
'djangorestframework',
'sorl-thumbnail',
'Pillow'
],
classifiers=[
'Programming Language :: Python',
Expand Down
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, 7)
VERSION = (0, 0, 8)
__version__ = '.'.join(str(v) for v in VERSION)
12 changes: 10 additions & 2 deletions small_small_hr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class Meta: # pylint: disable=too-few-public-methods
'staff',
'name',
'description',
'public',
'file',
]

Expand All @@ -424,6 +425,7 @@ def __init__(self, *args, **kwargs):
Field('name',),
Field('description',),
Field('file',),
Field('public',),
FormActions(
Submit('submitBtn', _('Submit'), css_class='btn-primary'),
)
Expand Down Expand Up @@ -488,9 +490,9 @@ class StaffProfileAdminForm(forms.ModelForm):
nssf = forms.CharField(label=_('NSSF'), required=False)
pin_number = forms.CharField(label=_('PIN Number'), required=False)
emergency_contact_name = forms.CharField(
label=_('Emergecy Contact Name'), required=False)
label=_('Emergency Contact Name'), required=False)
emergency_contact_relationship = forms.CharField(
label=_('Emergecy Contact Relationship'), required=False)
label=_('Emergency Contact Relationship'), required=False)
emergency_contact_number = PhoneNumberField(
label=_('Emergency Contact Phone Number'), required=False)

Expand All @@ -503,6 +505,7 @@ class Meta: # pylint: disable=too-few-public-methods
'first_name',
'last_name',
'id_number',
'image',
'phone',
'sex',
'role',
Expand Down Expand Up @@ -534,6 +537,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Field('first_name',),
Field('last_name',),
Field('image',),
Field('phone',),
Field('id_number',),
Field('sex',),
Expand Down Expand Up @@ -652,6 +656,7 @@ class Meta: # pylint: disable=too-few-public-methods
'first_name',
'last_name',
'id_number',
'image',
'phone',
'sex',
'role',
Expand Down Expand Up @@ -684,6 +689,7 @@ def __init__(self, *args, **kwargs):
Field('user',),
Field('first_name',),
Field('last_name',),
Field('image',),
Field('phone',),
Field('id_number',),
Field('sex',),
Expand Down Expand Up @@ -721,6 +727,7 @@ class Meta: # pylint: disable=too-few-public-methods
'first_name',
'last_name',
'id_number',
'image',
'phone',
'sex',
'nhif',
Expand All @@ -746,6 +753,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Field('first_name',),
Field('last_name',),
Field('image',),
Field('phone',),
Field('id_number',),
Field('sex',),
Expand Down
36 changes: 36 additions & 0 deletions small_small_hr/migrations/0002_auto_20180722_1808.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 2.0.7 on 2018-07-22 15:08

from django.db import migrations
import private_storage.fields
import private_storage.storage.files
import sorl.thumbnail.fields


class Migration(migrations.Migration):

dependencies = [
('small_small_hr', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='staffprofile',
name='image',
field=sorl.thumbnail.fields.ImageField(
blank=True,
help_text='A square image works best',
max_length=255,
upload_to='staff-images/',
verbose_name='Profile Image'),
),
migrations.AlterField(
model_name='staffdocument',
name='file',
field=private_storage.fields.PrivateFileField(
help_text='Upload staff member document',
storage=private_storage.storage.files.PrivateFileSystemStorage(
),
upload_to='staff-documents/',
verbose_name='File'),
),
]
21 changes: 21 additions & 0 deletions small_small_hr/migrations/0003_staffdocument_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.0.7 on 2018-07-25 16:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('small_small_hr', '0002_auto_20180722_1808'),
]

operations = [
migrations.AddField(
model_name='staffdocument',
name='public',
field=models.BooleanField(
default=False,
help_text='If public, it will be available to everyone.',
verbose_name='Public'),
),
]
33 changes: 20 additions & 13 deletions small_small_hr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models import Value as V
from django.db.models import Sum
from django.db.models import Value as V
from django.db.models.functions import Coalesce
from django.utils.translation import ugettext as _

from phonenumber_field.modelfields import PhoneNumberField
from private_storage.fields import PrivateFileField
from sorl.thumbnail import ImageField

from small_small_hr.managers import LeaveManager

Expand All @@ -33,7 +34,7 @@ class TimeStampedModel(models.Model):
auto_now=True)

# pylint: disable=too-few-public-methods
class Meta(object):
class Meta:
"""
Meta options for TimeStampedModel
"""
Expand All @@ -47,7 +48,7 @@ class Role(TimeStampedModel, models.Model):
name = models.CharField(_('Name'), max_length=255)
description = models.TextField(_('Description'), blank=True, default='')

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for StaffDocument
"""
Expand Down Expand Up @@ -83,6 +84,9 @@ class StaffProfile(TimeStampedModel, models.Model):

user = models.OneToOneField(
USER, verbose_name=_('User'), on_delete=models.CASCADE)
image = ImageField(upload_to="staff-images/", max_length=255,
verbose_name=_("Profile Image"),
help_text=_("A square image works best"), blank=True)
sex = models.CharField(_('Gender'), choices=SEX_CHOICES, max_length=1,
default=NOT_KNOWN, blank=True, db_index=True)
role = models.ForeignKey(Role, verbose_name=_('Role'), blank=True,
Expand All @@ -108,7 +112,7 @@ class StaffProfile(TimeStampedModel, models.Model):
help_text=_('The end date of employment'))
data = JSONField(_('Data'), default=dict, blank=True)

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for StaffProfile
"""
Expand Down Expand Up @@ -186,7 +190,7 @@ def get_available_sick_days(self, year: int = datetime.today().year):
return leave_record.get_available_leave_days()

def __str__(self):
return self.get_name()
return self.get_name() # pylint: disable=no-member


class StaffDocument(TimeStampedModel, models.Model):
Expand All @@ -199,7 +203,7 @@ class StaffDocument(TimeStampedModel, models.Model):
description = models.TextField(_('Description'), blank=True, default='')
file = PrivateFileField(
_('File'), upload_to='staff-documents/',
help_text=_("Upload staff member drocument"),
help_text=_("Upload staff member document"),
content_types=[
'application/pdf',
'application/msword',
Expand All @@ -209,8 +213,12 @@ class StaffDocument(TimeStampedModel, models.Model):
],
max_file_size=1048576
)
public = models.BooleanField(
_('Public'),
help_text=_('If public, it will be available to everyone.'),
blank=True, default=False)

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for StaffDocument
"""
Expand Down Expand Up @@ -248,7 +256,7 @@ class BaseStaffRequest(TimeStampedModel, models.Model):
blank=True, db_index=True)
comments = models.TextField(_('Comments'), blank=True, default='')

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for StaffDocument
"""
Expand All @@ -273,7 +281,7 @@ class Leave(BaseStaffRequest):

objects = LeaveManager()

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for Leave
"""
Expand All @@ -296,7 +304,7 @@ class OverTime(BaseStaffRequest):
start = models.TimeField(_('Start'), auto_now=False, auto_now_add=False)
end = models.TimeField(_('End'), auto_now=False, auto_now_add=False)

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for OverTime
"""
Expand All @@ -306,8 +314,7 @@ class Meta(object): # pylint: disable=too-few-public-methods
ordering = ['staff', 'date', 'start']

def __str__(self):
# pylint: disable=no-member
name = self.staff.get_name()
name = self.staff.get_name() # pylint: disable=no-member
return _(f'{name}: {self.date} from {self.start} to {self.end}')

def get_duration(self):
Expand Down Expand Up @@ -344,7 +351,7 @@ class AnnualLeave(TimeStampedModel, models.Model):
_('Carried Over Leave days'), default=0, blank=True,
help_text=_('Number of leave days carried over into this year.'))

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
Meta options for AnnualLeave
"""
Expand Down
4 changes: 2 additions & 2 deletions small_small_hr/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UserSerializer(serializers.ModelSerializer):
UserSerializer class
"""

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
meta options
"""
Expand Down Expand Up @@ -45,7 +45,7 @@ class StaffProfileSerializer(serializers.ModelSerializer):
emergency_contact_name = serializers.SerializerMethodField()
emergency_contact_number = serializers.SerializerMethodField()

class Meta(object): # pylint: disable=too-few-public-methods
class Meta: # pylint: disable=too-few-public-methods
"""
class meta options
"""
Expand Down
Binary file added tests/fixtures/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
SECRET_KEY = "i love oov"

PRIVATE_STORAGE_ROOT = '/tmp/'
MEDIA_ROOT = '/tmp/'
PRIVATE_STORAGE_AUTH_FUNCTION = 'private_storage.permissions.allow_staff'

# try and load local_settings if present
Expand Down
Loading

0 comments on commit 93d4a8c

Please sign in to comment.