|
|
|
|
@ -3,7 +3,7 @@ import dateutil.relativedelta as rdelta |
|
|
|
|
import json, datetime |
|
|
|
|
import calendar as python_calendar |
|
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
|
from django.http import HttpResponseRedirect, HttpResponse, Http404 |
|
|
|
|
from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponseForbidden |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.utils.translation import ugettext as _, get_language |
|
|
|
|
from django_messages.forms import SendForm |
|
|
|
|
@ -27,21 +27,74 @@ class SettingsView(TemplateView): |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
template_name = 'client/accounts/settings.html' |
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super(SettingsView, self).get_context_data(**kwargs) |
|
|
|
|
context['change_password_form'] = ChangePasswordForm() |
|
|
|
|
|
|
|
|
|
def get_announce_form(self): |
|
|
|
|
user = self.request.user |
|
|
|
|
try: |
|
|
|
|
contact = user.contact_set.get(email=user.username) |
|
|
|
|
except Contact.DoesNotExist: |
|
|
|
|
contact = None |
|
|
|
|
if not contact: |
|
|
|
|
return SubscribeSettingsForm() |
|
|
|
|
setting = contact.contactsettings |
|
|
|
|
initial = {'email': contact.email} |
|
|
|
|
|
|
|
|
|
initial['city'] = ','.join(['%s:%s'%(item.id, item.name) for item in set(setting.city.all())]) |
|
|
|
|
if setting.exponent_practicum or setting.organiser_practicum or setting.theme.exists(): |
|
|
|
|
initial['get_announce'] = True |
|
|
|
|
# north america check |
|
|
|
|
if setting.area.filter(id=SubscribeSettingsForm.NA_ID).exists(): |
|
|
|
|
initial['na_expo'] = True |
|
|
|
|
# asia check |
|
|
|
|
if setting.area.filter(id=SubscribeSettingsForm.ASIA_ID).exists(): |
|
|
|
|
initial['asia_expo'] = True |
|
|
|
|
# europe check |
|
|
|
|
if setting.area.filter(id=SubscribeSettingsForm.EUROPE_ID).exists(): |
|
|
|
|
initial['europe_expo'] = True |
|
|
|
|
|
|
|
|
|
form = SubscribeSettingsForm(instance=setting, initial=initial) |
|
|
|
|
return form |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super(SettingsView, self).get_context_data(**kwargs) |
|
|
|
|
context['change_password_form'] = ChangePasswordForm() |
|
|
|
|
context['subscribe'] = self.get_announce_form() |
|
|
|
|
|
|
|
|
|
if contact: |
|
|
|
|
context['subscribe'] = SubscribeSettingsForm(instance=contact.contactsettings) |
|
|
|
|
else: |
|
|
|
|
context['subscribe'] = SubscribeSettingsForm() |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
|
def save_announce_settings(request): |
|
|
|
|
|
|
|
|
|
if request.POST: |
|
|
|
|
user = request.user |
|
|
|
|
email = request.POST.get('email') or user.username |
|
|
|
|
|
|
|
|
|
# check if setting subscription already exist |
|
|
|
|
try: |
|
|
|
|
contact, created = user.contact_set.get(email=email), False |
|
|
|
|
except Contact.DoesNotExist: |
|
|
|
|
contact, created = Contact.objects.create_contact(email, user, create_setting=True), True |
|
|
|
|
setting = contact.contactsettings |
|
|
|
|
form = SubscribeSettingsForm(request.POST, instance=setting) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
setting = form.save(commit=False) |
|
|
|
|
setting.contact = contact |
|
|
|
|
setting.save() |
|
|
|
|
form.save_m2m() |
|
|
|
|
form.save_additional_fields(setting) |
|
|
|
|
else: |
|
|
|
|
errors = form.errors |
|
|
|
|
not_valid |
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('accounts_settings')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dates_range(date1, date2): |
|
|
|
|
delta = date2 - date1 |
|
|
|
|
dates = [] |
|
|
|
|
@ -54,7 +107,7 @@ class CalendarView(TemplateView): |
|
|
|
|
display template with user calendar(one month) |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
template_name = 'accounts/calendar.html' |
|
|
|
|
template_name = 'client/accounts/calendar.html' |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
""" |
|
|
|
|
@ -155,7 +208,7 @@ class ProfileView(TemplateView): |
|
|
|
|
|
|
|
|
|
in template forms handles dynamically by ajax |
|
|
|
|
""" |
|
|
|
|
template_name = 'accounts/new_profile.html' |
|
|
|
|
template_name = 'client/accounts/new_profile.html' |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super(ProfileView, self).get_context_data(**kwargs) |
|
|
|
|
|