예제 #1
0
 def get_custom_sorted(self, **kwargs):
     """
         Checks for a callable custom sorting.
         And returns its result.
         This does not necessarily return a queryset. It can return any type,
         it all depends on the return value of the custom sorting. In my case
         I had to implement natural sorting and could not find a way of doing it
         with a queryset so had to return a list.
     """
     qs = self.get_query_set().filter(**kwargs)
     ordering = callable_from_string(settings.UPLOADIT_FILE_SORTING)
     if callable(ordering):
         customsorted = ordering(qs)
         return customsorted
     return qs
예제 #2
0
from os import unlink as delete_file

from celery.task import Task
from celery import registry, group

from uploadit.utils import callable_from_string
from uploadit.conf import settings
from uploadit.models import UploadedFile



UPLOADIT_PROCESS_FILE = callable_from_string(settings.UPLOADIT_PROCESS_FILE)


class UploaditFileUpload(Task):
    """ This task is in charge of uploading the file to the proper location in media
        and creating the db objects.
        This task can be called by a single image upload( uploadit.views.upload_image ),
        or a multiple image upload ( uploadit.utils.upload_images ).
        Beware that if calling this task from uploadit.views.upload_image, the image is a tmp file created
        by django's TemporaryFileUploadHandler which gives the image a random name, so you will lose the original name.
    """
    name = "uploadit.tasks.upload_file"
    ignore_result = True

    def run(self, **kwargs):
        """
            @filepath: Path to the temporary uploaded file.
            @filename - Original name of the file.
        """
        logger = self.get_logger()
예제 #3
0
from django.db import models
from django.core.files import File

from uploadit.managers import FileManager
from uploadit.conf import settings
from uploadit.utils import callable_from_string


file_model = callable_from_string(settings.UPLOADIT_FILE_MODEL)


class UploadedFile(file_model):
    """
        Represents an uploaded file in the db.
    """

    objects = FileManager()

    class Meta:
        ordering = settings.UPLOADIT_OBJECTS_ORDERING


def process_file(**kwargs):
    """
        Default file processor.
    """
    filepath, filename = kwargs.pop("filepath"), kwargs.pop("filename")
    newargs = dict()
    for arg in kwargs:
        try:
            UploadedFile._meta.get_field_by_name(arg)