Commit f3f64e58 authored by fred's avatar fred

add an error message when trying to double book a diffusion

parent f7d042b4
......@@ -53,12 +53,17 @@ def is_already_in_soma(diffusion):
return True
return os.path.exists(os.path.join(LOCAL_BASE_PATH, get_diffusion_file_path(diffusion)))
class DuplicateDiffusionSlot(Exception):
pass
def add_diffusion(diffusion):
soundfile = diffusion.episode.soundfile_set.filter(fragment=False)[0]
diffusion_path = get_diffusion_file_path(diffusion)
# copy file
if os.path.exists(LOCAL_BASE_PATH):
if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
raise DuplicateDiffusionSlot()
os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
shutil.copyfile(soundfile.file.path,
os.path.join(LOCAL_BASE_PATH, diffusion_path, os.path.basename(soundfile.file.path)))
......
......@@ -351,9 +351,13 @@ class AddDiffusionView(DetailView):
def get(self, request, *args, **kwargs):
diffusion = self.get_object()
utils.add_diffusion(diffusion)
episode = diffusion.episode
messages.info(self.request, _('%s added to soma') % episode.emission.title)
try:
utils.add_diffusion(diffusion)
except utils.DuplicateDiffusionSlot:
messages.error(self.request, _('soma slot already in use, the diffusion could not be added.'))
else:
messages.info(self.request, _('%s added to soma') % episode.emission.title)
return HttpResponseRedirect(reverse('episode-view', kwargs={
'emission_slug': episode.emission.slug,
'slug': episode.slug}))
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