From d22034f02eaa43a0fef97c5d3ff247f466a90dc4 Mon Sep 17 00:00:00 2001 From: FUNNYDMAN Date: Wed, 7 Nov 2018 10:29:17 +0300 Subject: [PATCH] trying to fix problem with contact us form --- eshop/accounts_ext/fixtures/accounts.json | 21 ++++++++++++++++++- eshop/accounts_ext/views.py | 2 -- eshop/cart/urls.py | 1 - eshop/contact_us/admin.py | 5 +++-- eshop/contact_us/forms.py | 20 ++++++++++-------- eshop/contact_us/tests.py | 1 - eshop/contact_us/views.py | 1 - eshop/core/admin.py | 3 +-- eshop/core/context_processors.py | 1 - .../core/management/commands/clean_deleted.py | 4 ++-- eshop/core/management/commands/clearcache.py | 1 + eshop/core/templatetags/core_filters.py | 1 + eshop/core/views.py | 4 +++- eshop/eshop_project/settings/production.py | 5 ++++- eshop/products/views.py | 1 - 15 files changed, 46 insertions(+), 25 deletions(-) diff --git a/eshop/accounts_ext/fixtures/accounts.json b/eshop/accounts_ext/fixtures/accounts.json index b1002ab..0a5cbef 100644 --- a/eshop/accounts_ext/fixtures/accounts.json +++ b/eshop/accounts_ext/fixtures/accounts.json @@ -1 +1,20 @@ -[{"model": "accounts_ext.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$100000$AAP4DpqYKrFB$mQRKz7qi/1va3Zoh2O3g9j7wYKCBaMLz5LFrbszDNLA=", "last_login": "2018-08-12T20:46:54Z", "create_at": "2018-08-12T20:46:44.961Z", "updated_at": "2018-08-12T20:47:05.733Z", "status": 25, "is_superuser": true, "username": "dimkasp", "email": "dimkasp@mail.ru", "referral_user": null, "confirmed_at": null, "groups": [], "user_permissions": []}}] \ No newline at end of file +[ + { + "model": "accounts_ext.user", + "pk": 1, + "fields": { + "password": "pbkdf2_sha256$100000$AAP4DpqYKrFB$mQRKz7qi/1va3Zoh2O3g9j7wYKCBaMLz5LFrbszDNLA=", + "last_login": "2018-08-12T20:46:54Z", + "create_at": "2018-08-12T20:46:44.961Z", + "updated_at": "2018-08-12T20:47:05.733Z", + "status": 25, + "is_superuser": true, + "username": "dimkasp", + "email": "dimkasp@mail.ru", + "referral_user": null, + "confirmed_at": null, + "groups": [], + "user_permissions": [] + } + } +] diff --git a/eshop/accounts_ext/views.py b/eshop/accounts_ext/views.py index 7c23e93..4a5141f 100644 --- a/eshop/accounts_ext/views.py +++ b/eshop/accounts_ext/views.py @@ -28,8 +28,6 @@ from .forms import ( logger = logging.getLogger(__name__) -# Create your views here. - class LoginView(LoginViewBase): redirect_field_name = 'next' form_class = AuthenticationForm diff --git a/eshop/cart/urls.py b/eshop/cart/urls.py index 70963cd..520e213 100644 --- a/eshop/cart/urls.py +++ b/eshop/cart/urls.py @@ -1,4 +1,3 @@ -from django.conf.urls import url from django.urls import re_path from . import views diff --git a/eshop/contact_us/admin.py b/eshop/contact_us/admin.py index a07e70a..b9a9309 100644 --- a/eshop/contact_us/admin.py +++ b/eshop/contact_us/admin.py @@ -6,6 +6,7 @@ from core import admin as CoreAdmin from .models import Request + @admin.register(Request) class ContactUsAdmin(CoreAdmin.SafeModelAdmin): list_filter = ( @@ -13,5 +14,5 @@ class ContactUsAdmin(CoreAdmin.SafeModelAdmin): ('create_at', DateRangeFilter), ('updated_at', DateTimeRangeFilter), ) - search_fields = ('email','subject','phone') - list_display = ('email','subject','phone', 'status') + search_fields = ('email', 'subject', 'phone') + list_display = ('email', 'subject', 'phone', 'status') diff --git a/eshop/contact_us/forms.py b/eshop/contact_us/forms.py index 1e9457d..86f240f 100644 --- a/eshop/contact_us/forms.py +++ b/eshop/contact_us/forms.py @@ -1,5 +1,5 @@ from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout, HTML, Field, Submit, Hidden +from crispy_forms.layout import Layout, Field, Submit, Hidden from django import forms from django.conf import settings @@ -11,11 +11,11 @@ from .models import ( Request, STATUS_NEW ) + # -------------------------------- Client-side forms -----------------------------------# class ContactUsForm(RequestNotifiable, forms.ModelForm): - field_template = 'bootstrap/forms/contact_us.html' def __init__(self, *args, **kwargs): @@ -27,12 +27,15 @@ class ContactUsForm(RequestNotifiable, forms.ModelForm): self.helper.form_action = reverse_lazy('contact_us:send') self.helper.form_method = 'post' self.helper.layout = Layout( - Hidden('next', reverse_lazy(self.next) if not self.next_kwargs else reverse_lazy(self.next, kwargs=self.next_kwargs)), - Field('name', css_class=self.field_css+"__text", placeholder=_("Имя"), template=self.field_template), - Field('email', css_class=self.field_css+"__text", placeholder=_("Email"), template=self.field_template), - Field('subject', css_class=self.field_css+"__text", placeholder=_("Название продукта"), template=self.field_template), - Field('phone', css_class=self.field_css+"__text", placeholder=_("+79781234567"), template=self.field_template), - Submit('send', _("Отправить"), css_class=self.field_css+"__btn") + Hidden('next', reverse_lazy(self.next) if not self.next_kwargs else reverse_lazy(self.next, + kwargs=self.next_kwargs)), + Field('name', css_class=self.field_css + "__text", placeholder=_("Имя"), template=self.field_template), + Field('email', css_class=self.field_css + "__text", placeholder=_("Email"), template=self.field_template), + Field('subject', css_class=self.field_css + "__text", placeholder=_("Название продукта"), + template=self.field_template), + Field('phone', css_class=self.field_css + "__text", placeholder=_("+79781234567"), + template=self.field_template), + Submit('send', _("Отправить"), css_class=self.field_css + "__btn") ) super(ContactUsForm, self).__init__(*args, **kwargs) self.init_fields(self.fields) @@ -66,7 +69,6 @@ class ContactUsForm(RequestNotifiable, forms.ModelForm): context, ) - class Meta: model = Request fields = ('name', 'email', 'subject', 'phone',) diff --git a/eshop/contact_us/tests.py b/eshop/contact_us/tests.py index 0716457..8d99b69 100644 --- a/eshop/contact_us/tests.py +++ b/eshop/contact_us/tests.py @@ -5,7 +5,6 @@ from core.tests import BehaviourTestCaseMixin from .models import Request -# Create your tests here. class SendRequestWithTestCase(BehaviourTestCaseMixin, TestCase): model = Request diff --git a/eshop/contact_us/views.py b/eshop/contact_us/views.py index 74a9bb9..0f34196 100644 --- a/eshop/contact_us/views.py +++ b/eshop/contact_us/views.py @@ -11,7 +11,6 @@ from .forms import ContactUsForm logger = logging.getLogger(__name__) -# Create your views here. class ContactUsFormView(SuccessMessageMixin, FormView): next = None template_name = None diff --git a/eshop/core/admin.py b/eshop/core/admin.py index e188911..73a18f3 100644 --- a/eshop/core/admin.py +++ b/eshop/core/admin.py @@ -117,7 +117,7 @@ class SafeModelAdmin(admin.ModelAdmin): @admin.register(Certificate) class CertAdmin(SafeModelAdmin): - list_display = ('name','image', 'status') + list_display = ('name', 'image', 'status') search_fields = ('name',) list_filter = ('status',) @@ -135,4 +135,3 @@ class CurrencyAdmin(admin.ModelAdmin): ('create_at', DateRangeFilter), ('updated_at', DateTimeRangeFilter) ) search_fields = ('name', 'code', 'sign') - diff --git a/eshop/core/context_processors.py b/eshop/core/context_processors.py index d21287c..59d0672 100644 --- a/eshop/core/context_processors.py +++ b/eshop/core/context_processors.py @@ -31,6 +31,5 @@ def _product_breadcrumbs(request): return breadcrumb - def _news_breadcrumbs(request): pass diff --git a/eshop/core/management/commands/clean_deleted.py b/eshop/core/management/commands/clean_deleted.py index f67e4c4..f95e4f9 100644 --- a/eshop/core/management/commands/clean_deleted.py +++ b/eshop/core/management/commands/clean_deleted.py @@ -1,4 +1,4 @@ -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand import django.apps from core.models import AbstractStatusModel @@ -15,4 +15,4 @@ class Command(BaseCommand): for obj in data: obj.delete_from_base() - self.stdout.write(self.style.SUCCESS('Successfully deleted %s %s' % (len(data), model))) \ No newline at end of file + self.stdout.write(self.style.SUCCESS('Successfully deleted %s %s' % (len(data), model))) diff --git a/eshop/core/management/commands/clearcache.py b/eshop/core/management/commands/clearcache.py index bcd3c40..9b6e3ca 100644 --- a/eshop/core/management/commands/clearcache.py +++ b/eshop/core/management/commands/clearcache.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand from django.core.cache import cache + class Command(BaseCommand): def handle(self, *args, **kwargs): cache.clear() diff --git a/eshop/core/templatetags/core_filters.py b/eshop/core/templatetags/core_filters.py index 2034bf2..85324be 100644 --- a/eshop/core/templatetags/core_filters.py +++ b/eshop/core/templatetags/core_filters.py @@ -2,6 +2,7 @@ from django.template import Library register = Library() + @register.filter def get_item(dictionary, key): return dictionary.get(key) diff --git a/eshop/core/views.py b/eshop/core/views.py index 7aed9b8..4931980 100644 --- a/eshop/core/views.py +++ b/eshop/core/views.py @@ -1,6 +1,5 @@ from django.contrib.auth.mixins import LoginRequiredMixin -# Create your views here. from django.views import View from django.views.generic import TemplateView, ListView, DetailView, FormView from django.views.generic.edit import BaseFormView @@ -25,9 +24,11 @@ class ProtectedDetailView(LoginRequiredMixin, DetailView): class ProtectedFormView(LoginRequiredMixin, FormView): pass + class ProtectedBaseFormView(LoginRequiredMixin, BaseFormView): pass + class Handler404View(TemplateView): template_name = '404.html' @@ -39,5 +40,6 @@ class Handler500View(TemplateView): class Handler403View(TemplateView): template_name = '403.html' + class Handler400View(TemplateView): template_name = '400.html' diff --git a/eshop/eshop_project/settings/production.py b/eshop/eshop_project/settings/production.py index badb638..4a1ca25 100644 --- a/eshop/eshop_project/settings/production.py +++ b/eshop/eshop_project/settings/production.py @@ -1,4 +1,7 @@ -from .base import * +try: + from .base import * +except ImportError: + raise ImportError("Oops,can't find base settings") # Email user settings ADMINS = ( diff --git a/eshop/products/views.py b/eshop/products/views.py index 84ac4a7..e23a03b 100644 --- a/eshop/products/views.py +++ b/eshop/products/views.py @@ -42,7 +42,6 @@ class ProductListView(ListView): category_slug = parse_path(self.kwargs.get('path')) cat_qs = ProductCategory.objects.filter(slug=category_slug) qs = qs.filter(parent_id__in=cat_qs.get_descendants(include_self=True)) - print(qs) # TODO understand why there are some filtering queries # if self.request.GET.get('name'): # qs = qs.filter(name__icontains=self.request.GET.get('name'))