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.
 
 
 
 
 
 

69 lines
1.8 KiB

# -*- coding: utf-8 -*-
import MySQLdb
import datetime
from django.utils.translation import activate
from MySQLdb.cursors import DictCursor
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
import xlrd
from import_xls.utils import to_theme, to_tag
from functions.translate import fill_with_signal
from article.models import Article
from accounts.models import User
from django.db import IntegrityError
from exposition.models import Exposition
NEWS_FILE = settings.MEDIA_ROOT+'/import/exported_news.xls'
BLOGS_FILE = settings.MEDIA_ROOT+'/import/blogs.xls'
class Command(BaseCommand):
def handle(self, *args, **options):
activate('ru')
f = open(BLOGS_FILE, 'r')
book = xlrd.open_workbook(file_contents=f.read())
sheet = book.sheet_by_index(0)
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)]
print(len(row_list))
existing = 0
for row_number, row in enumerate(row_list[2:]):
id = int(row[0])
if id == 49:
continue
main_title = row[1]
theme = row[2]
tag = row[3]
description = row[4]
article = Article.objects.language('ru').get(id=id)
#article.main_title = main_title
#article.description = description
#article.save()
to_theme(article, theme)
to_tag(article, tag)
print(id)
"""
try:
expo = Exposition.objects.filter(translations__name=event)[0]
except IndexError:
expo = None
if expo:
article.exposition = expo
article.save()
print(id)
"""