You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
1.0 KiB

from django.core.management.base import BaseCommand, CommandError
from exposition.models import Exposition
import urllib2
from django.conf import settings
from django.utils import translation
def handle_expo(item):
logo = item.get_logo()
translation.activate('en')
domain = 'http://hit.expomap.ru'
url = domain+logo.file_path.url
file_name = url.split('/')[-1]
download_to = settings.MEDIA_ROOT+'exposition/logo/'+file_name
try:
response = urllib2.urlopen(url, timeout=5)
except:
print('download error')
return None
with open(download_to,'wb') as f:
f.write(response.read())
f.close()
file_name = 'exposition/logo/'+file_name
item.logo = file_name
item.save()
class Command(BaseCommand):
def handle(self, *args, **options):
for exposition in Exposition.objects.all('en'):
if exposition.files.filter(purpose='logo').exists():
handle_expo(exposition)
print(exposition)