fix extra queries bug

remotes/origin/1203
Nazar Kotjuk 10 years ago
parent ce857f4140
commit be10fba319
  1. 5
      city/models.py
  2. 6
      conference/models.py
  3. 1
      country/management/__init__.py
  4. 1
      country/management/commands/__init__.py
  5. 25
      country/management/commands/country_coordinates.py
  6. 39
      country/management/commands/country_update_from_old.py
  7. 9
      country/manager.py
  8. 8
      country/models.py
  9. 3
      exposition/models.py
  10. 3
      seminar/models.py
  11. 3
      webinar/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):

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

@ -1 +0,0 @@
__author__ = 'kotzilla'

@ -1 +0,0 @@
__author__ = 'kotzilla'

@ -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'])

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

@ -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:

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

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

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

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

Loading…
Cancel
Save