Exemplo n.º 1
0
 def save_header_image(self, request, job):
     if self.is_valid():
         f = self.cleaned_data['header_image']
         if f:
             header_image = File()
             header_image.content_type = ContentType.objects.get_for_model(Job)
             header_image.object_id = job.id
             header_image.creator = request.user
             header_image.creator_username = request.user.username
             header_image.owner = request.user
             header_image.owner_username = request.user.username
             filename = "%s-%s" % (job.slug, f.name)
             f.file.seek(0)
             header_image.file.save(filename, f)
             job.header_image = header_image
             job.save()
             assign_files_perms(job, files=[job.header_image])
Exemplo n.º 2
0
    def save_file_from_url(self, url, instance):
        file_name = os.path.basename(urllib.unquote(url).replace(' ', '_'))
        tfile = TFile()
        tfile.name = file_name
        tfile.content_type = ContentType.objects.get_for_model(instance)
        tfile.object_id = instance.id
        if hasattr(instance, 'creator'):
            tfile.creator = instance.creator
        if hasattr(instance, 'creator_username'):
            tfile.creator_username = instance.creator_username
        if hasattr(instance, 'owner'):
            tfile.owner = instance.owner
        if hasattr(instance, 'owner_username'):
            tfile.owner_username = instance.owner_username

        #file_path = file_directory(tfile, tfile.name)
        tfile.file.save(file_name, ContentFile(urllib2.urlopen(url).read()))
        tfile.save()
        return tfile
Exemplo n.º 3
0
    def save_file_from_url(self, url, instance):
        file_name = os.path.basename(urllib.unquote(url).replace(' ', '_'))
        tfile = TFile()
        tfile.name = file_name
        tfile.content_type = ContentType.objects.get_for_model(instance)
        tfile.object_id = instance.id
        if hasattr(instance, 'creator'):
            tfile.creator = instance.creator
        if hasattr(instance, 'creator_username'):
            tfile.creator_username = instance.creator_username
        if hasattr(instance, 'owner'):
            tfile.owner = instance.owner
        if hasattr(instance, 'owner_username'):
            tfile.owner_username = instance.owner_username

        #file_path = file_directory(tfile, tfile.name)
        tfile.file.save(file_name, ContentFile(urllib2.urlopen(url).read()))
        tfile.save()
        return tfile