diff --git a/.idea/PyRIGS.iml b/.idea/PyRIGS.iml index f6cbf3c5..2b9ccb41 100644 --- a/.idea/PyRIGS.iml +++ b/.idea/PyRIGS.iml @@ -11,7 +11,7 @@ - + diff --git a/.idea/dataSources.ids b/.idea/dataSources.ids index b79da580..efee65b5 100644 --- a/.idea/dataSources.ids +++ b/.idea/dataSources.ids @@ -1,6 +1,163 @@ - + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
\ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index f2b8fe89..349ba60d 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,10 +1,11 @@ - + sqlite.xerial org.sqlite.JDBC jdbc:sqlite:D:\Users\Ghost\PycharmProjects\pyrigs\db.sqlite3 + .* diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 7f0eba3f..b3af52ac 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -62,11 +62,22 @@ WSGI_APPLICATION = 'PyRIGS.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases - +try: + import pymysql + pymysql.install_as_MySQLdb() +except ImportError: + pass DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + }, + 'legacy': { + 'ENGINE': 'django.db.backends.mysql', + 'HOST': 'alfie.codedinternet.com', + 'NAME': 'tec_rigs', + 'USER': 'tec_rigs', + 'PASSWORD': 'xMNb(b+Giu]&', } } diff --git a/RIGS/templates/RIGS/person_list.html b/RIGS/templates/RIGS/person_list.html index 7099a9df..e42919a8 100644 --- a/RIGS/templates/RIGS/person_list.html +++ b/RIGS/templates/RIGS/person_list.html @@ -1,13 +1,20 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} {% load widget_tweaks %} +{% load paginator from filters %} {% block title %}People list{% endblock %} {% block content %}
-

People

- New -
{% include 'pagination.html' %}
+
+
+

People

+
+
+ New +
+
+
{% paginator %}
@@ -29,7 +36,7 @@
{{ person.phone }} {{ person.notes|yesno|capfirst }} - + @@ -44,6 +51,6 @@
-
{% include 'pagination.html' %}
+
{% paginator %}
{% endblock %} \ No newline at end of file diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index acb20b96..f679d35f 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -19,4 +19,45 @@ def nice_errors(form, non_field_msg='General form errors'): else: key = form.fields[field].label nice_errors[key] = errors - return nice_errors \ No newline at end of file + return nice_errors + +def paginator(context, adjacent_pages=3): + """ + To be used in conjunction with the object_list generic view. + + Adds pagination context variables for use in displaying first, adjacent and + last page links in addition to those created by the object_list generic + view. + + """ + page = context['page_obj'] + paginator = context['paginator'] + startPage = max(page.number - adjacent_pages, 1) + if startPage <= 3: startPage = 1 + endPage = page.number + adjacent_pages + 1 + if endPage >= paginator.num_pages - 1: endPage = paginator.num_pages + 1 + page_numbers = [n for n in range(startPage, endPage) \ + if n > 0 and n <= paginator.num_pages] + + dict = { + 'is_paginated': paginator.num_pages > 0, + 'page_obj': page, + 'paginator': paginator, + 'results': paginator.per_page, + 'page_numbers': page_numbers, + 'show_first': 1 not in page_numbers, + 'show_last': paginator.num_pages not in page_numbers, + 'first': 1, + 'last': paginator.num_pages, + 'has_next': page.has_next(), + 'has_previous': page.has_previous(), + } + + if page.has_next(): + dict['next'] = page.next_page_number() + if page.has_previous(): + dict['previous'] = page.previous_page_number() + + return dict + +register.inclusion_tag('pagination.html', takes_context=True)(paginator) \ No newline at end of file diff --git a/RIGS/views.py b/RIGS/views.py index a8a43daa..5cee7c30 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -1,7 +1,7 @@ from django.http.response import HttpResponseRedirect from django.core.urlresolvers import reverse_lazy from django.views import generic -import models +from RIGS import models # Create your views here. def login(request, **kwargs): @@ -26,6 +26,7 @@ class CloseModal(generic.TemplateView): class PersonIndex(generic.ListView): model = models.Person + paginate_by = 20 class PersonDetail(generic.DetailView): model = models.Person diff --git a/requirements.txt b/requirements.txt index aef892d3..95f5a6b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ Django==1.7.1 PyMySQL==0.6.2 django-debug-toolbar==1.2.2 -django-mysql-pymysql==0.1 django-registration-redux==1.1 django-reversion==1.8.5 sqlparse==0.1.13 \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 69688764..c394f59c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -126,7 +126,6 @@ var dd = this.getDate().toString(); return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]); // padding }; - @@ -136,6 +135,16 @@ + {% block js %} {% endblock %} diff --git a/templates/pagination.html b/templates/pagination.html index a8dc4121..d66ed14d 100644 --- a/templates/pagination.html +++ b/templates/pagination.html @@ -1,27 +1,35 @@ -{% if request.is_paginated %} +{% if is_paginated %}
    - {% if page_obj.has_previous %} -
  • + {% if has_previous %} +
  • {% else %} {% endif %} - {% for page in pages %} - {% if page %} - {% ifequal page page_obj.number %} -
  • {{ page }}
  • - {% else %} -
  • {{ page }}
  • - {% endifequal %} - {% else %} - ... - {% endif %} - {% endfor %} - {% if page_obj.has_next %} -
  • - {% else %} - - {% endif %} -
+ + {% if show_first %} +
  • +
  • + {% endif %} + + {% for page in page_numbers %} + {% ifequal page page_obj.number %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + + {% if show_last %} +
  • +
  • + {% endif %} + + {% if has_next %} +
  • + {% else %} + + {% endif %} +
    {% endif %} \ No newline at end of file