Browse Source

minor fixes

devel
Dmitry Novikov 7 years ago
parent
commit
008fb866fe
  1. 10
      abonapp/migrations/0002_auto_20180808_1448.py
  2. 3
      abonapp/models.py
  3. 1
      messenger/models.py

10
abonapp/migrations/0002_auto_20180808_1448.py

@ -20,14 +20,17 @@ def backup_info(apps, _):
print('\tbackup_info') print('\tbackup_info')
Abon = apps.get_model('abonapp', 'Abon') Abon = apps.get_model('abonapp', 'Abon')
obs = Abon.objects.exclude(ip_address=None).only('ip_address', 'is_dynamic_ip') obs = Abon.objects.exclude(ip_address=None).only('ip_address', 'is_dynamic_ip')
with open(TMP_FILE, 'w') as f:
serializers.serialize('json', obs, stream=f, fields=('ip_address', 'is_dynamic_ip'))
if obs.exists():
with open(TMP_FILE, 'w') as f:
serializers.serialize('json', obs, stream=f, fields=('ip_address', 'is_dynamic_ip'))
print('\tEND backup_info') print('\tEND backup_info')
def restore_info_to_new_scheme(apps, _): def restore_info_to_new_scheme(apps, _):
print('\trestore_info_to_new_scheme') print('\trestore_info_to_new_scheme')
Abon = apps.get_model('abonapp', 'Abon') Abon = apps.get_model('abonapp', 'Abon')
if not os.path.isfile(TMP_FILE):
return
with open(TMP_FILE, 'r') as f: with open(TMP_FILE, 'r') as f:
for abon in load(f): for abon in load(f):
ip_addr = abon['fields'].get('ip_address') ip_addr = abon['fields'].get('ip_address')
@ -66,8 +69,7 @@ def restore_info_to_new_scheme(apps, _):
else: else:
print('\tUser with pk=%s not found' % abon['pk']) print('\tUser with pk=%s not found' % abon['pk'])
print('\tEND restore_info_to_new_scheme') print('\tEND restore_info_to_new_scheme')
if os.path.isfile(TMP_FILE):
os.remove(TMP_FILE)
os.remove(TMP_FILE)
class Migration(migrations.Migration): class Migration(migrations.Migration):

3
abonapp/models.py

@ -7,8 +7,7 @@ from django.conf import settings
from django.core import validators from django.core import validators
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
from django.db import models, connection, transaction from django.db import models, connection, transaction
from django.db.models.signals import pre_delete, post_init, \
pre_save
from django.db.models.signals import post_init, pre_save
from django.dispatch import receiver from django.dispatch import receiver
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.utils import timezone from django.utils import timezone

1
messenger/models.py

@ -1,4 +1,3 @@
from typing import Iterable
from urllib.parse import urljoin from urllib.parse import urljoin
from django.conf import settings from django.conf import settings

Loading…
Cancel
Save