diff --git a/app/requirements.txt b/app/requirements.txt index ed9584c..c3a96be 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -12,7 +12,6 @@ django-appconf==1.0.1 django-appdata==0.1.4 django-classy-tags==0.6.2 django-cms==3.1.3 -django-cms-smartsnippets==0.1.3 django-debug-toolbar==1.4 django-durationfield==0.5.2 django-easy-select2==1.3.1 @@ -39,7 +38,6 @@ djangocms-admin-style==0.2.8 djangocms-column==1.5 djangocms-file==0.1 djangocms-flash==0.2.0 -djangocms-forms==0.1.15 djangocms-googlemap==0.3 djangocms-inherit==0.1 djangocms-installer==0.8.1 diff --git a/app/settings.py b/app/settings.py index 0fb73aa..58c6ab1 100644 --- a/app/settings.py +++ b/app/settings.py @@ -269,7 +269,7 @@ INSTALLED_APPS = ( # 'debug_toolbar', 'djangocms_forms', 'smartsnippets', - # 'easy_select2', + 'easy_select2', 'promo', 'trademark', diff --git a/trademark/landing/__init__.py b/trademark/landing/__init__.py deleted file mode 100644 index a5682fb..0000000 --- a/trademark/landing/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/trademark/landing/api.py b/trademark/landing/api.py deleted file mode 100644 index a50e4d8..0000000 --- a/trademark/landing/api.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import random -import pymorphy2 -from trademark.models import Trademark, Product -from django.http import HttpResponse -import json - - -def _get_random_list(qs): - - _list = list(qs) - random.shuffle(_list) - - return _list - - -def _get_dic_words(words): - - words_dict = {} - - for key in words: - key = key.lower() - if key in words_dict: - value = words_dict[key] - words_dict[key] = value + 1 - else: - words_dict[key] = 1 - - return words_dict - - -def get_notation(list_words, normalize=False): - - if len(list_words) > 1: - notation = list_words[random.randint(0, len(list_words) - 1)] - else: - notation = list_words[0] - - if normalize: - morph = pymorphy2.MorphAnalyzer().parse(notation)[0] - try: - result = morph.inflect({'plur', 'nomn'}).word - except: - result = get_notation(list_words, normalize=True) - else: - result = notation - result = result.capitalize() - - return result - - -def get_lists_for_notation(trademark): - - _words = [] - _generic_words = [] - - morph = pymorphy2.MorphAnalyzer() - - try: - products = trademark.products.all() - for product in products: - if product: - product_phrase = product.title.split(',') - - for phrase in product_phrase: - words = phrase.\ - lower().\ - replace(';', '').\ - replace('.', '').\ - replace('[', '').\ - replace(']', ''). \ - replace('(', ''). \ - replace(')', ''). \ - replace('\n', '') - - if len(words.split()) == 1: - _words.append(words.replace(' ', '')) - - fraction_phrase = words.lower().split(' ') - for word in fraction_phrase: - p = morph.parse(word)[0] - if len(word) >= 3 and p.tag.POS == 'NOUN': - _generic_words.append(p.normal_form) - - except Product.DoesNotExist: - return False, False - - return _words, _generic_words - - -def get_random_list_trademarks(request, status='Expired', count=10): - notation = '' - trademark_list = [] - - expired_trademarks = Trademark.objects.filter(status=status) - random_list = _get_random_list(expired_trademarks)[:count] - - for trademark in random_list: - words, generic_words = get_lists_for_notation(trademark) - - if words: - notation = get_notation(words) - if not words and generic_words: - notation = get_notation(generic_words, normalize=True) - - if notation: - brand = u'{notation} "{title}"'.format(notation=notation, title=trademark) - # print u'%s' % notation + u' "%s"' % trademark - else: - brand = u'{}'.format(trademark) - - trademark_list.append({'name': brand, - 'ico': 'fa' - }) - - response = {'count': len(trademark_list), 'status': 'ok', 'items': trademark_list} - - return HttpResponse(json.dumps(response), content_type="application/json") \ No newline at end of file diff --git a/trademark/urls.py b/trademark/urls.py index bb7c9f3..910f7cd 100644 --- a/trademark/urls.py +++ b/trademark/urls.py @@ -13,7 +13,6 @@ urlpatterns = patterns('', url(r'^products/(?P[\w-]+)/$', views.ProductDetailView.as_view(), name='product-detail'), url(r'^results/(?P[\w-]+)/$', views.SearchDetailView.as_view(), name='search-detail'), url(r'^trademark/(?P[\w-]+)/$', views.TrademarkDetailView.as_view(), name='trademark-detail'), - url(r'^random-trademarks/', get_random_list_trademarks, name='random-trademarks'), url(r'^request/(?P[\w-]+)/$', views.Search.as_view(), name='search-detail'), url(r'^request/$', views.Search.as_view(), name='search'), )