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.
45 lines
1.2 KiB
45 lines
1.2 KiB
# -*- coding: utf-8 -*-
|
|
import MySQLdb
|
|
from MySQLdb.cursors import DictCursor
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from functions.translate import fill_with_signal
|
|
from article.models import Article
|
|
from accounts.models import User
|
|
from django.db import IntegrityError
|
|
import xlwt
|
|
from django.utils import translation
|
|
from django.conf import settings
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
translation.activate('en')
|
|
|
|
workbook = xlwt.Workbook(encoding = 'utf8')
|
|
worksheet = workbook.add_sheet('My Worksheet')
|
|
|
|
font = xlwt.Font()
|
|
font.name = 'Times New Roman'
|
|
font.bold = True
|
|
|
|
style = xlwt.XFStyle()
|
|
# Create the Style
|
|
style.font = font
|
|
|
|
qs = Article.objects.news()
|
|
worksheet.write(0, 0, 'id')
|
|
worksheet.write(0, 1, 'url')
|
|
worksheet.write(0, 2, 'title')
|
|
|
|
row = 1
|
|
for a in qs:
|
|
print a.id
|
|
url = a.slug
|
|
id = a.id
|
|
name = a.main_title
|
|
|
|
worksheet.write(row, 0, id)
|
|
worksheet.write(row, 1, url)
|
|
worksheet.write(row, 2, name)
|
|
|
|
row += 1
|
|
workbook.save(settings.MEDIA_ROOT+'/import/exported_news.xls') |