- |
+ |
{% thumbnail obj.get_logo '281x225' as im %}
{% endthumbnail %}
|
-
+ |
@@ -152,7 +152,7 @@
{% with sqs_obj.object as obj %}
- |
+ |
{% thumbnail obj.get_logo '109x114' as im %}
{% endthumbnail %}
@@ -230,9 +230,9 @@
|
- |
+ |
{% if obj.get_event_place_name %}
-
+
{{ obj.get_event_place_name }}
{% endif %}
|
@@ -292,7 +292,7 @@
{% for sqs_obj in foreign %}
{% with sqs_obj.object as obj %}
- |
+ |
|
@@ -302,9 +302,9 @@
|
- |
+ |
{% if obj.get_event_place_name %}
-
+
{{ obj.get_event_place_name }}
{% endif %}
|
diff --git a/functions/custom_views.py b/functions/custom_views.py
index 27851453..acb4f081 100644
--- a/functions/custom_views.py
+++ b/functions/custom_views.py
@@ -36,6 +36,7 @@ from file.forms import FileModelForm
from file.models import TmpFile
from functions.forms import AdminSearchForm
from functions.views_help import split_params
+from functions.http import JsonResponse
from haystack.query import EmptySearchQuerySet
from hvad.utils import get_translation_aware_manager
from meta.models import MetaSetting
diff --git a/functions/forms.py b/functions/forms.py
index 4b00e3e7..9addd2f4 100644
--- a/functions/forms.py
+++ b/functions/forms.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from django import forms
from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import force_text
from django.db.models import ObjectDoesNotExist
from django.forms.models import ModelChoiceIterator
@@ -186,17 +187,42 @@ class FieldsetMixin(object):
}
-class CustomModelChoiceIterator(ModelChoiceIterator):
- def __init__(self, field):
- self.field = field
- self.queryset = getattr(field, 'c_queryset', field.queryset.none())
+# class CustomModelChoiceIterator(ModelChoiceIterator):
+# def __init__(self, field):
+# self.field = field
+# self.queryset = getattr(field, 'c_queryset', field.queryset.none())
+
+
+class OrderedSelectMultiple(forms.SelectMultiple):
+ def render_options(self, choices, selected_choices):
+ self.choices.queryset = self.choices.queryset.filter(pk__in=selected_choices)
+ choices = dict(self.choices)
+ selected_choices_str = set(force_text(v) for v in selected_choices)
+ output = []
+ for choice in selected_choices:
+ label = choices.get(choice)
+ if label:
+ output.append(self.render_option(selected_choices_str, choice, label))
+ # unselected_choices = set(choices.iterkeys()).difference(selected_choices)
+ # if unselected_choices:
+ # for option_value, option_label in filter(lambda x: x[0] in unselected_choices, choices.iteritems()):
+ # if isinstance(option_label, (list, tuple)):
+ # output.append(format_html('')
+ # else:
+ # output.append(self.render_option(selected_choices_str, option_value, option_label))
+ return '\n'.join(output)
class ML_ModelMultipleChoiceField(forms.ModelMultipleChoiceField):
- def _get_choices(self):
- if hasattr(self, '_choices'):
- return self._choices
- return CustomModelChoiceIterator(self)
- choices = property(_get_choices, forms.ChoiceField._set_choices)
+ widget = OrderedSelectMultiple
+ # def _get_choices(self):
+ # if hasattr(self, '_choices'):
+ # return self._choices
+ # return CustomModelChoiceIterator(self)
+ # choices = property(_get_choices, forms.ChoiceField._set_choices)
+
diff --git a/functions/utils.py b/functions/utils.py
index 28aea224..6339456f 100644
--- a/functions/utils.py
+++ b/functions/utils.py
@@ -1,7 +1,9 @@
-from string import Template
+# -*- coding: utf-8 -*-
+# from string import Template
+import string
+from datetime import timedelta, datetime
-
-class DeltaTemplate(Template):
+class DeltaTemplate(string.Template):
delimiter = "%"
@@ -14,3 +16,25 @@ def strfdelta(tdelta, fmt):
d["S"] = '{:02d}'.format(seconds)
t = DeltaTemplate(fmt)
return t.substitute(**d)
+
+
+class CachedSting(object):
+ def __init__(self, path, timeout=None):
+ super(CachedSting, self).__init__()
+ self.path = path
+ self.timeout = timeout or timedelta(days=1)
+ self.get_object()
+
+ def __repr__(self):
+ return self.__str__()
+
+ def __str__(self):
+ if self.timeto > datetime.now():
+ return self.object
+ self.get_object()
+ return self.object
+
+ def get_object(self):
+ self.timeto = datetime.now() + self.timeout
+ with open(self.path, 'r') as f:
+ self.object = f.read()
diff --git a/proj/config.ini b/proj/config.ini
index 05e83239..f05c5f7f 100644
--- a/proj/config.ini
+++ b/proj/config.ini
@@ -3,3 +3,4 @@ expo_city = [-2960561, -2996338, -1044367, -1762397, -1746443, -1771148, -192446
conf_city = [-2960561, -2996338, -1044367]
expo_country = [159, 47, 40, 186, 31, 99, 87, 60]
conf_country = [159, 47, 187]
+
diff --git a/settings/admin.py b/settings/admin.py
index 318858c5..87f9b39e 100644
--- a/settings/admin.py
+++ b/settings/admin.py
@@ -9,7 +9,11 @@ from django.core.context_processors import csrf
from django.conf import settings
from functions.custom_views import ContextMixin
-from forms import MainPageArticle, MainPageNews, MainPageThemes, EventSectionSettingsForm
+from .forms import MainPageArticle
+from .forms import MainPageNews
+from .forms import MainPageThemes
+from .forms import EventSectionSettingsForm
+from .forms import EventDefaultDescriptionEditForm
def handle_form(request, form):
@@ -81,3 +85,13 @@ class EventSectionSettings(ContextMixin, FormView):
def form_valid(self, form):
form.save()
return super(EventSectionSettings, self).form_valid(form)
+
+
+class EventDefaultDescription(ContextMixin, FormView):
+ form_class = EventDefaultDescriptionEditForm
+ template_name = 'c_admin/settings/default_description.html'
+ success_url = reverse_lazy('settings_default_description')
+
+ def form_valid(self, form):
+ form.save()
+ return super(EventDefaultDescription, self).form_valid(form)
diff --git a/settings/admin_urls.py b/settings/admin_urls.py
index 7bd2c78b..ed0cc041 100644
--- a/settings/admin_urls.py
+++ b/settings/admin_urls.py
@@ -1,6 +1,12 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
-from .admin import handle_themes, handle_news, handle_articles, main_page, EventSectionSettings
+from .admin import handle_themes
+from .admin import handle_news
+from .admin import handle_articles
+from .admin import main_page
+from .admin import EventSectionSettings
+from .admin import EventDefaultDescription
+
urlpatterns = patterns('',
url(r'^main-page/themes/', handle_themes, name='settings_main_page_themes'),
@@ -9,5 +15,6 @@ urlpatterns = patterns('',
url(r'^main-page/$', main_page, name='settings_main_page'),
url(r'^sections/$', EventSectionSettings.as_view(), name='settings_sections'),
+ url(r'^description/$', EventDefaultDescription.as_view(), name='settings_default_description'),
)
diff --git a/settings/forms.py b/settings/forms.py
index c977412a..7b6b91a9 100644
--- a/settings/forms.py
+++ b/settings/forms.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import os
import json
from itertools import chain
@@ -10,7 +11,7 @@ from django.core.exceptions import (
)
from django.db.models import Q
from django.utils.encoding import force_text
-from django.utils.html import format_html
+# from django.utils.html import format_html
from django.utils.translation import ugettext as _
from django.conf import settings
from django.core.urlresolvers import reverse, reverse_lazy
@@ -53,28 +54,6 @@ class ParticipationCommentForm(CommentForm):
model = ParticipationComment
-class OrderedSelectMultiple(forms.SelectMultiple):
- def render_options(self, choices, selected_choices):
- choices = dict(self.choices)
- selected_choices_str = set(force_text(v) for v in selected_choices)
- output = []
- for choice in selected_choices:
- label = choices.get(choice)
- if label:
- output.append(self.render_option(selected_choices_str, choice, label))
- # unselected_choices = set(choices.iterkeys()).difference(selected_choices)
- # if unselected_choices:
- # for option_value, option_label in filter(lambda x: x[0] in unselected_choices, choices.iteritems()):
- # if isinstance(option_label, (list, tuple)):
- # output.append(format_html('')
- # else:
- # output.append(self.render_option(selected_choices_str, option_value, option_label))
- return '\n'.join(output)
-
-
class OredredMixin(object):
def clean(self, value):
if self.required and not value:
@@ -107,7 +86,7 @@ class OrderedModelMultipleChoiceField(OredredMixin, forms.ModelMultipleChoiceFie
class OML_MMChoiceField(OredredMixin, ML_ModelMultipleChoiceField):
- widget = OrderedSelectMultiple
+ pass
class MainPageThemes(forms.Form):
@@ -159,6 +138,7 @@ class MainPageArticle(forms.Form):
class EventSectionSettingsForm(forms.Form):
+ verbose = _(u'Блок "самые популярные"')
expo_city = OML_MMChoiceField(label=_(u'Каталог городов (выставки)'),
queryset=City.objects.all(), required=False)
conf_city = OML_MMChoiceField(label=_(u'Каталог городов (конференции)'),
@@ -176,9 +156,9 @@ class EventSectionSettingsForm(forms.Form):
'data-ajax-url': reverse('admin_{model}_search'.format(model=model)),
'select2': 'true',
})
- if self.initial[name]:
- field.c_queryset = field.queryset.filter(pk__in=self.initial[name])
- field.widget.choices = field.choices
+ # if self.initial[name]:
+ # field.c_queryset = field.queryset.filter(pk__in=self.initial[name])
+ # field.widget.choices = field.choices
def save(self):
INI_CONFIG = settings.INI_CONFIG
@@ -191,3 +171,33 @@ class EventSectionSettingsForm(forms.Form):
for lang_code, name in settings.LANGUAGES:
for key_attr in ['C_CITY_CATALOG_KEY', 'C_COUNTRY_CATALOG_KEY', 'E_CITY_CATALOG_KEY', 'E_COUNTRY_CATALOG_KEY']:
cache.delete(getattr(settings, key_attr) + '_' + lang_code)
+
+
+class EventDefaultDescriptionEditForm(forms.Form):
+ data_mapping = {
+ 'e_description_ru': 'templates/client/includes/conference/default_description_ru.html',
+ 'e_description_en': 'templates/client/includes/conference/default_description_en.html',
+ 'c_description_ru': 'templates/client/includes/exposition/default_description_ru.html',
+ 'c_description_en': 'templates/client/includes/exposition/default_description_en.html',
+ }
+ e_description_ru = forms.CharField(label=_(u'Описание для выставки'), required=False, widget=CKEditorWidget)
+ e_description_en = forms.CharField(label=_(u'Описание для выставки'), required=False, widget=CKEditorWidget)
+ c_description_ru = forms.CharField(label=_(u'Описание для конференции'), required=False, widget=CKEditorWidget)
+ c_description_en = forms.CharField(label=_(u'Описание для конференции'), required=False, widget=CKEditorWidget)
+
+ def __init__(self, *args, **kwargs):
+ super(EventDefaultDescriptionEditForm, self).__init__(*args, **kwargs)
+ for field_name, path in self.data_mapping.iteritems():
+ try:
+ with open(os.path.join(settings.SITE_ROOT, path), 'r') as f:
+ self.initial[field_name] = f.read()
+ except:
+ pass
+
+ def save(self):
+ for field_name, path in self.data_mapping.iteritems():
+ try:
+ with open(os.path.join(settings.SITE_ROOT, path), 'w+') as f:
+ f.write(self.cleaned_data.get(field_name))
+ except:
+ pass
diff --git a/static/mailing_settings/js/main.js b/static/mailing_settings/js/main.js
index a97c0a2a..09cb2492 100644
--- a/static/mailing_settings/js/main.js
+++ b/static/mailing_settings/js/main.js
@@ -1,5 +1,17 @@
'use strict';
+function sendForm () {
+ var $form = $('#mailing_settings_form');
+ $.ajax({
+ url: $form.attr('action'),
+ type: $form.attr('method'),
+ data: $form.serializeArray(),
+ success: function(response){
+ console.log(response);
+ }
+ })
+}
+
// Выбор тем
(function () {
var $themes_modal = $('.popup-window.themes'),
@@ -124,6 +136,8 @@
}
$.fancybox.close();
+
+ sendForm();
});
@@ -145,6 +159,7 @@
removeCheckbox($input.attr('name'), $input.val());
$(this).parent('li').remove();
+ sendForm();
});
@@ -157,6 +172,7 @@
removeCheckbox($input.attr('name'), $input.val());
$(this).parent('li').remove();
+ sendForm();
});
})();
@@ -211,6 +227,7 @@
}
$.fancybox.close();
+ sendForm();
});
@@ -225,6 +242,7 @@
$('#id_' + $input.attr('name')).find('option[value="' + $input.val() + '"]').remove();
$(this).parent('li').remove();
+ sendForm();
});
})();
@@ -303,8 +321,6 @@
$selected_co.append($co);
});
- console.log(user_countries);
-
// открываем список тегов в теме
$countries_modal.on('click', '.trigger', function (e) {
e.preventDefault();
@@ -359,6 +375,7 @@
}
$.fancybox.close();
+ sendForm();
});
// Удаление выбранного континента
@@ -370,6 +387,7 @@
removeCheckbox($input.attr('name'), $input.val());
$(this).parent('li').remove();
+ sendForm();
});
@@ -382,6 +400,7 @@
removeCheckbox($input.attr('name'), $input.val());
$(this).parent('li').remove();
+ sendForm();
});
})();
diff --git a/templates/c_admin/includes/admin_nav.html b/templates/c_admin/includes/admin_nav.html
index 3a006838..010ddbeb 100644
--- a/templates/c_admin/includes/admin_nav.html
+++ b/templates/c_admin/includes/admin_nav.html
@@ -46,7 +46,8 @@
Услуги
Управление услугами
Главная страница
- Разделы событий
+ {% trans 'Блок "Самые популярные" (каталог)' %}
+ {% trans 'Описание по умолчанию' %}
Мета
Перевод
diff --git a/templates/c_admin/settings/default_description.html b/templates/c_admin/settings/default_description.html
new file mode 100644
index 00000000..786c3660
--- /dev/null
+++ b/templates/c_admin/settings/default_description.html
@@ -0,0 +1,119 @@
+{% extends 'base.html' %}
+{% load i18n %}
+{% load static %}
+
+
+{% block scripts %}
+
+{% endblock %}
+
+
+{% block body %}
+
+
+{% endblock %}
diff --git a/templates/c_admin/settings/sections.html b/templates/c_admin/settings/sections.html
index 4599b75c..8de2eba2 100644
--- a/templates/c_admin/settings/sections.html
+++ b/templates/c_admin/settings/sections.html
@@ -147,7 +147,7 @@
| | | |