diff --git a/accounts/management/__init__.py b/accounts/management/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/accounts/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/accounts/management/commands/__init__.py b/accounts/management/commands/__init__.py new file mode 100644 index 00000000..3ed9fd0f --- /dev/null +++ b/accounts/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'root' diff --git a/accounts/management/commands/load_accounts.py b/accounts/management/commands/load_accounts.py new file mode 100644 index 00000000..6d2147fb --- /dev/null +++ b/accounts/management/commands/load_accounts.py @@ -0,0 +1,82 @@ +import os +import MySQLdb +from MySQLdb.cursors import DictCursor +from django.core.management.base import BaseCommand +from accounts.models import User + +def create_new_user(data): + email = data['email'] + firstname = data['firstname'] + lastname = data['lastname'] + position = data['position'] + web_page = data['web_page'] + fb = data['fb'] + li = data['li'] + sk = data['sk'] + about = data['about'] + password = data['password'] + url = data['url'] + if not url: + url = str(data['id']) + + user = User(username=email, first_name=firstname, last_name=lastname, email=email, + is_staff=False, is_active=True, is_superuser=False, password=password, position=position, url=url) + + try: + user.save() + except: + return + profile = user.profile + + profile.web_page = web_page + profile.facebook = fb + profile.linkedin = li + profile.skype = sk + profile.about = about + try: + profile.save() + except: + pass + + return + + +class Command(BaseCommand): + def handle(self, *args, **options): + db = MySQLdb.connect(host="localhost", + user="expomap", + passwd="7FbLtAGjse", + db="old_db", + charset='utf8', + cursorclass=DictCursor) + cursor = db.cursor() + sql = """ + SELECT customers_id as id, customers_email_address as email, customers_password as password, customers_firstname as firstname , + customers_lastname as lastname , customers_telephone as phone, customers_job as `position`, customers_web as web_page, + customers_facebook as fb, customers_linkedin as li, customers_skype as sk, customers_about as about, + url + FROM `customers` + where customers_email_address!='' + + """ + + + + + cursor.execute(sql) + result = cursor.fetchall() + + #user.password = result[0]['customers_password'] + + for res in result: + email = res['email'] + print(email) + try: + user = User.objects.get(username=email) + except User.DoesNotExist: + user = None + create_new_user(res) + if user: + password = res['password'] + user.password = password + user.save() diff --git a/accounts/models.py b/accounts/models.py index 909e2bda..1a68fa90 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -259,10 +259,10 @@ class Profile(models.Model): about = models.TextField(verbose_name='О себе', blank=True) avatar = models.ImageField(verbose_name='Фото', upload_to='accounts/avatar/', blank=True) skype = models.CharField(blank=True, max_length=255) - facebook = models.URLField(verbose_name=_(u'Facebook'), blank=True) - twitter = models.URLField(verbose_name=_(u'Twitter'), blank=True) - linkedin = models.URLField(verbose_name=_(u'LinkedIn'), blank=True) - vk = models.URLField(verbose_name=_(u'В контакте'), blank=True) + facebook = models.URLField(verbose_name=_(u'Facebook'), blank=True, max_length=255) + twitter = models.URLField(verbose_name=_(u'Twitter'), blank=True,max_length=255) + linkedin = models.URLField(verbose_name=_(u'LinkedIn'), blank=True, max_length=255) + vk = models.URLField(verbose_name=_(u'В контакте'), blank=True, max_length=255) # meta title = models.CharField(max_length=255, blank=True) diff --git a/banners/__init__.py b/banners/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/banners/models.py b/banners/models.py new file mode 100644 index 00000000..a690ec3f --- /dev/null +++ b/banners/models.py @@ -0,0 +1,10 @@ +from django.db import models + +# Create your models here. + +class Redirect(models.Model): + redirect = models.URLField() + count = models.PositiveIntegerField(default=0) + + def __unicode__(self): + return self.redirect diff --git a/banners/tests.py b/banners/tests.py new file mode 100644 index 00000000..501deb77 --- /dev/null +++ b/banners/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/banners/urls.py b/banners/urls.py new file mode 100644 index 00000000..a0ce0988 --- /dev/null +++ b/banners/urls.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import patterns, url + +urlpatterns = patterns('', + url(r'redirect/(?P.*)/$', 'banners.views.redirect'), +) + diff --git a/banners/views.py b/banners/views.py new file mode 100644 index 00000000..22eb6ca5 --- /dev/null +++ b/banners/views.py @@ -0,0 +1,10 @@ +from django.http import HttpResponseRedirect +from django.shortcuts import get_object_or_404 +from banners.models import Redirect +from django.db.models import F + +def redirect(request, id): + redirect = get_object_or_404(Redirect, id=id) + Redirect.objects.filter(id=id).update(count=F('count')+1) + return HttpResponseRedirect(redirect.redirect) + diff --git a/conference/views.py b/conference/views.py index 4546e609..71ec8f9d 100644 --- a/conference/views.py +++ b/conference/views.py @@ -24,7 +24,8 @@ from functions.cache_mixin import JitterCacheMixin, CacheMixin MONTHES = settings.MONTHES -class ConferenceBy(MetadataMixin, ListView): +class ConferenceBy(JitterCacheMixin, MetadataMixin, ListView): + cache_range = settings.CACHE_RANGE template_name = 'conference/conference_by.html' title1 = '' title2 = '' @@ -40,7 +41,6 @@ class ConferenceBy(MetadataMixin, ListView): class ConferenceByCountry(ConferenceBy): - cache_range = [60, 120] model = Country title1 = _(u'По странам') title2 = _(u'Коференции мира по странам') @@ -55,7 +55,6 @@ class ConferenceByCountry(ConferenceBy): class ConferenceByTheme(ConferenceBy): - cache_range = [60, 120] model = Theme title1 = _(u'По тематикам') title2 = _(u'Коференции мира по тематикам') @@ -70,7 +69,6 @@ class ConferenceByTheme(ConferenceBy): class ConferenceByCity(ConferenceBy): - cache_range = [60, 120] model = City title1 = _(u'По городам') title2 = _(u'Коференции мира по городам') @@ -84,7 +82,8 @@ class ConferenceByCity(ConferenceBy): # .order_by('translations__name').distinct() -class ConferenceCatalog(MetadataMixin, ListView): +class ConferenceCatalog(JitterCacheMixin, MetadataMixin, ListView): + cache_range = settings.CACHE_RANGE model = Conference paginate_by = settings.CLIENT_PAGINATION template_name = 'client/conference/catalog.html' @@ -276,6 +275,7 @@ class ConferenceServiceView(FormMixin, DetailView): model = Conference slug_field = 'url' service = None + success_url = '/service/thanks/' def post(self, request, *args, **kwargs): self.object = self.get_object() @@ -310,7 +310,7 @@ class ConferenceServiceView(FormMixin, DetailView): order.conference = self.object order.save() messages.success(self.request, _(u'Ваш запрос был успешно отправлен')) - return HttpResponseRedirect(self.request.path) + return HttpResponseRedirect(self.success_url) def get_initial(self): """ @@ -333,7 +333,8 @@ class ConferenceServiceView(FormMixin, DetailView): -class ConferenceDetail(MetadataMixin, DetailView): +class ConferenceDetail(JitterCacheMixin, DetailView): + cache_range = settings.CACHE_RANGE model = Conference slug_field = 'url' template_name = 'client/conference/conference_detail.html' diff --git a/exposition/models.py b/exposition/models.py index 989cfbf4..5fb497ff 100644 --- a/exposition/models.py +++ b/exposition/models.py @@ -175,6 +175,8 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin): def get_parent(self): return {} + def get_absolute_url(self): + return self.get_permanent_url() def get_index_text(self): translation.activate('ru') diff --git a/exposition/views.py b/exposition/views.py index 92756eb0..13ea4857 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -28,7 +28,7 @@ from functions.cache_mixin import JitterCacheMixin, CacheMixin -class ExpositionBy(MetadataMixin, ListView): +class ExpositionBy(JitterCacheMixin, MetadataMixin, ListView): template_name = 'exposition/exposition_by.html' title1 = '' title2 = '' @@ -135,7 +135,8 @@ def exposition_visit(request, id): #------------------------------------------------------------------------------ -class ExpoDetail(MetadataMixin, DetailView): +class ExpoDetail(JitterCacheMixin, MetadataMixin, DetailView): + cache_range = settings.CACHE_RANGE model = Exposition slug_field = 'url' template_name = 'client/exposition/exposition_detail.html' @@ -168,6 +169,7 @@ class ExpositionServiceView(MetadataMixin, FormMixin, DetailView): model = Exposition slug_field = 'url' service = None + success_url = '/service/thanks/' def dispatch(self, request, *args, **kwargs): service_url = self.kwargs.get('service_url') @@ -208,7 +210,7 @@ class ExpositionServiceView(MetadataMixin, FormMixin, DetailView): order.exposition = self.object order.save() messages.success(self.request, _(u'Ваш запрос был успешно отправлен')) - return HttpResponseRedirect(self.request.path) + return HttpResponseRedirect(self.success_url) def get_initial(self): """ diff --git a/place_exposition/views.py b/place_exposition/views.py index 1b2c33be..c72b2c38 100644 --- a/place_exposition/views.py +++ b/place_exposition/views.py @@ -14,6 +14,8 @@ from country.models import Country from city.models import City from models import PlaceExposition from meta.views import MetadataMixin +from django.conf import settings +from functions.cache_mixin import JitterCacheMixin, CacheMixin def catalog(request): @@ -49,7 +51,8 @@ class PlaceSearchView(ExpoSearchView): search_form = PlaceSearchForm model = PlaceExposition -class PlaceDetail(MetadataMixin, DetailView): +class PlaceDetail(JitterCacheMixin, MetadataMixin, DetailView): + cache_range = settings.CACHE_RANGE model = PlaceExposition search_form = PlaceSearchForm slug_field = 'url' @@ -99,7 +102,6 @@ class PlaceDetail(MetadataMixin, DetailView): class PlacePhoto(ListView): template_name = 'client/place/photo.html' obj = None - search_form = PlaceSearchForm def get_queryset(self): slug = self.kwargs.get('slug') @@ -117,11 +119,10 @@ class PlacePhoto(ListView): def get_context_data(self, **kwargs): context = super(PlacePhoto, self).get_context_data(**kwargs) context['object'] = self.obj - context['search_form'] = self.search_form return context -class PlaceList(MetadataMixin, ListView): +class PlaceList(JitterCacheMixin, MetadataMixin, ListView): model = PlaceExposition paginate_by = 10 template_name = 'client/place/place_list.html' @@ -129,7 +130,8 @@ class PlaceList(MetadataMixin, ListView): def get_queryset(self): - qs = super(PlaceList, self).get_queryset().order_by('-rating') + #qs = super(PlaceList, self).get_queryset().order_by('-rating') + qs= PlaceExposition.objects.language().select_related('country', 'city').all().order_by('-rating') conf_qs = PlaceConference.objects.language().all() return list(qs)+list(conf_qs) @@ -139,17 +141,16 @@ class PlaceList(MetadataMixin, ListView): return context -class PlaceCatalog(MetadataMixin, ListView): +class PlaceCatalog(JitterCacheMixin, MetadataMixin, ListView): + cache_range = settings.CACHE_RANGE model = PlaceExposition paginate_by = 10 - template_name = 'place/catalog.html' - search_form = PlaceSearchForm + template_name = 'client/place/catalog.html' filter_object = None def get_context_data(self, **kwargs): context = super(PlaceCatalog, self).get_context_data(**kwargs) - context['search_form'] = self.search_form context['filter_object'] = self.filter_object context['catalog_url'] = self.catalog_url @@ -164,8 +165,8 @@ class PlaceCountryCatalog(PlaceCatalog): country = get_object_or_404(Country, url=slug) self.kwargs['country'] = country self.filter_object = country - qs = self.model.objects.language().filter(country=country).order_by('-rating') - conf_qs = PlaceConference.objects.language().filter(country=country) + qs = self.model.objects.language().select_related('country', 'city').filter(country=country).order_by('-rating') + conf_qs = PlaceConference.objects.language().select_related('country', 'city').filter(country=country) return list(qs) + list(conf_qs) @@ -178,6 +179,6 @@ class PlaceCityCatalog(PlaceCatalog): city = get_object_or_404(City, url=slug) self.kwargs['city'] = city self.filter_object = city - qs = self.model.objects.language().filter(city=city).order_by('-rating') - conf_qs = PlaceConference.objects.language().filter(city=city) + qs = self.model.objects.language().select_related('country', 'city').filter(city=city).order_by('-rating') + conf_qs = PlaceConference.objects.language().select_related('country', 'city').filter(city=city) return list(qs) + list(conf_qs) \ No newline at end of file diff --git a/proj/settings.py b/proj/settings.py index cce3dfd0..4c5b602e 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -277,6 +277,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', + 'django.contrib.sitemaps', 'haystack', #custom modules 'accounts', @@ -304,6 +305,7 @@ INSTALLED_APPS = ( 'translator', 'webinar', 'meta', + 'banners', #django modules 'sorl.thumbnail', # for logos 'photologue', # photogallery diff --git a/proj/sitemaps.py b/proj/sitemaps.py new file mode 100644 index 00000000..9b4cd46e --- /dev/null +++ b/proj/sitemaps.py @@ -0,0 +1,119 @@ +import datetime +from django.contrib.sitemaps import Sitemap +from exposition.models import Exposition +from conference.models import Conference +from city.models import City +from country.models import Country +from theme.models import Theme, Tag +from article.models import Article +from django.core.paginator import Paginator + + +class Abstract(Sitemap): + changefreq = 'weekly' + priority = 0.8 + + def lastmod(self, obj): + return datetime.date.today() + + +class ExpoCard(Abstract): + changefreq = 'weekly' + priority = 0.8 + + def items(self): + return Exposition.enable.upcoming() + + def lastmod(self, obj): + return obj.modified + +class ExpoCity(Abstract): + + def items(self): + return City.used.expo_cities() + + def location(self, obj): + return "/expo/city/%s/" % obj.url + +class ExpoCountry(Abstract): + def items(self): + return Country.objects.expo_countries() + + def location(self, obj): + return "/expo/country/%s/" % obj.url + +class ExpoTheme(Abstract): + def items(self): + return Theme.active.expo_themes() + + def location(self, obj): + return "/expo/theme/%s/" % obj.url + +class ExpoTag(Abstract): + def items(self): + return Tag.active.expo_tag() + + def location(self, obj): + return "/expo/tag/%s/" % obj.url + + + +class ConfCard(Sitemap): + changefreq = 'weekly' + priority = 0.8 + + def items(self): + return Conference.enable.upcoming() + + def lastmod(self, obj): + return obj.modified + + def location(self, obj): + return "/conference/%s/" % obj.url + + +class ConfCity(Abstract): + + def items(self): + return City.used.conference_cities() + + def location(self, obj): + return "/conference/city/%s/" % obj.url + +class ConfCountry(Abstract): + def items(self): + return Country.objects.conference_countries() + + def location(self, obj): + return "/conference/country/%s/" % obj.url + +class ConfTheme(Abstract): + def items(self): + return Theme.active.conference_themes_with_count() + + def location(self, obj): + return "/conference/theme/%s/" % obj.url + +class ConfTag(Abstract): + def items(self): + return Tag.active.conference_tags() + + def location(self, obj): + return "/conference/tag/%s/" % obj.url + + +class NewsSiteMap(Abstract): + priority = 0.5 + def items(self): + return Article.objects.news().filter(publish_date__isnull=False) + + def location(self, obj): + return "/news/%s/" % obj.slug + +class BlogsSiteMap(Abstract): + priority = 0.5 + def items(self): + return Article.objects.blogs().filter(publish_date__isnull=False) + + def location(self, obj): + return "/blogs/%s/" % obj.slug \ No newline at end of file diff --git a/proj/urls.py b/proj/urls.py index bb004455..808c691e 100644 --- a/proj/urls.py +++ b/proj/urls.py @@ -10,9 +10,23 @@ class Robot(TemplateView): template_name = 'robot.txt' content_type = 'text/plain' + +from django.contrib.sitemaps import Sitemap +from exposition.models import Exposition + +from sitemaps import ExpoCard, ExpoCity, ExpoCountry, ExpoTheme, ExpoTag, ConfCard, ConfCity, ConfCountry, ConfTheme,\ + ConfTag, NewsSiteMap, BlogsSiteMap + +sitemaps = { + 'expo': ExpoCard(), 'news': NewsSiteMap(), 'blogs': BlogsSiteMap(),#'expo_city': ExpoCity(), 'expo_country': ExpoCountry(), 'expo_theme': ExpoTheme(), \ + 'conference': ConfCard(), 'expo_tag': ExpoTag(), 'conference_city': ConfCity(), 'conference_country': ConfCountry(),\ + 'conference_theme': ConfTheme(), 'conference_tag': ConfTag() +} + urlpatterns = patterns('', #url(r'^__debug__/', include(debug_toolbar.urls)), url(r'^admin/', include('proj.admin_urls')), + url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), url(r'^robot\.txt$', Robot.as_view()), url(r'^$', MainPageView.as_view()), url(r'^theme/', include('theme.urls')), @@ -43,8 +57,9 @@ urlpatterns = patterns('', url(r'^accounts/', include('registration.backends.default.urls')), url(r'^', include('password_reset.urls')), url(r'^i18n/', include('django.conf.urls.i18n')), + url(r'^redirect/', include('banners.urls')), #url(r'^social/', include('social_auth.urls')), - #url(r'^', include('settings.old_urls')), + url(r'^', include('settings.old_urls')), #url(r'^search/', include('haystack.urls')), url(r'^', include('service.urls')), ) diff --git a/proj/views.py b/proj/views.py index 0e73f49d..925e676f 100644 --- a/proj/views.py +++ b/proj/views.py @@ -8,6 +8,7 @@ from exposition.models import Exposition from theme.models import Theme from news.models import News from article.models import Article +from functions.cache_mixin import JitterCacheMixin, CacheMixin from functions.forms import ThemeSearch, PlaceSearch @@ -29,7 +30,8 @@ def expo_context(request): return cont -class MainPageView(TemplateView): +class MainPageView(JitterCacheMixin,TemplateView): + cache_range = settings.CACHE_RANGE template_name = 'index.html' def get_context_data(self, **kwargs): diff --git a/service/models.py b/service/models.py index 7eba79b1..0e5eaeec 100644 --- a/service/models.py +++ b/service/models.py @@ -88,7 +88,7 @@ class Tickets(AbstractOrder): class Remote(AbstractOrder): interested_participants = models.TextField(blank=True) - additional = models.CharField(max_length=255) + additional = models.CharField(max_length=255, blank=True) class Participation(AbstractOrder): @@ -97,12 +97,12 @@ class Participation(AbstractOrder): company_inf = models.TextField() class Translation(AbstractOrder): - days = models.IntegerField() - hours = models.IntegerField() - fr = models.DateField() - to = models.DateField() - languages = models.TextField() - themes = models.TextField() + days = models.IntegerField(null=True,blank=True) + hours = models.IntegerField(null=True, blank=True) + fr = models.DateField(blank=True) + to = models.DateField(blank=True) + languages = models.TextField(blank=True) + themes = models.TextField(blank=True) class Visit(AbstractOrder): fr = models.DateField() diff --git a/service/order_forms.py b/service/order_forms.py index 0bf38f8c..319db724 100644 --- a/service/order_forms.py +++ b/service/order_forms.py @@ -105,7 +105,7 @@ ADDITIONAL_REMOTE_CHOICES = [(_(u'официальный каталог'), _(u' ] class RemoteForm(AbstractOrderForm): - additional = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=ADDITIONAL_REMOTE_CHOICES) + additional = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=ADDITIONAL_REMOTE_CHOICES, required=False) class Meta: model = Remote @@ -130,12 +130,10 @@ LANGS = [(_(u'Русский'), _(u'Русский'))] from theme.models import Theme class TranslationForm(AbstractOrderForm): - languages = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), - choices=LANGS) - themes = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), - choices=[(theme.id, theme.id) for theme in Theme.objects.language().filter()]) - fr = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateFrom', 'placeholder': _(u'дд.мм.гггг')})) - to = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateTo', 'placeholder': _(u'дд.мм.гггг')})) + languages = forms.CharField(required=False) + themes = forms.CharField(required=False) + fr = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateFrom', 'placeholder': _(u'дд.мм.гггг')}), required=False) + to = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateTo', 'placeholder': _(u'дд.мм.гггг')}), required=False) class Meta: model = Translation diff --git a/templates/client/article/article.html b/templates/client/article/article.html index f2e6882b..6c87ca98 100644 --- a/templates/client/article/article.html +++ b/templates/client/article/article.html @@ -46,12 +46,13 @@ - +{% with blogs=object.similars %} +{% if blogs %}
- {% for blog in object.similars %} + {% for blog in blogs %}
+{% endif %} +{% endwith %} {% endblock %} \ No newline at end of file diff --git a/templates/client/base_catalog.html b/templates/client/base_catalog.html index 7918d644..674a7eae 100644 --- a/templates/client/base_catalog.html +++ b/templates/client/base_catalog.html @@ -22,11 +22,8 @@ {% if theme_for_filter.id == 27 or theme_for_filter.id == 9 or theme_for_filter.id == 48 %} @@ -68,7 +65,7 @@ {% endwith %} {% block under_search_baner %}
- +
{% endblock %} diff --git a/templates/client/includes/exposition/exposition_list.html b/templates/client/includes/exposition/exposition_list.html index 0329abbe..5dabdba6 100644 --- a/templates/client/includes/exposition/exposition_list.html +++ b/templates/client/includes/exposition/exposition_list.html @@ -90,6 +90,8 @@
+ + {% if forloop.counter == 8 %}