diff --git a/archilance/management/commands/generate_projects.py b/archilance/management/commands/generate_projects.py index febb7cd..66f6846 100644 --- a/archilance/management/commands/generate_projects.py +++ b/archilance/management/commands/generate_projects.py @@ -6,7 +6,7 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_ import random from archilance import util -from projects.models import Project, CURRENCIES, TERMS, Specialization, Realty +from projects.models import Project, Order, CURRENCIES, TERMS, Specialization, Realty from users.models import User @@ -73,6 +73,9 @@ class Command(BaseCommand): project.customer = User.objects.filter(groups__name='Заказчики', is_active=True, is_superuser=False).order_by('?').first() project.save() + + Order.objects.create(project=project) + return project _.times(create_project, 1000) diff --git a/archilance/settings/base.py b/archilance/settings/base.py index 96d7bd5..aaabc4d 100644 --- a/archilance/settings/base.py +++ b/archilance/settings/base.py @@ -247,3 +247,5 @@ SHELL_PLUS_POST_IMPORTS = ( # Extra auto imports ('archilance', 'util'), ('pprint', ('pprint', 'pformat')), ) + +PAGE_SIZE = 10 # Pagination diff --git a/projects/forms.py b/projects/forms.py index f17c2f8..8d8b449 100644 --- a/projects/forms.py +++ b/projects/forms.py @@ -13,14 +13,25 @@ from users.models import User # RealtyFormSet = inlineformset_factory(Project, Realty) +PROJECT_ORDER_CHOICES = ( + ('name', 'Name'), + ('budget', 'Budget'), + ('created', 'Created'), + ('views', 'Views'), +) + class ProjectFilterForm(forms.ModelForm): + order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) + last_order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) + reverse_order = forms.BooleanField(required=False) + class Meta: model = Project fields = ( 'cro', - 'work_type', 'specialization', + 'work_type', ) widgets = { diff --git a/projects/templates/project_filter.html b/projects/templates/project_filter.html index 0508ae9..5118bb9 100644 --- a/projects/templates/project_filter.html +++ b/projects/templates/project_filter.html @@ -65,6 +65,9 @@ + + +

Расширенный поиск

@@ -175,84 +178,132 @@ {# #} {# #} - - - + + + + + + +
- - - - - - - - - - - - - -
- {% for proj in projects %} -
-
-

- {{ proj }} -

-
    -
  • - Объект "{{ proj.realty.name }}" -
  • -
  • - 0 ответ от имени группы -
  • -
-

{{ proj.text }}

- - {% if TEMPLATE_DEBUG %} -
{{ proj|inspect }}

Specialization: {{ proj.specialization }}
Realty location: {{ proj.realty.location }}
Constr. type: {{ proj.realty.construction_type }}
Build. classif.: {{ proj.realty.building_classification }}
- {% endif %} - -
    -
  • {{ proj.created }}
  • -
  • 0
  • -
  • {{ proj.answers.count }}
  • -
  • {{ proj.user }}
  • -
+ + + + + + + +
+ {% for proj in projects %} +
+
+

+ {{ proj }} +

+
    +
  • + Объект "{{ proj.realty.name }}" +
  • +
  • + 0 ответ от имени группы +
  • +
+

{{ proj.text }}

+ + {% if TEMPLATE_DEBUG %} +
{{ proj|inspect }}

Specialization: {{ proj.specialization }}
Realty location: {{ proj.realty.location }}
Constr. type: {{ proj.realty.construction_type }}
Build. classif.: {{ proj.realty.building_classification }}
+ {% endif %} + +
    +
  • {{ proj.created }}
  • +
  • 0
  • +
  • {{ proj.answers.count }}
  • +
  • {{ proj.user }}
  • +
+
+
+

+ {{ proj.budget }} +

+
    + {% if proj.secure_deal %} +
  • Безопасная сделка
  • + {% endif %} + +
  • + Стадия: "П" +
  • + +
  • + Отказаться и переместить + в корзину +
  • +
+
-
-

- {{ proj.budget }} -

-
    - {% if proj.secure_deal %} -
  • Безопасная сделка
  • + {% endfor %} +
+ + + + + + + +
+ {% if is_paginated %} +
-
- {% endfor %} -
-
- {% include 'partials/pagination.html' %} -
+ + {% else %} + {% include 'partials/pagination.html' %} + {% endif %} +
+ {% include 'partials/footer.html' %}
diff --git a/projects/views.py b/projects/views.py index 761423e..16baf3e 100644 --- a/projects/views.py +++ b/projects/views.py @@ -1,14 +1,15 @@ -import json -from pprint import pprint, pformat -import pydash as _ - +from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.urlresolvers import reverse, reverse_lazy from django.http import HttpResponseForbidden, HttpResponseRedirect, HttpResponse, Http404 from django.shortcuts import render, get_object_or_404, redirect from django.views.generic import ListView, DetailView, CreateView, View, UpdateView, TemplateView, FormView from django.views.generic.base import ContextMixin +from pprint import pprint, pformat +import json +import pydash as _ from .mixins import LastAccessMixin from .models import Project, ProjectFile, Portfolio, Candidate, Answer, Realty, Order @@ -28,6 +29,7 @@ from .forms import ( RealtyForm, ) + class ProjectFilterView(BaseMixin, View): template_name = 'project_filter.html' form_class = ProjectFilterForm @@ -37,7 +39,6 @@ class ProjectFilterView(BaseMixin, View): form = self.form_class(request.GET, request=request) realty_form = self.realty_form(request.GET, request=request, prefix='realty_form') context = self.get_context_data(**_.merge({}, request.GET, kwargs)) - display_msg = 'Список проектов' projects = Project.objects @@ -52,7 +53,8 @@ class ProjectFilterView(BaseMixin, View): projects = projects.filter(cro=cro) - if work_type: projects = projects.filter(work_type=work_type) + if work_type: + projects = projects.filter(work_type=work_type) if specialization: projects = projects.filter( @@ -60,8 +62,11 @@ class ProjectFilterView(BaseMixin, View): specialization__rght__lte=specialization.rght, ) - if building_classification: projects = projects.filter(realty__building_classification=building_classification) - if construction_type: projects = projects.filter(realty__construction_type=construction_type) + if building_classification: + projects = projects.filter(realty__building_classification=building_classification) + + if construction_type: + projects = projects.filter(realty__construction_type=construction_type) if location: projects = projects.filter( @@ -69,6 +74,26 @@ class ProjectFilterView(BaseMixin, View): realty__location__rght__lte=location.rght, ) + order_by = form.cleaned_data.get('order_by') + last_order_by = form.cleaned_data.get('last_order_by') + reverse_order = form.cleaned_data.get('reverse_order') + + if order_by: + if order_by == last_order_by: + reverse_order = not reverse_order + else: + reverse_order = False + + projects = projects.order_by('-%s' % order_by if reverse_order else order_by) + last_order_by = order_by + elif last_order_by: + projects = projects.order_by('-%s' % last_order_by if reverse_order else last_order_by) + + context.update({ + 'last_order_by': last_order_by, + 'reverse_order': reverse_order, + }) + project_count = projects.count() display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' else: @@ -86,17 +111,22 @@ class ProjectFilterView(BaseMixin, View): '
{realty_form}
' ).format(realty_form=pformat(realty_form.errors))) - order_by = request.GET.get('order_by') # TODO: Validate - if order_by: - projects = projects.order_by(order_by) + paginator = Paginator(projects.all(), settings.PAGE_SIZE) + page = request.GET.get('page') - projects = projects[:10] + try: + projects = paginator.page(page) + except PageNotAnInteger: + projects = paginator.page(1) + except EmptyPage: + projects = paginator.page(paginator.num_pages) context.update({ 'form': form, 'realty_form': realty_form, 'projects': projects, + 'is_paginated': True, 'display_msg': display_msg, }) @@ -157,6 +187,8 @@ class CustomerProjectCreateView(BaseMixin, View): project.save() form.save_m2m() + Order.objects.create(project=project) + for file in request.FILES.getlist('new_files'): proj_file = ProjectFile.objects.create(file=file, project=project) proj_file.save() diff --git a/users/serializers.py b/users/serializers.py index f7aff5d..41266be 100755 --- a/users/serializers.py +++ b/users/serializers.py @@ -24,7 +24,6 @@ class UserSerializer(ModelSerializer): 'last_name', 'last_time_visit', 'location', - 'nickname', 'patronym', 'skype', 'website', @@ -49,4 +48,5 @@ class UserSerializer(ModelSerializer): # # return inst + # import code; code.interact(local=dict(globals(), **locals())) diff --git a/work_sell/templates/worksells_list.html b/work_sell/templates/worksells_list.html index c5bcd1a..25d9702 100644 --- a/work_sell/templates/worksells_list.html +++ b/work_sell/templates/worksells_list.html @@ -143,36 +143,38 @@ {% endfor %} - {% if is_paginated %} -
- +
+ {% endif %} + {% include 'partials/footer.html' %} diff --git a/work_sell/views.py b/work_sell/views.py index f5a8c7b..f6c375c 100644 --- a/work_sell/views.py +++ b/work_sell/views.py @@ -35,7 +35,8 @@ class BasicCreateView(PictureCreateView): class WorkSellsView(ListView): model = WorkSell template_name = 'worksells_list.html' - paginate_by = 20 + # paginate_by = 20 + paginate_by = 1 def get_form_kwargs(self, **kwargs): kwargs = super().get_form_kwargs