Commit 640d2b44 authored by fred's avatar fred

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

parent d79604db
...@@ -6,6 +6,8 @@ import os ...@@ -6,6 +6,8 @@ import os
import re import re
import urllib2 import urllib2
from optparse import make_option
from django.core.files import File from django.core.files import File
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify from django.utils.text import slugify
...@@ -50,7 +52,16 @@ class Command(BaseCommand): ...@@ -50,7 +52,16 @@ class Command(BaseCommand):
args = 'filename' args = 'filename'
help = 'Load emissions and episodes from a Spip dump file' 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: with open(filename) as fd:
content = fd.read() content = fd.read()
# the spip_courriers parts of the spip export are not properly # the spip_courriers parts of the spip export are not properly
...@@ -80,8 +91,9 @@ class Command(BaseCommand): ...@@ -80,8 +91,9 @@ class Command(BaseCommand):
self.load_documents() self.load_documents()
self.load_document_links() self.load_document_links()
self.process_emission_keywords() if self.do_updates:
self.process_episode_keywords() self.process_emission_keywords()
self.process_episode_keywords()
for emission_id in straight_emission_rubric_ids: for emission_id in straight_emission_rubric_ids:
rubric = self.rubrics[emission_id] rubric = self.rubrics[emission_id]
...@@ -285,6 +297,10 @@ class Command(BaseCommand): ...@@ -285,6 +297,10 @@ class Command(BaseCommand):
emission = Emission.objects.get(slug=slug) emission = Emission.objects.get(slug=slug)
except Emission.DoesNotExist: except Emission.DoesNotExist:
emission = Emission() emission = Emission()
if emission.id and not self.do_updates:
return emission
slug = slug.split(',')[0] slug = slug.split(',')[0]
emission.slug = slug emission.slug = slug
emission.title = rubric.titre emission.title = rubric.titre
...@@ -329,6 +345,10 @@ class Command(BaseCommand): ...@@ -329,6 +345,10 @@ class Command(BaseCommand):
except Episode.DoesNotExist: except Episode.DoesNotExist:
episode = Episode() episode = Episode()
episode.slug = slug episode.slug = slug
if episode.id and not self.do_updates:
return episode
episode.emission = emission episode.emission = emission
episode.title = article.titre episode.title = article.titre
episode.description = makeHtmlFromSpip(article.descriptif, episode.description = makeHtmlFromSpip(article.descriptif,
...@@ -392,6 +412,10 @@ class Command(BaseCommand): ...@@ -392,6 +412,10 @@ class Command(BaseCommand):
newsitem = NewsItem.objects.get(slug=slug) newsitem = NewsItem.objects.get(slug=slug)
except NewsItem.DoesNotExist: except NewsItem.DoesNotExist:
newsitem = NewsItem() newsitem = NewsItem()
if newsitem.id and not self.do_updates:
return newsitem
newsitem.title = breve.titre newsitem.title = breve.titre
newsitem.slug = slug newsitem.slug = slug
newsitem.text = makeHtmlFromSpip(breve.texte, 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