diff --git a/employees/api/serializers.py b/employees/api/serializers.py index 433a361..a7fdc35 100644 --- a/employees/api/serializers.py +++ b/employees/api/serializers.py @@ -41,16 +41,31 @@ def get_variations_urls(self, obj): return_object[key] = super(StdImageFieldSerializer, self).to_representation(field_obj) # Also include the original (if possible) - if hasattr(obj, 'url'): - return_object['original'] = super(StdImageFieldSerializer, self).to_representation(obj) + try: + if hasattr(obj, 'url'): + return_object['original'] = super(StdImageFieldSerializer, self).to_representation(obj) + except ValueError: + pass return return_object class EmployeeModelSerializer(serializers.ModelSerializer): user = UserDisplaySerializer(read_only=True) + primary_activity = serializers.SerializerMethodField() + secondary_activity = serializers.SerializerMethodField() + type = serializers.SerializerMethodField() image = StdImageFieldSerializer() + def get_primary_activity(self, obj): + return Employee.ACTIVITY_DICT[obj.primary_activity] + + def get_secondary_activity(self, obj): + return Employee.ACTIVITY_DICT[obj.secondary_activity] + + def get_type(self, obj): + return Employee.EMPLOYEE_DICT[obj.type] + class Meta: model = Employee fields = "__all__" diff --git a/employees/api/views.py b/employees/api/views.py index 7229676..e55d38d 100644 --- a/employees/api/views.py +++ b/employees/api/views.py @@ -1,4 +1,5 @@ from rest_framework import generics, permissions +from django.db.models import Q from employees.models import Employee from .pagination import StandardResultsPagination @@ -15,9 +16,38 @@ def get_serializer_context(self, *args, **kwargs): return context def get_queryset(self, *args, **kwargs): - qs = Employee.objects.filter(type__in=["MEM", "AFF", "PRE", "SEC", "CFO"]) + qs = Employee.objects.exclude(type__in=["RET", "KIA"]) + + query = self.request.GET.get("q", None) + if query is not None: + type_search = query + activity_search = query + if query is not "": + type_search = self.search(Employee.EMPLOYEE_DICT, query) + activity_search = self.search(Employee.ACTIVITY_DICT, query) + + if type_search is not "": + qs = qs.filter(type__icontains=type_search) + elif activity_search is not "": + qs = qs.filter( + Q(primary_activity__icontains=activity_search) | + Q(secondary_activity__icontains=activity_search) + ) + else: + qs = qs.filter( + Q(user__last_name__icontains=query) | + Q(user__first_name__icontains=query) | + Q(callsign__icontains=query) + ) return qs + def search(self, values, searchFor): + # This search is not very efficient. We should replace it. + for k in values: + if searchFor.lower() in values[k].lower(): + return k + return "" + class EmployeeDetailAPIView(generics.ListAPIView): queryset = Employee.objects.all() diff --git a/employees/migrations/0006_auto_20171228_0646.py b/employees/migrations/0006_auto_20171228_0646.py new file mode 100644 index 0000000..e426fec --- /dev/null +++ b/employees/migrations/0006_auto_20171228_0646.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0 on 2017-12-28 14:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('employees', '0005_auto_20171216_1956'), + ] + + operations = [ + migrations.AlterModelOptions( + name='employee', + options={'ordering': ['emp_no']}, + ), + ] diff --git a/employees/migrations/0007_auto_20171231_1618.py b/employees/migrations/0007_auto_20171231_1618.py new file mode 100644 index 0000000..29c2024 --- /dev/null +++ b/employees/migrations/0007_auto_20171231_1618.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0 on 2018-01-01 00:18 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('employees', '0006_auto_20171228_0646'), + ] + + operations = [ + migrations.AlterModelOptions( + name='employee', + options={'ordering': ['-emp_no']}, + ), + ] diff --git a/employees/models.py b/employees/models.py index ed87567..476e563 100644 --- a/employees/models.py +++ b/employees/models.py @@ -106,3 +106,6 @@ def __str__(self): def get_absolute_url(self): return reverse("employee:detail", kwargs={"pk":self.emp_no}) + + class Meta: + ordering = ["-emp_no"] diff --git a/employees/templates/employees/employee_list.html b/employees/templates/employees/employee_list.html index b3b8e2c..027e014 100644 --- a/employees/templates/employees/employee_list.html +++ b/employees/templates/employees/employee_list.html @@ -8,6 +8,7 @@ {% block container %} +
@@ -154,102 +155,228 @@

