예제 #1
0
def bulk_upload(request):
    from django.core.urlresolvers import reverse
    from os import path

    if request.method == 'POST' and 'data' in request.FILES:

        category = None
        if request.POST.get('category'):
            category = Category.objects.get(pk=int(request.POST.get('category')))
            
        from django.template.defaultfilters import slugify
        from django.core.files.base import ContentFile
        
        for uploaded_file in request.FILES.getlist('data'):
            fname, ext = path.splitext(uploaded_file.name)
            target_fname = slugify(fname) + ext.lower()
            
            mf = MediaFile()
            mf.file.save(target_fname, uploaded_file)
            mf.save()
    
            if category:
                mf.categories.add(category)
    
            mt = MediaFileTranslation()
            mt.parent  = mf
            mt.caption = fname.replace('_', ' ')
            mt.save()

        messages.info(request, _("%d files imported") % len(request.FILES.getlist('data')))
    else:
        messages.error(request, _("No input file given"))
            
    return HttpResponseRedirect(reverse('admin:medialibrary_mediafile_changelist'))
예제 #2
0
 def _processDownloadedFile(self, vidFile, title, desc, mediaPath):
     orig = os.path.join(self.tmp, vidFile)
     new = os.path.join(settings.MEDIA_ROOT, mediaPath, vidFile)
     subprocess.call(['yamdi', '-i', orig, '-o', new])
     try:
         mf = MediaFile.objects.get(file=os.path.join(mediaPath, vidFile))
     except MediaFile.DoesNotExist:
         mf = MediaFile(file=os.path.join(mediaPath, vidFile))
     mf.save()
     tr = mf.get_translation()
     if tr == None:        
         tr = MediaFileTranslation(parent=mf, language_code='cs')
     tr.caption = mark_safe(title)
     tr.description = mark_safe(desc)
     tr.save()
예제 #3
0
 def _processDownloadedFile(self, vidFile, title, desc, mediaPath):
     orig = os.path.join(self.tmp, vidFile)
     new = os.path.join(settings.MEDIA_ROOT, mediaPath, vidFile)
     subprocess.call(['yamdi', '-i', orig, '-o', new])
     try:
         mf = MediaFile.objects.get(file=os.path.join(mediaPath, vidFile))
     except MediaFile.DoesNotExist:
         mf = MediaFile(file=os.path.join(mediaPath, vidFile))
     mf.save()
     tr = mf.get_translation()
     if tr == None:
         tr = MediaFileTranslation(parent=mf, language_code='cs')
     tr.caption = mark_safe(title)
     tr.description = mark_safe(desc)
     tr.save()
예제 #4
0
def bulk_upload(request):
    from django.core.urlresolvers import reverse
    from os import path

    if request.method == 'POST' and 'data' in request.FILES:

        category = None
        if request.POST.get('category'):
            category = Category.objects.get(
                pk=int(request.POST.get('category')))

        from django.template.defaultfilters import slugify
        from django.core.files.base import ContentFile

        for uploaded_file in request.FILES.getlist('data'):
            fname, ext = path.splitext(uploaded_file.name)
            target_fname = slugify(fname) + ext.lower()

            mf = MediaFile()
            mf.file.save(target_fname, uploaded_file)
            mf.save()

            if category:
                mf.categories.add(category)

            mt = MediaFileTranslation()
            mt.parent = mf
            mt.caption = fname.replace('_', ' ')
            mt.save()

        messages.info(
            request,
            _("%d files imported") % len(request.FILES.getlist('data')))
    else:
        messages.error(request, _("No input file given"))

    return HttpResponseRedirect(
        reverse('admin:medialibrary_mediafile_changelist'))