|
|
|
|
@ -12,6 +12,7 @@ from .models import * |
|
|
|
|
from django.views.decorators.cache import never_cache |
|
|
|
|
from django.db.models import Count |
|
|
|
|
|
|
|
|
|
import pymorphy2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchDetailView(generic.DetailView): |
|
|
|
|
@ -219,3 +220,50 @@ class Search(generic.View): |
|
|
|
|
return HttpResponse(json.dumps(response), content_type="application/json") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@never_cache |
|
|
|
|
def get_random_list_trademarks(request, status='Expired', count=10): |
|
|
|
|
morph = pymorphy2.MorphAnalyzer() |
|
|
|
|
|
|
|
|
|
trademark_list = [] |
|
|
|
|
expired_trademarks = Trademark.objects.filter(status=status).order_by('?')[:count*2] |
|
|
|
|
|
|
|
|
|
for trademark in expired_trademarks: |
|
|
|
|
if len(trademark.title.split(' ')) > 3: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
for product in trademark.products.all(): |
|
|
|
|
words = product.title.split(' ') |
|
|
|
|
normalize_title = [] |
|
|
|
|
if len(words) <= 3: |
|
|
|
|
first_word = morph.parse(words[0])[0] |
|
|
|
|
if first_word.tag.POS == 'NOUN': |
|
|
|
|
for word in words: |
|
|
|
|
word = morph.parse(word)[0] |
|
|
|
|
try: |
|
|
|
|
normalize_title.append(word.inflect({'sing', 'nomn'}).word) |
|
|
|
|
except: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
glyph = Nice.objects.get(nice_id=notation[1]).glyph or 'fa-snowflake-o' |
|
|
|
|
except Nice.DoesNotExist: |
|
|
|
|
# Быть такого не должно |
|
|
|
|
glyph = 'fa-snowflake-o' |
|
|
|
|
|
|
|
|
|
trademark_list.append({ |
|
|
|
|
'product': ' '.join(normalize_title).capitalize(), |
|
|
|
|
'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") |
|
|
|
|
|
|
|
|
|
|