Example #1
0
def deletesession(sessionId):
    sessiondata = WorkflowReportData.objects.filter(sessionid = sessionId)
    # delete all the files of a session
    for data in sessiondata:
        try:
            print "remove file " + data.dataurl
            with open(data.dataurl, 'wb') as f:
                destination = File(f)
                destination.delete()

            #shutil.rmtree(data.dataurl)
        except Exception as e0:
            print "Failed to delete file: " + data.dataurl

    WorkflowReportData.objects.filter(sessionid = sessionId).delete()
    WorkflowSessions.objects.filter(sessionid = sessionId).delete()
Example #2
0
class VideoData(models.Model):
    """
    エンコード後に作成され、情報が保持されるモデル
    基本的にユーザーが編集不可
    """
    video = models.OneToOneField(Video,
                                 verbose_name='動画',
                                 on_delete=models.CASCADE,
                                 related_name='data')
    thumbnail = models.ImageField('サムネイル', upload_to=thumbnail_upload_to)
    file = models.FileField('動画ファイル', upload_to=video_upload_to)
    fps = models.PositiveIntegerField('FPS')
    duration = models.FloatField('動画時間')

    def update_thumbnail(self, t):
        temp_file_path = get_tempfile('.mp4', self.file)
        clip = VideoFileClip(temp_file_path)

        next_thumbnail_path = get_tempfile('.jpg')
        clip.save_frame(next_thumbnail_path, t=t)
        clip.close()

        self.thumbnail.delete(False)
        with open(next_thumbnail_path, 'rb') as f:
            self.thumbnail = File(f)
            self.save()

    def duration_str(self):
        hour = int((self.duration / 3600))
        minute = int((self.duration % 3600) / 60)
        second = int((self.duration % 3600) % 60)

        if hour == 0:
            hour = ''
        else:
            hour = str(hour) + ':'

        result = hour + '%02d:%02d' % (minute, second)
        return result

    def delete(self, **kwargs):
        self.file.delete(False)
        self.thumbnail.delete(False)
        return super().delete(**kwargs)
Example #3
0
 def post(self, request):
     username = ""
     f = open("user.txt")
     for line in f:
         for word in line.split():
             username = word
             break
         break
     user = User.objects.get(username=username)
     all_folders = Folder.objects.select_related().filter(user=user)
     fil = request.data["file"]
     f = File.objects.select_related().filter(pk=fil).first()
     if f and f.folder in all_folders:
         file = request.data["file"]
         file1 = File.objects.select_related().filter(pk=file).first()
         file1.delete()
         return Response([{"status":"successful"}])
     else:
         return Response([{"status":"no_file"}])
Example #4
0
    def _load_files(self, base, old=[]):
        old_map = dict([(os.path.join(f.path, f.name), f) for f in old])
        new, changed = [], False

        for root, dirs, files in os.walk(base):
            for name in files:
                fullname = os.path.join(root, name)
                name_on_storage = '%s.%s' % (uuid.uuid1().hex, name)
                path = os.path.dirname(os.path.relpath(fullname, base))

                new_file = old_map.get(os.path.join(path, name))
                if new_file:
                    # Check if it's new enough.
                    old_modified = int(
                        totimestamp(
                            new_file.the_file.storage.modified_time(
                                new_file.the_file.name)))
                    new_modified = int(os.stat(fullname).st_mtime)
                    if new_modified > old_modified:
                        f = DJFile(open(fullname))
                        new_file = File(name=name, path=path, size=f.size)
                        new_file.the_file.save(name_on_storage, f)
                        changed = True
                    else:
                        new_file.reuse = True
                else:
                    f = DJFile(open(fullname))
                    new_file = File(name=name, path=path, size=f.size)
                    new_file.the_file.save(name_on_storage, f)
                    changed = True

                new.append(new_file)

        if len(old) != len(new):
            changed = True

        for f in old:
            if not getattr(f, 'reuse', False):
                f.the_file.delete()
                f.delete()

        return new, changed
