diff --git a/trademark/landing/api.py b/trademark/landing/api.py index 4aa3a33..17eb139 100644 --- a/trademark/landing/api.py +++ b/trademark/landing/api.py @@ -5,6 +5,7 @@ import pymorphy2 from trademark.models import Trademark, Product, Nice from django.http import HttpResponse import json +from django.views.decorators.cache import never_cache def _get_random_list(qs): @@ -41,11 +42,11 @@ def get_notation(list_words, normalize=False, t=0): notation = list_words[0] if normalize: - print 'normalize 44', notation, notation[0], notation[1] + # print 'normalize 44', notation, notation[0], notation[1] morph = pymorphy2.MorphAnalyzer().parse(notation[0])[0] try: - result = morph.inflect({'plur', 'nomn'}).word, notation[1] + result = morph.inflect({'sing', 'nomn'}).word, notation[1] except: result = get_notation(list_words, normalize=True, t=1) else: @@ -96,17 +97,21 @@ def get_lists_for_notation(trademark): return _words, _generic_words +@never_cache def get_random_list_trademarks(request, status='Expired', count=10): ico = '' notation = '' trademark_list = [] - expired_trademarks = Trademark.objects.filter(status=status) - random_list = _get_random_list(expired_trademarks)[:count] + expired_trademarks = Trademark.objects.filter(status=status).order_by('?') + random_list = _get_random_list(expired_trademarks)[:count*2] for trademark in random_list: words, generic_words = get_lists_for_notation(trademark) + if len(trademark.title.split(' ')) > 3: + continue + if words: notation = get_notation(words) # print 'words', notation, notation[1] @@ -115,22 +120,28 @@ def get_random_list_trademarks(request, status='Expired', count=10): notation = get_notation(generic_words, normalize=True) # print 'generic_words', notation, notation[0], notation[1] if notation: - brand = u'{notation} "{title} "'.format(notation=notation[0], title=trademark) - # print u'%s' % notation[0] + u' "%s"' % trademark try: pass # print notation[1] # print notation - ico = Nice.objects.get(nice_id=notation[1]).glyph + glyph = Nice.objects.get(nice_id=notation[1]).glyph or 'fa-snowflake-o' except Nice.DoesNotExist: - ico = 'fa-snowflake-o' + glyph = 'fa-snowflake-o' else: - brand = u'{}'.format(trademark) - - trademark_list.append({'name': brand, - 'ico': u'fa {}'.format(ico) - }) - - response = {'count': len(trademark_list), 'status': 'ok', 'items': trademark_list} + continue + # brand = u'{}'.format(trademark) + + trademark_list.append({ + 'product': notation[0], + 'name': trademark.title.title(), + 'trademark': trademark.id, + 'glyph': glyph + }) + + response = { + 'count': len(trademark_list), + 'status': 'ok', + 'items': trademark_list[:count] + } return HttpResponse(json.dumps(response), content_type="application/json") diff --git a/trademark/models.py b/trademark/models.py index 52c732a..fbdd5d3 100644 --- a/trademark/models.py +++ b/trademark/models.py @@ -70,7 +70,7 @@ class Nice(models.Model): alphabet = defaultdict(lambda : defaultdict(list)) for product in self.popular_products: letter = product.title[0].upper() - first_word = product.title.split(' ')[0] + first_word = product.title.split(' ')[0].replace(',', '') # if title_sense: alphabet[letter][first_word.capitalize()].append(product) @@ -82,21 +82,21 @@ class Nice(models.Model): if len(products) == 1: del alphabet[letter][first_word] product = products.pop() - words = product.title + words = product.title.strip() alphabet[letter][words] = product.id else: words = [] for product in alphabet[letter][first_word]: title = re.sub("[\(\[].*?[\)\]]", "", product.title) - title_sense = title.replace(first_word, '').strip() + title_sense = title.replace(first_word, '') if title_sense: + if title_sense[0] == ',': + title_sense = title_sense[1:].strip() words.append(title_sense) - # words = [product.title for product in alphabet[letter][first_word]] - alphabet[letter][first_word] = ', '.join(set(words)) + alphabet[letter][first_word] = ', '.join([word for word in set(words) if word]) letter_items = alphabet[letter] alphabet[letter] = sorted(letter_items.items(), key=lambda x: type(x[1])) - # alphabet[letter] = letter_items.items() return sorted(alphabet.items()) diff --git a/trademark/static/trademark/js/landing.js b/trademark/static/trademark/js/landing.js new file mode 100644 index 0000000..674d09f --- /dev/null +++ b/trademark/static/trademark/js/landing.js @@ -0,0 +1,24 @@ + +angular.module('zuykov') + +.controller('TrademarkSearchLandingCtrl', ['$scope', '$http', function ($scope, $http) { + $scope.load = function () { + $scope.trademarks = []; + $scope.loading = true; + $scope.loading_text = 'Загрузка'; + $http.get('/ru/trademarks/online-search/random-trademarks/'). + success(function(data, status, headers, config) { + $scope.trademarks = data.items; + + $scope.loading = false; + $scope.loading_text = 'Показать ещё'; + }). + error(function(data, status, headers, config) { + $scope.loading = false; + $scope.loading_text = 'Показать ещё'; + }); + }; + + $scope.load(); + +}]); \ No newline at end of file diff --git a/trademark/static/trademark/less/landing.less b/trademark/static/trademark/less/landing.less new file mode 100644 index 0000000..30838bf --- /dev/null +++ b/trademark/static/trademark/less/landing.less @@ -0,0 +1,32 @@ +.trademark-search-landing-examples { + margin: 0 auto; + width: 75%; + + .trademark-search-landing-examples-loading { + width: 100%; + text-align: center; + } + .trademark-search-landing-examples-item { + text-align: center; + width: 45%; + margin-top: 15px; + } + + i { + margin-right: 5px; + } + .glyphicon-refresh-animate { + -animation: spin 1s infinite linear; + -webkit-animation: spin2 1s infinite linear; + } + + @-webkit-keyframes spin2 { + from { -webkit-transform: rotate(0deg);} + to { -webkit-transform: rotate(360deg);} + } + + @keyframes spin { + from { transform: scale(1) rotate(0deg);} + to { transform: scale(1) rotate(360deg);} + } +} \ No newline at end of file diff --git a/trademark/static/trademark/less/main.less b/trademark/static/trademark/less/main.less index 5aeb8d1..e1a4da2 100644 --- a/trademark/static/trademark/less/main.less +++ b/trademark/static/trademark/less/main.less @@ -1,3 +1,4 @@ +@import 'landing.less'; @import 'result.less'; @import 'detail.less'; @import 'loading.less'; diff --git a/trademark/templates/trademark/index.html b/trademark/templates/trademark/index.html index 051ada6..354828e 100644 --- a/trademark/templates/trademark/index.html +++ b/trademark/templates/trademark/index.html @@ -5,7 +5,18 @@ {% include 'trademark/form.html' %} -
Исключительные права на эти товарные знаки не продлили, поэтому их регистрация возможна после проведения полного поиска.
+{% verbatim %} +Исключительные права на эти товарные знаки не продлили, поэтому их регистрация возможна после проведения полного поиска.
+ +