Commit a83f36f6 authored by fred's avatar fred
Browse files

do not update image field is the filename is identical

parent 96d94674
......@@ -265,9 +265,7 @@ class Command(BaseCommand):
elif emission.description:
image_path = re.findall('src="/(media/IMG.*?)"', emission.description, re.DOTALL)
if image_path:
image_path = image_path[0]
emission.image = File(file(image_path))
self.set_image(emission, image_path)
emission.save()
emission.categories.clear()
......@@ -304,9 +302,7 @@ class Command(BaseCommand):
elif episode.description:
image_path = re.findall('src="/(media/IMG.*?)"', episode.description, re.DOTALL)
if image_path:
image_path = image_path[0]
episode.image = File(file(image_path))
self.set_image(episode, image_path)
for motcle in article.mots_cles:
episode.tags.add(motcle.lower())
......@@ -341,19 +337,25 @@ class Command(BaseCommand):
soundfile.file = File(file('media/IMG/' + episode_file.filename))
soundfile.save()
for breve in breves.values():
slug = breve.url.lower()
try:
newsitem = NewsItem.objects.get(slug=breve.url.lower())
newsitem = NewsItem.objects.get(slug=slug)
except NewsItem.DoesNotExist:
newsitem = NewsItem()
newsitem.title = breve.titre
newsitem.slug = breve.url.lower()
newsitem.slug = slug
newsitem.text = makeHtmlFromSpip(breve.texte,
documents=documents) or None
newsitem.datetime = datetime.strptime(breve.date_heure, '%Y-%m-%d %H:%M:%S')
image_path = re.findall('src="/(media/IMG.*?)"', newsitem.text, re.DOTALL)
if image_path:
image_path = image_path[0]
newsitem.image = File(file(image_path))
self.set_image(newsitem, image_path)
newsitem.save()
def set_image(self, object, image_path):
if not image_path:
return
image_path = image_path[0]
if object.image and os.path.basename(object.image.path) == os.path.basename(image_path):
return
object.image = File(file(image_path))
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