Пример #1
0
    def attach_data(self, data, original_filename=None, username=None, attachment_id=None,
                    media_meta=None, replace_attachment=False):
        """
            This creates the auxmedia attachment with the downloaded data.
        """
        self.last_modified = datetime.utcnow()
        is_update = False

        if not attachment_id:
            attachment_id = self.file_hash

        if (attachment_id in self.current_attachments) and replace_attachment:
            self.delete_attachment(attachment_id)
            for aux in self.aux_media:
                if aux.attachment_id == attachment_id:
                    self.aux_media.remove(aux)

        if not attachment_id in self.current_attachments:
            if not getattr(self, '_id'):
                self.save()  # let's just make sure an id has been assigned to this guy before we try to put_attachment
            self.put_attachment(data, attachment_id, content_type=self.get_mime_type(data, filename=original_filename))
            new_media = AuxMedia()
            new_media.uploaded_date = datetime.utcnow()
            new_media.attachment_id = attachment_id
            new_media.uploaded_filename = original_filename
            new_media.uploaded_by = username
            new_media.checksum = self.file_hash
            if media_meta:
                new_media.media_meta = media_meta
            self.aux_media.append(new_media)
            self.save()
            is_update = True

        return is_update
Пример #2
0
    def attach_data(self, data, original_filename=None, username=None, attachment_id=None,
                    media_meta=None):
        """
        This creates the auxmedia attachment with the downloaded data.
        """
        self.last_modified = datetime.utcnow()

        if not attachment_id:
            attachment_id = self.file_hash

        if not self._attachments or attachment_id not in self._attachments:
            if not getattr(self, '_id'):
                # put attchment blows away existing data, so make sure an id has been
                # assigned to this guy before we do it. this is the expected path
                self.save()
            else:
                # this should only be files that had attachments deleted while the bug
                # was in effect, so hopefully we will stop seeing it after a few days
                logging.error('someone is uploading a file that should have existed for multimedia %s' % self._id)
            self.put_attachment(data, attachment_id, content_type=self.get_mime_type(data, filename=original_filename))
        new_media = AuxMedia()
        new_media.uploaded_date = datetime.utcnow()
        new_media.attachment_id = attachment_id
        new_media.uploaded_filename = original_filename
        new_media.uploaded_by = username
        new_media.checksum = self.file_hash
        if media_meta:
            new_media.media_meta = media_meta
        self.aux_media.append(new_media)
        self.save()
        return True
Пример #3
0
    def attach_data(self, data, original_filename=None, username=None, attachment_id=None,
                    media_meta=None, replace_attachment=False):
        """
            This creates the auxmedia attachment with the downloaded data.
        """
        self.last_modified = datetime.utcnow()
        is_update = False

        if not attachment_id:
            attachment_id = self.file_hash

        if (attachment_id in self.current_attachments) and replace_attachment:
            self.delete_attachment(attachment_id)
            for aux in self.aux_media:
                if aux.attachment_id == attachment_id:
                    self.aux_media.remove(aux)
            is_update = True

        if not attachment_id in self.current_attachments:
            if not getattr(self, '_id'):
                self.save()  # let's just make sure an id has been assigned to this guy before we try to put_attachment
            self.put_attachment(data, attachment_id, content_type=self.get_mime_type(data))
            new_media = AuxMedia()
            new_media.uploaded_date = datetime.utcnow()
            new_media.attachment_id = attachment_id
            new_media.uploaded_filename = original_filename
            new_media.uploaded_by = username
            new_media.checksum = self.file_hash
            if media_meta:
                new_media.media_meta = media_meta
            self.aux_media.append(new_media)
            self.save()

        return is_update
Пример #4
0
    def attach_data(self, data, original_filename=None, username=None, attachment_id=None, media_meta=None):
        """
        This creates the auxmedia attachment with the downloaded data.
        """
        self.last_modified = datetime.utcnow()

        if not attachment_id:
            attachment_id = self.file_hash

        if not self._attachments or attachment_id not in self._attachments:
            if not getattr(self, "_id"):
                # put attchment blows away existing data, so make sure an id has been
                # assigned to this guy before we do it. this is the expected path
                self.save()
            else:
                # this should only be files that had attachments deleted while the bug
                # was in effect, so hopefully we will stop seeing it after a few days
                logging.error("someone is uploading a file that should have existed for multimedia %s" % self._id)
            self.put_attachment(data, attachment_id, content_type=self.get_mime_type(data, filename=original_filename))
        new_media = AuxMedia()
        new_media.uploaded_date = datetime.utcnow()
        new_media.attachment_id = attachment_id
        new_media.uploaded_filename = original_filename
        new_media.uploaded_by = username
        new_media.checksum = self.file_hash
        if media_meta:
            new_media.media_meta = media_meta
        self.aux_media.append(new_media)
        self.save()
        return True
Пример #5
0
 def attach_data(self, data, upload_path=None, username=None, attachment_id=None,
                 media_meta=None, replace_attachment=False):
     self.last_modified = datetime.utcnow()
     self.save()
     if not attachment_id:
         attachment_id = self.file_hash
     if attachment_id in self.current_attachments and replace_attachment:
         self.delete_attachment(attachment_id)
         for aux in self.aux_media:
             if aux.attachment_id == attachment_id:
                 self.aux_media.remove(aux)
         self.save()
     if not attachment_id in self.current_attachments:
         mime = magic.Magic(mime=True)
         content_type = mime.from_buffer(data)
         self.put_attachment(data, attachment_id, content_type=content_type)
         new_media = AuxMedia()
         new_media.uploaded_date = datetime.utcnow()
         new_media.attachment_id = attachment_id
         new_media.uploaded_filename = upload_path
         new_media.uploaded_by = username
         new_media.checksum = self.file_hash
         if media_meta:
             new_media.media_meta = media_meta
         self.aux_media.append(new_media)
     self.save()