|
|
|
|
@ -11,7 +11,9 @@ from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpRespons |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.utils.translation import ugettext as _, get_language |
|
|
|
|
from django_messages.forms import SendForm |
|
|
|
|
from django.views.generic import TemplateView, FormView |
|
|
|
|
from django.views.generic import TemplateView, FormView, RedirectView |
|
|
|
|
# from django.views.generic.detail import SingleObjectMixin |
|
|
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
from meta.views import MetadataMixin |
|
|
|
|
@ -91,18 +93,8 @@ class SettingsView(CreateUpdateView): |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailingSettings(ContextMixin, AjaxableResponseMixin, CreateUpdateView): |
|
|
|
|
form_class = MailingSettingsForm |
|
|
|
|
template_name = 'client/accounts/mailing_settings.html' |
|
|
|
|
success_url = reverse_lazy('accounts-mailing_settings') |
|
|
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
|
return self.success_url |
|
|
|
|
|
|
|
|
|
def get_object(self): |
|
|
|
|
self.extra_ctx.update({ |
|
|
|
|
'r_cities': City.used.russia(), |
|
|
|
|
}) |
|
|
|
|
class GetUserMixin(object): |
|
|
|
|
def get_user(self): |
|
|
|
|
instance = None |
|
|
|
|
if self.request.user.is_authenticated(): |
|
|
|
|
try: |
|
|
|
|
@ -117,7 +109,22 @@ class MailingSettings(ContextMixin, AjaxableResponseMixin, CreateUpdateView): |
|
|
|
|
instance = Contact.objects.get(pk=self.request.session['ml_contact_pk']) |
|
|
|
|
except Contact.DoesNotExist: |
|
|
|
|
pass |
|
|
|
|
return instance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailingSettings(GetUserMixin, ContextMixin, AjaxableResponseMixin, CreateUpdateView): |
|
|
|
|
form_class = MailingSettingsForm |
|
|
|
|
template_name = 'client/accounts/mailing_settings.html' |
|
|
|
|
success_url = reverse_lazy('accounts-mailing_settings') |
|
|
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
|
return self.success_url |
|
|
|
|
|
|
|
|
|
def get_object(self): |
|
|
|
|
self.extra_ctx.update({ |
|
|
|
|
'r_cities': City.used.russia(), |
|
|
|
|
}) |
|
|
|
|
instance = self.get_user() |
|
|
|
|
if instance is not None: |
|
|
|
|
self.extra_ctx.update({ |
|
|
|
|
'checked_f_countries': list(instance.f_countries.values_list('pk', flat=True)), |
|
|
|
|
@ -130,19 +137,33 @@ class MailingSettings(ContextMixin, AjaxableResponseMixin, CreateUpdateView): |
|
|
|
|
return instance |
|
|
|
|
|
|
|
|
|
def form_valid(self, form): |
|
|
|
|
print(form.cleaned_data) |
|
|
|
|
print(form.errors) |
|
|
|
|
print(self.request.POST) |
|
|
|
|
# print(form.cleaned_data) |
|
|
|
|
# print(form.errors) |
|
|
|
|
# print(self.request.POST) |
|
|
|
|
# import pdb; pdb.set_trace() |
|
|
|
|
return super(MailingSettings, self).form_valid(form) |
|
|
|
|
|
|
|
|
|
def form_invalid(self, form): |
|
|
|
|
print(form.cleaned_data) |
|
|
|
|
print(form.errors) |
|
|
|
|
print(self.request.POST) |
|
|
|
|
# print(form.cleaned_data) |
|
|
|
|
# print(form.errors) |
|
|
|
|
# print(self.request.POST) |
|
|
|
|
return super(MailingSettings, self).form_invalid(form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailingSettingsUnsubscribe(GetUserMixin, RedirectView): |
|
|
|
|
url = reverse_lazy('accounts-mailing_settings') |
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
contact = self.get_user() |
|
|
|
|
if contact is None: |
|
|
|
|
return HttpResponseForbidden() |
|
|
|
|
if contact.subscriber: |
|
|
|
|
contact.subscriber = False |
|
|
|
|
contact.save() |
|
|
|
|
return super(MailingSettingsUnsubscribe, self).get(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CalendarView(TemplateView): |
|
|
|
|
""" |
|
|
|
|
display template with user calendar(one month) |
|
|
|
|
|