Лэндинг для онлайн поиска + мелкие исправления

remotes/origin/HEAD
Alexander Kondratyev 9 years ago
parent c6c2344ed0
commit 4ea60d578d
  1. 41
      trademark/landing/api.py
  2. 12
      trademark/models.py
  3. 24
      trademark/static/trademark/js/landing.js
  4. 32
      trademark/static/trademark/less/landing.less
  5. 1
      trademark/static/trademark/less/main.less
  6. 15
      trademark/templates/trademark/index.html
  7. 5
      trademark/views.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")

@ -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())

@ -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();
}]);

@ -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);}
}
}

@ -1,3 +1,4 @@
@import 'landing.less';
@import 'result.less';
@import 'detail.less';
@import 'loading.less';

@ -5,7 +5,18 @@
</h1>
{% include 'trademark/form.html' %}
<h3>Для вдохновения</h3>
<p>Исключительные права на эти товарные знаки не продлили, поэтому их <a href="http://zuykov.com/ru/trademarks/registraciya-tovarnogo-znaka/">регистрация</a> возможна после проведения <a href="http://zuykov.com/ru/trademarks/poisk-tovarnogo-znaka/">полного поиска</a>.</p>
{% verbatim %}
<div ng-controller="TrademarkSearchLandingCtrl" ng-show="trademarks">
<h3>Для вдохновения</h3>
<p>Исключительные права на эти товарные знаки не продлили, поэтому их <a href="http://zuykov.com/ru/trademarks/registraciya-tovarnogo-znaka/">регистрация</a> возможна после проведения <a href="http://zuykov.com/ru/trademarks/poisk-tovarnogo-znaka/">полного поиска</a>.</p>
<ul class='list-inline trademark-search-landing-examples'>
<li class="trademark-search-landing-examples-loading">
<button class="btn btn-primary" ng-click='load()'><i class="fa fa-refresh" area-hidden="true" ng-class="{ 'glyphicon-refresh-animate': loading }"></i><span>{{loading_text}}</span></button>
</li>
<li class="trademark-search-landing-examples-item" ng-repeat="trademark in trademarks"><h3><i class="fa {{ trademark.glyph }}" aria-hidden="true"></i></h3>{{trademark.product}} «<a href="/ru/trademarks/online-search/trademark/{{trademark.trademark}}/">{{trademark.name}}</a>»</li>
</ul>
</div>
{% endverbatim %}
{% endblock %}

@ -10,6 +10,7 @@ import json
from .models import *
from django.views.decorators.cache import never_cache
from django.db.models import Count
@ -119,8 +120,8 @@ class ProductDetailView(generic.DetailView):
context['product'] = product
context['nice'] = Nice.objects.get(nice_id=product.nice_id)
context['trademarks_expired'] = product.trademark_set.filter(status='Expired').order_by('?')[:42]
context['trademarks_acting'] = product.trademark_set.filter(status='Acting').order_by('?')[:42]
context['trademarks_expired'] = product.trademark_set.annotate(num_nices=Count('nices')).filter(status='Expired', num_nices__lt=4).order_by('?')[:42]
context['trademarks_acting'] = product.trademark_set.annotate(num_nices=Count('nices')).filter(status='Acting', num_nices__lt=4).order_by('?')[:42]
return context

Loading…
Cancel
Save