From be10fba3199a6f5def91c5c15ccc9693d634451d Mon Sep 17 00:00:00 2001 From: Nazar Kotjuk Date: Mon, 26 Oct 2015 15:12:23 +0200 Subject: [PATCH] fix extra queries bug --- city/models.py | 5 +-- conference/models.py | 6 ++- country/management/__init__.py | 1 - country/management/commands/__init__.py | 1 - .../commands/country_coordinates.py | 25 ------------ .../commands/country_update_from_old.py | 39 ------------------- country/manager.py | 9 +---- country/models.py | 8 ++-- exposition/models.py | 3 +- seminar/models.py | 3 +- webinar/models.py | 3 +- 11 files changed, 17 insertions(+), 86 deletions(-) delete mode 100644 country/management/__init__.py delete mode 100644 country/management/commands/__init__.py delete mode 100644 country/management/commands/country_coordinates.py delete mode 100644 country/management/commands/country_update_from_old.py diff --git a/city/models.py b/city/models.py index d0be0311..a216d34c 100644 --- a/city/models.py +++ b/city/models.py @@ -18,10 +18,9 @@ from functions.signal_handlers import post_save_handler, pre_save_handler from functions.models_methods import ExpoManager, CityManager from service.models import Service - -#flags = [str(item.url) for item in Service.objects.all()] if db_table_exists('service_service') else [] #check if table exist and create flags if true -flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] if db_table_exists('service_service') else [] +#flags = [str(item.url) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] class City(TranslatableModel): diff --git a/conference/models.py b/conference/models.py index 8f067230..9e2b545e 100644 --- a/conference/models.py +++ b/conference/models.py @@ -2,6 +2,7 @@ import datetime from django.utils.translation import ugettext as _ from django.db import models +from django.conf import settings from django.db.models import Q from django.db.models.signals import post_save, pre_save from django.contrib.contenttypes import generic @@ -22,8 +23,9 @@ from functions.model_mixin import EventMixin, ExpoMixin from functions.models_methods import hvad_to_dict # check if table exist and create flags if true -flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] -from django.conf import settings +#flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] + CURRENCY = settings.CURRENCY BIT_AUDIENCE = settings.BIT_AUDIENCE diff --git a/country/management/__init__.py b/country/management/__init__.py deleted file mode 100644 index 13ef41a7..00000000 --- a/country/management/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'kotzilla' diff --git a/country/management/commands/__init__.py b/country/management/commands/__init__.py deleted file mode 100644 index 13ef41a7..00000000 --- a/country/management/commands/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'kotzilla' diff --git a/country/management/commands/country_coordinates.py b/country/management/commands/country_coordinates.py deleted file mode 100644 index abe3a38d..00000000 --- a/country/management/commands/country_coordinates.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -import MySQLdb -from MySQLdb.cursors import DictCursor -from django.core.management.base import BaseCommand, CommandError -from country.models import Country - - -class Command(BaseCommand): - def handle(self, *args, **options): - # local database(will not work on production) - db = MySQLdb.connect(host="localhost", - user="root", - passwd="qazedc", - db="test", - charset='utf8', - cursorclass=DictCursor) - cursor = db.cursor() - # !!!database can change - sql = "SELECT country_code as code, geo_lat as latitude, geo_lng as longitude FROM test.country_country LEFT JOIN localization.meta_location ON test.country_country.country_code=localization.meta_location.iso COLLATE utf8_unicode_ci WHERE localization.meta_location.type='CO' AND geo_lat IS NOT NULL;" - cursor.execute(sql) - result = cursor.fetchall() - for item in result: - updates = Country.objects.filter(country_code=item['code']).update(latitude=item['latitude'], longitude=item['longitude']) - if updates: - print(item['code']) \ No newline at end of file diff --git a/country/management/commands/country_update_from_old.py b/country/management/commands/country_update_from_old.py deleted file mode 100644 index 5c70e1f9..00000000 --- a/country/management/commands/country_update_from_old.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -import MySQLdb -from MySQLdb.cursors import DictCursor -from django.core.management.base import BaseCommand, CommandError -from django.utils import translation -from country.models import Country - - -def get_from_old(country): - db = MySQLdb.connect(host="localhost", - user="kotzilla", - passwd="qazedc", - db="test2", - charset='utf8', - cursorclass=DictCursor) - cursor = db.cursor() - sql = """SELECT url, inflect FROM old_expomap.products_places WHERE title="%(name)s" """%{'name': country.name.encode('utf-8')} - #print(country.name.encode('utf-8')) -# print(sql) - cursor.execute(sql) - result = cursor.fetchone() - - return result - - -class Command(BaseCommand): - def handle(self, *args, **options): - translation.activate('ru') - for country in Country.objects.all(): - old_data = get_from_old(country) - if old_data is None: - continue - country.old_url = old_data['url'] - country.inflect = old_data['inflect'] - try: - country.save() - print(country) - except: - continue \ No newline at end of file diff --git a/country/manager.py b/country/manager.py index 1d4b278e..672ca2a2 100644 --- a/country/manager.py +++ b/country/manager.py @@ -1,19 +1,12 @@ import datetime from django.utils import translation from django.core.cache import cache -from django.utils.translation import get_language as lang from hvad.models import TranslationManager class CountryManager(TranslationManager): cache_time = 600 - ''' - def all(self): - """ - hack - """ - return super(TranslationManager, self).all().filter(translations__language_code=lang()).order_by('translations__name') - ''' + def safe_get(self, **kwargs): model = self.model try: diff --git a/country/models.py b/country/models.py index 36bb5a99..9578ad08 100644 --- a/country/models.py +++ b/country/models.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- from datetime import date from django.db import models +from django.utils import translation from django.contrib.contenttypes import generic from django.db.models.signals import post_save, pre_save from hvad.models import TranslatableModel, TranslatedFields from bitfield import BitField from manager import CountryManager, AreaManager -# models from directories.models import Language, Currency from city.models import City from service.models import Service @@ -16,14 +16,14 @@ from organiser.models import Organiser from conference.models import Conference from seminar.models import Seminar from webinar.models import Webinar -# func from functions.db import db_table_exists from functions.signal_handlers import post_save_handler, pre_save_handler -from django.utils import translation + # check if table exist and create flags if true -flags = [str(item.url) for item in Service.objects.all()] if db_table_exists('service_service') else [] +#flags = [str(item.url) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] class Area(TranslatableModel): diff --git a/exposition/models.py b/exposition/models.py index eb21de6d..9fd2fdce 100644 --- a/exposition/models.py +++ b/exposition/models.py @@ -37,7 +37,8 @@ BIT_AUDIENCE = settings.BIT_AUDIENCE CURRENCY = settings.CURRENCY # check if table exist and create flags if true -flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] +#flags = [item.url for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] class Exposition(TranslatableModel, EventMixin, ExpoMixin): diff --git a/seminar/models.py b/seminar/models.py index f25ac9d5..14ba3096 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -14,7 +14,8 @@ from functions.models_methods import ExpoManager from functions.model_mixin import EventMixin, ExpoMixin # check if table exist and create flags if true -flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +#flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] CURRENCY = ('RUB', 'USD', 'EUR') diff --git a/webinar/models.py b/webinar/models.py index 75eb9d2e..55bed4ae 100644 --- a/webinar/models.py +++ b/webinar/models.py @@ -13,7 +13,8 @@ from functions.models_methods import ExpoManager from functions.model_mixin import EventMixin, ExpoMixin # check if table exist and create flags if true -flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +#flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] +flags = ['catalog', 'translator', 'participation', 'remote', 'tickets', 'visit', 'buildstand'] CURRENCY = ('RUB', 'USD', 'EUR')