Example #5
0
    def _load_files(self, base, old=[]):
        old_map = dict([(os.path.join(f.path, f.name), f) for f in old])
        new, changed = [], False

        for root, dirs, files in os.walk(base):
            for name in files:
                fullname = os.path.join(root, name)
                name_on_storage = "%s.%s" % (uuid.uuid1().hex, name)
                path = os.path.dirname(os.path.relpath(fullname, base))

                new_file = old_map.get(os.path.join(path, name))
                if new_file:
                    # Check if it's new enough.
                    old_modified = int(totimestamp(new_file.the_file.storage.modified_time(new_file.the_file.name)))
                    new_modified = int(os.stat(fullname).st_mtime)
                    if new_modified > old_modified:
                        f = DJFile(open(fullname))
                        new_file = File(name=name, path=path, size=f.size)
                        new_file.the_file.save(name_on_storage, f)
                        changed = True
                    else:
                        new_file.reuse = True
                else:
                    f = DJFile(open(fullname))
                    new_file = File(name=name, path=path, size=f.size)
                    new_file.the_file.save(name_on_storage, f)
                    changed = True

                new.append(new_file)

        if len(old) != len(new):
            changed = True

        for f in old:
            if not getattr(f, "reuse", False):
                f.the_file.delete()
                f.delete()

        return new, changed
Example #6
0
class Album(models.Model, NextPreviousMixin):
    title = models.CharField(max_length=200)
    artist = models.ForeignKey(Artist, related_name='albums')
    year = models.IntegerField(blank=True, null=True)

    cover = StdImageField(upload_to='album_covers', size=(300, 300), thumbnail_size=(125, 125), blank=True)

    slug = MySlugField('title')
    dir_name = DirNameField('get_dir_name')

    objects = AlbumManager()

    class Meta:
        ordering = ('year', 'title')

    def __unicode__(self):
        if self.year:
            return u"%s (%d)" % (self.title, self.year)
        return self.title

    def delete(self, *args, **kwargs):
        for track in self.get_tracks():
            track.delete()

        super(Album, self).delete(*args, **kwargs)

    @models.permalink
    def get_absolute_url(self):
        return ('nonclassical-album', (self.artist.slug, self.slug))

    def get_dir_name(self):
        if self.year:
            return "%d %s" % (self.year, self.title)
        return self.title

    def get_tracks(self):
        return MusicFile.objects.filter(track__cd__album=self). \
            order_by('track__cd', 'track')

    def get_nonclassical_tracks(self):
        return Track.objects.filter(cd__album=self). \
            order_by('cd__num', 'track')

    def total_duration(self):
        return self.get_tracks().aggregate(Sum('length')).values()[0] or 0

    def next(self):
        return super(Album, self).next(artist=self.artist)

    def previous(self):
        return super(Album, self).previous(artist=self.artist)

    def set_artwork_from_url(self, url):
        tempfile, headers = urllib.urlretrieve(url)
        try:
            self.cover = DjangoFile(open(tempfile))
            self.save()
        except:
            self.cover.delete()
            raise
        finally:
            try:
                os.unlink(tempfile)
            except:
                pass
Example #7
0
class Album(models.Model, NextPreviousMixin):
    title = models.CharField(max_length=200)
    artist = models.ForeignKey(Artist, related_name='albums')
    year = models.IntegerField(blank=True, null=True)

    cover = StdImageField(upload_to='album_covers',
                          size=(300, 300),
                          thumbnail_size=(125, 125),
                          blank=True)

    slug = MySlugField('title')
    dir_name = DirNameField('get_dir_name')

    objects = AlbumManager()

    class Meta:
        ordering = ('year', 'title')

    def __unicode__(self):
        if self.year:
            return u"%s (%d)" % (self.title, self.year)
        return self.title

    def delete(self, *args, **kwargs):
        for track in self.get_tracks():
            track.delete()

        super(Album, self).delete(*args, **kwargs)

    @models.permalink
    def get_absolute_url(self):
        return ('nonclassical-album', (self.artist.slug, self.slug))

    def get_dir_name(self):
        if self.year:
            return "%d %s" % (self.year, self.title)
        return self.title

    def get_tracks(self):
        return MusicFile.objects.filter(track__cd__album=self). \
            order_by('track__cd', 'track')

    def get_nonclassical_tracks(self):
        return Track.objects.filter(cd__album=self). \
            order_by('cd__num', 'track')

    def total_duration(self):
        return self.get_tracks().aggregate(Sum('length')).values()[0] or 0

    def next(self):
        return super(Album, self).next(artist=self.artist)

    def previous(self):
        return super(Album, self).previous(artist=self.artist)

    def set_artwork_from_url(self, url):
        tempfile, headers = urllib.urlretrieve(url)
        try:
            self.cover = DjangoFile(open(tempfile))
            self.save()
        except:
            self.cover.delete()
            raise
        finally:
            try:
                os.unlink(tempfile)
            except:
                pass