Commit 640d2b44 authored by fred's avatar fred

add --no-updates flag to load-from-spip

parent d79604db
......@@ -6,6 +6,8 @@ import os
import re
import urllib2
from optparse import make_option
from django.core.files import File
from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify
......@@ -50,7 +52,16 @@ class Command(BaseCommand):
args = 'filename'
help = 'Load emissions and episodes from a Spip dump file'
def handle(self, filename, *args, **options):
option_list = BaseCommand.option_list + (
make_option('--no-updates',
action='store_true',
dest='dont_update',
default=False,
help='Only create new objects, do not update existing ones'),
)
def handle(self, filename, dont_update, **options):
self.do_updates = (not dont_update)
with open(filename) as fd:
content = fd.read()
# the spip_courriers parts of the spip export are not properly
......@@ -80,8 +91,9 @@ class Command(BaseCommand):
self.load_documents()
self.load_document_links()
self.process_emission_keywords()
self.process_episode_keywords()
if self.do_updates:
self.process_emission_keywords()
self.process_episode_keywords()
for emission_id in straight_emission_rubric_ids:
rubric = self.rubrics[emission_id]
......@@ -285,6 +297,10 @@ class Command(BaseCommand):
emission = Emission.objects.get(slug=slug)
except Emission.DoesNotExist:
emission = Emission()
if emission.id and not self.do_updates:
return emission
slug = slug.split(',')[0]
emission.slug = slug
emission.title = rubric.titre
......@@ -329,6 +345,10 @@ class Command(BaseCommand):
except Episode.DoesNotExist:
episode = Episode()
episode.slug = slug
if episode.id and not self.do_updates:
return episode
episode.emission = emission
episode.title = article.titre
episode.description = makeHtmlFromSpip(article.descriptif,
......@@ -392,6 +412,10 @@ class Command(BaseCommand):
newsitem = NewsItem.objects.get(slug=slug)
except NewsItem.DoesNotExist:
newsitem = NewsItem()
if newsitem.id and not self.do_updates:
return newsitem
newsitem.title = breve.titre
newsitem.slug = slug
newsitem.text = makeHtmlFromSpip(breve.texte,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment