sketch with ico

remotes/origin/upgrade-requirements
Dmitriy Shesterkin 9 years ago
parent 739dc139dc
commit 5330881dad
  1. 45
      trademark/landing/api.py

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import random import random
import pymorphy2 import pymorphy2
from trademark.models import Trademark, Product from trademark.models import Trademark, Product, Nice
from django.http import HttpResponse from django.http import HttpResponse
import json import json
@ -30,7 +30,10 @@ def _get_dic_words(words):
return words_dict return words_dict
def get_notation(list_words, normalize=False): def get_notation(list_words, normalize=False, t=0):
if t:
print 't', list_words
if len(list_words) > 1: if len(list_words) > 1:
notation = list_words[random.randint(0, len(list_words) - 1)] notation = list_words[random.randint(0, len(list_words) - 1)]
@ -38,14 +41,18 @@ def get_notation(list_words, normalize=False):
notation = list_words[0] notation = list_words[0]
if normalize: if normalize:
morph = pymorphy2.MorphAnalyzer().parse(notation)[0] print 'normalize 44', notation, notation[0], notation[1]
morph = pymorphy2.MorphAnalyzer().parse(notation[0])[0]
try: try:
result = morph.inflect({'plur', 'nomn'}).word result = morph.inflect({'plur', 'nomn'}).word, notation[1]
except: except:
result = get_notation(list_words, normalize=True) result = get_notation(list_words, normalize=True, t=1)
else: else:
result = notation # print notation
result = result.capitalize() result = notation[0], notation[1]
result = result[0].capitalize(), result[1]
return result return result
@ -61,6 +68,7 @@ def get_lists_for_notation(trademark):
products = trademark.products.all() products = trademark.products.all()
for product in products: for product in products:
if product: if product:
nice_id = product.nice_id
product_phrase = product.title.split(',') product_phrase = product.title.split(',')
for phrase in product_phrase: for phrase in product_phrase:
@ -75,21 +83,21 @@ def get_lists_for_notation(trademark):
replace('\n', '') replace('\n', '')
if len(words.split()) == 1: if len(words.split()) == 1:
_words.append(words.replace(' ', '')) _words.append((words.replace(' ', ''), nice_id))
fraction_phrase = words.lower().split(' ') fraction_phrase = words.lower().split(' ')
for word in fraction_phrase: for word in fraction_phrase:
p = morph.parse(word)[0] p = morph.parse(word)[0]
if len(word) >= 3 and p.tag.POS == 'NOUN': if len(word) >= 3 and p.tag.POS == 'NOUN':
_generic_words.append(p.normal_form) _generic_words.append((p.normal_form, nice_id))
except Product.DoesNotExist: except Product.DoesNotExist:
return False, False return False, False
return _words, _generic_words return _words, _generic_words
def get_random_list_trademarks(request, status='Expired', count=10): def get_random_list_trademarks(request, status='Expired', count=10):
ico = ''
notation = '' notation = ''
trademark_list = [] trademark_list = []
@ -101,17 +109,26 @@ def get_random_list_trademarks(request, status='Expired', count=10):
if words: if words:
notation = get_notation(words) notation = get_notation(words)
# print 'words', notation, notation[1]
if not words and generic_words: if not words and generic_words:
# print generic_words
notation = get_notation(generic_words, normalize=True) notation = get_notation(generic_words, normalize=True)
# print 'generic_words', notation, notation[0], notation[1]
if notation: if notation:
brand = u'{notation} "{title}"'.format(notation=notation, title=trademark) brand = u'{notation} "{title} "'.format(notation=notation[0], title=trademark)
# print u'%s' % notation + u' "%s"' % 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
except Nice.DoesNotExist:
ico = 'fa-snowflake-o'
else: else:
brand = u'{}'.format(trademark) brand = u'{}'.format(trademark)
trademark_list.append({'name': brand, trademark_list.append({'name': brand,
'ico': 'fa' 'ico': u'fa {}'.format(ico)
}) })
response = {'count': len(trademark_list), 'status': 'ok', 'items': trademark_list} response = {'count': len(trademark_list), 'status': 'ok', 'items': trademark_list}

Loading…
Cancel
Save