Пример #1
0
    def upload_complete(self, request, filename, upload):
        path = settings.MEDIA_URL + "/" + filename
        self._dest.close()

        self._dir = settings.MEDIA_ROOT

        # Avoid File.objects.create, as this will try to make
        # Another file copy at FileField's 'upload_to' dir
        new_File = File()
        new_File.file = os.path.join(self._dir, filename)
        new_File.type = "N"  # This field was initially not allowed NULL
        if request.user.is_authenticated():
            new_File.owner = request.user
        else:
            new_File.owner, _created = User.objects.get_or_create(
                username=self.DEFAULT_UPLOADER_USERNAME)
        new_File.save()
        #print "uploaded file saved!"
        if not request.user.is_authenticated():
            #print 'adding unclaimed files to session'
            if self.SESSION_UNCLAIMED_FILES_KEY in request.session:
                request.session[self.SESSION_UNCLAIMED_FILES_KEY].append(
                    new_File.pk)
            else:
                request.session['unclaimed_files'] = [new_File.pk]

        # Asynchronously process document with Google Documents API
        print "upload_complete, firing task"
        tasks.process_document.delay(new_File)

        return {
            "path": path,
            "file_pk": new_File.pk,
            "file_url": new_File.get_absolute_url()
        }
Пример #2
0
    def upload_complete(self, request, filename, upload):
        path = settings.MEDIA_URL + "/" + filename
        self._dest.close()

        self._dir = settings.MEDIA_ROOT

        # Avoid File.objects.create, as this will try to make
        # Another file copy at FileField's 'upload_to' dir
        new_File = File()
        new_File.file = os.path.join(self._dir, filename)
        new_File.type = "N"  # This field was initially not allowed NULL
        if request.user.is_authenticated():
            new_File.owner = request.user
        else:
            new_File.owner, _created = User.objects.get_or_create(username=self.DEFAULT_UPLOADER_USERNAME)
        new_File.save()
        #print "uploaded file saved!"
        if not request.user.is_authenticated():
            #print 'adding unclaimed files to session'
            if self.SESSION_UNCLAIMED_FILES_KEY in request.session:
                request.session[self.SESSION_UNCLAIMED_FILES_KEY].append(new_File.pk)
            else:
                request.session['unclaimed_files'] = [new_File.pk]

        # Asynchronously process document with Google Documents API
        print "upload_complete, firing task"
        tasks.process_document.delay(new_File)

        return {"path": path, "file_pk": new_File.pk, "file_url": new_File.get_absolute_url()}
Пример #3
0
 def test_file_vote(self):
     file = File(title=u"A File", description=u"desc", type='N')
     file.save()
     any_user = User.objects.all()[0]
     file.Vote(any_user, vote_value=1) # This should add one Vote record to the many to many fkey
     self.assertEqual(file.votes.count(), 1)
Пример #4
0
 def test_file(self):
     # FIXME: warning on datetime.datetime.now() with local timezone?
     file = File(title=u"A File", description=u"desc", type='N')
     file.save()
     self.assertEqual(file.__unicode__(), u"A File at None")
     self.assertEqual(file.get_type_display(), u"Note (+5 pts)")