From 358a38af9efc91791c693bab0bc33be5a4128e87 Mon Sep 17 00:00:00 2001
From: fefa4ka
Date: Tue, 8 Nov 2016 05:15:24 +0300
Subject: [PATCH] load in thread
---
trademark/lib/poiskznakov.py | 12 +-----------
trademark/models.py | 2 +-
trademark/templates/trademark/search_detail.html | 4 ++--
trademark/views.py | 13 ++++++++++++-
4 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/trademark/lib/poiskznakov.py b/trademark/lib/poiskznakov.py
index 0a11065..79d52e9 100644
--- a/trademark/lib/poiskznakov.py
+++ b/trademark/lib/poiskznakov.py
@@ -3,8 +3,7 @@
import urllib2
import json
-import threading
-import time
+
class TrademarkSearchAPI():
login = "Zuykov"
@@ -94,13 +93,4 @@ class TrademarkSearchAPI():
return data['records_list']['21']['records']
-class SearchResultsThread(threading.Thread):
- def __init__(self, keyword, **kwargs):
- self.keyword = keyword
- super(SearchResultsThread, self).__init__(**kwargs)
- def run(self):
- loaded = False
- while not loaded:
- time.sleep(5)
- loaded = self.keyword.load_results()
diff --git a/trademark/models.py b/trademark/models.py
index 527b87e..7ae3da4 100644
--- a/trademark/models.py
+++ b/trademark/models.py
@@ -5,7 +5,7 @@ from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
-from lib.poiskznakov import TrademarkSearchAPI, SearchResultsThread
+from lib.poiskznakov import TrademarkSearchAPI
from unidecode import unidecode
from django.template.defaultfilters import slugify
diff --git a/trademark/templates/trademark/search_detail.html b/trademark/templates/trademark/search_detail.html
index 3804eb3..52996d3 100644
--- a/trademark/templates/trademark/search_detail.html
+++ b/trademark/templates/trademark/search_detail.html
@@ -52,7 +52,7 @@
Так же есть ряд законодательных требований, которым должен соответствовать знак, не выполнение которых может привести к отказу в регистрации вашего знака.
Если же вы заинтересованы в регистрации товарного знака, мы проведем поиск сходных знаков, как уже зарегистрированных, так и заявок, поданных на регистрацию, а так же проверим ваш знак на соответствие требованиям законодательства. Это значительно (до 95%) увеличивает вероятность того, что ваш знак будет зарегистрирован.
- {% include 'trademark/registration.html' with nice_available=nice_available nice_busy=nice_busy %}
+ {% include 'trademark/registration.html' with trademark_title=keyword.request nice_available=nice_available nice_busy=nice_busy %}
{% endif %}
@@ -63,7 +63,7 @@
{% if identity.count > 0 %}
-{% include 'trademark/registration.html' with nice_available=nice_available nice_busy=nice_busy %}
+{% include 'trademark/registration.html' with trademark_title=keyword.request nice_available=nice_available nice_busy=nice_busy %}
{% endif %}
diff --git a/trademark/views.py b/trademark/views.py
index bd632dc..7b012b2 100644
--- a/trademark/views.py
+++ b/trademark/views.py
@@ -84,6 +84,16 @@ class IndexView(generic.ListView):
def get_queryset(self):
return Keyword.objects.all()
+import threading
+import time
+
+class SearchResultsThread(threading.Thread):
+ def __init__(self, keyword, **kwargs):
+ self.keyword = keyword
+ super(SearchResultsThread, self).__init__(**kwargs)
+
+ def run(self):
+ self.keyword.load_results()
class Search(generic.View):
@@ -94,7 +104,8 @@ class Search(generic.View):
def get(self, request, slug):
keyword = get_object_or_404(Keyword, slug=slug)
- keyword.load_results()
+ loading = SearchResultsThread(keyword=keyword)
+ loading.start()
identity = keyword.searches.filter(similarity=146)[0]