Position Available

+
-
    - {% for employee in employee_list %} -
  • -
    -
    -
    -
    -
    - - {{ employee.user.first_name }} {{ employee.user.last_name }} - -
    -
    - -
    -
    -
    - - {{ employee.user.first_name }} "{{ employee.callsign }}" {{ employee.user.last_name }} -
    - - {{ activity_dict|get_value:employee.primary_activity }} - - - {{ activity_dict|get_value:employee.secondary_activity }} - -
    - -
    -
    - Status: - {{ employee_dict|get_value:employee.type }} -
    - -
    - Hire Date: - {{ employee.hire_date|date:"d M Y" }} -
    -
    -
    -
    -
    -
    - - - -
    -
  • - {% endfor %} -
+
+
- {% if no_account %} -
- + +
+
+
    +
    +
    + Load More Members + + + {% if no_account %} +
    + - {% endif %} - - {% if is_paginated %} -
      - {% if page_obj.has_previous %} -
    • - Previous -
    • - {% endif %} -
    • - Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }} -
    • - {% if page_obj.has_next %} -
    • - Next -
    • - {% endif %} -
    - {% endif %} -
    +
    + {% endif %}
    {% endblock %} + +{% block script %} + +{% endblock %} diff --git a/employees/views.py b/employees/views.py index 77708b1..8c140a8 100644 --- a/employees/views.py +++ b/employees/views.py @@ -102,11 +102,9 @@ def get_context_data(self, **kwargs): class EmployeeListView(ListView): model = Employee template_name = 'employees/employee_list.html' - paginate_by = 10 - ordering = 'emp_no' def get_queryset(self, *args, **kwargs): - qs = Employee.objects.filter(type__in=["MEM", "AFF"]) + qs = Employee.objects.exclude(type__in=["RET", "KIA"]) query = self.request.GET.get("q", None) if query is not None: qs = qs.filter( @@ -148,7 +146,7 @@ def no_account(self): qs = Employee.objects.filter( user__exact=self.request.user ).filter( - type__in=["MEM","AFF", "PRE", "SEC", "CFO"] + type__in=["MEM", "AFF", "PRE", "SEC", "CFO"] ) if qs.count() == 0: return True diff --git a/purnkleen/settings/base.py b/purnkleen/settings/base.py index f8da2ab..46754f9 100644 --- a/purnkleen/settings/base.py +++ b/purnkleen/settings/base.py @@ -167,7 +167,7 @@ 'disable_existing_loggers': False, 'handlers': { 'file': { - 'level': 'DEBUG', + 'level': 'ERROR', 'class': 'logging.FileHandler', 'filename': os.path.join(BASE_DIR, "pnk_debug.log"), }, @@ -175,7 +175,7 @@ 'loggers': { 'django': { 'handlers': ['file'], - 'level': 'DEBUG', + 'level': 'ERROR', 'propagate': True, }, }, diff --git a/purnkleen/settings/local.py b/purnkleen/settings/local.py index f8da2ab..46754f9 100644 --- a/purnkleen/settings/local.py +++ b/purnkleen/settings/local.py @@ -167,7 +167,7 @@ 'disable_existing_loggers': False, 'handlers': { 'file': { - 'level': 'DEBUG', + 'level': 'ERROR', 'class': 'logging.FileHandler', 'filename': os.path.join(BASE_DIR, "pnk_debug.log"), }, @@ -175,7 +175,7 @@ 'loggers': { 'django': { 'handlers': ['file'], - 'level': 'DEBUG', + 'level': 'ERROR', 'propagate': True, }, }, diff --git a/purnkleen/settings/production.py b/purnkleen/settings/production.py index b69bcfd..d28b429 100644 --- a/purnkleen/settings/production.py +++ b/purnkleen/settings/production.py @@ -27,8 +27,6 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False -CSRF_COOKIE_SECURE = True -SESSION_COOKIE_SECURE = True ALLOWED_HOSTS = ['www.purnkleen.com', 'purnkleen.com'] diff --git a/templates/base2.html b/templates/base2.html index a40b07a..5129ebc 100644 --- a/templates/base2.html +++ b/templates/base2.html @@ -132,7 +132,6 @@ - {% block body %} {% block container %}{% endblock %} {% block content %}{% endblock %} @@ -194,7 +193,10 @@ + + +{% block script %}{% endblock %}