def addThumbnail(self, filecontent=None):
     """ Add a fixed thumbnail
         The thumbnail in the library is big, so this is pretty useless.
     """
     if filecontent is None:
         import thumbnail
         self.thumbnail = thumbnail.thumbnail()
     else:
         self.thumbnail = filecontent
Beispiel #2
0
 def addThumbnail(self, filecontent=None):
     """ Add a fixed thumbnail
         The thumbnail in the library is big, so this is pretty useless.
     """
     if filecontent is None:
         import thumbnail
         self.thumbnail = thumbnail.thumbnail()
     else:
         self.thumbnail = filecontent
Beispiel #3
0
    def addThumbnail(self, filecontent=None):
        """
        Add a fixed thumbnail
        The thumbnail in the library is big, so this is pretty useless.
        @param filecontent bytes: the content of a file; defaults to None
        """
        assert(type(filecontent)==type(b""))

        if filecontent is None:
            import thumbnail
            self.thumbnail = thumbnail.thumbnail()
        else:
            self.thumbnail = filecontent
Beispiel #4
0
    def addThumbnail(self, filecontent=None):
        """
        Add a fixed thumbnail
        The thumbnail in the library is big, so this is pretty useless.
        @param filecontent bytes: the content of a file; defaults to None
        """
        assert (type(filecontent) == type(b""))

        if filecontent is None:
            import thumbnail
            self.thumbnail = thumbnail.thumbnail()
        else:
            self.thumbnail = filecontent
Beispiel #5
0
def index(request):
	latest_files = Item.objects.all()
	
	code = ''
	url = ''
	error = 'Napaka pri nalaganju!'
	
	allowed = ['bmp', 'gif', 'jpg', 'png', 'tiff', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'odt', 'ods', 'odp', 'wmv', 'mp4']
	
	randomString = random_string(100) #random number just for kicks (it should be as random and unique as possible)
	
	if request.method == 'POST':
		try:
			name = request.FILES['file'].name
			ext = name.split('.')[len(name.split('.'))-1].lower()
			
			if ext not in allowed:
				error = 'Ta tip datoteke ni dovoljen!'
				raise CustomException('wrong_type')
			
			url = str_to_url(request.FILES['file'].name)
			i = Item(name = request.FILES['file'].name, type = request.FILES['file'].content_type, url = url, random_string = randomString, description = '')
			
			if request.user.is_authenticated():
				if 'private' in request.POST:
					i.is_private = True
				
				i.user = request.user
			
			i.save() #save it to get id
			
			code = str(i.id) + random_string(6)
			
			i.code = code
			i.save()
			
			handle_uploaded_file(request.FILES['file'], code, url)
			
			i.path = code + '/' + url
			i.save()
			
			#if not logged in, save item id to session
			if not request.user.is_authenticated():
				if not 'uploaded_files' in request.session:
					request.session['uploaded_files'] = []
				
				tmp = request.session['uploaded_files']
				tmp.append(i.id)
				request.session['uploaded_files'] = tmp
				request.session.modified = True
			
			#everything went well, check if we can make a preview of file
			if i.type == 'application/pdf':
				try:
					os.system("convert -colorspace rgb " + FILES_URL + "/" + i.path + " " + FILES_URL + "/" + i.code + "/converted-" + i.code + ".jpg")
					i.converted = True
					
					#create thumbnail
					path = FILES_URL + "/" + i.code + "/converted-" + i.code + "-0.jpg"
					if not os.path.exists(path):
						path = FILES_URL + "/" + i.code + "/converted-" + i.code + ".jpg"
					
					t = thumbnail(path)
					m = thumbnail(path, 200)
					
					if t:
						i.thumbnail = t
					
					if m:
						i.thumbnail_medium = m
					
				except:
					#something went wrong
					i.converted = False
			
			if i.type == 'image/jpg' or i.type == 'image/jpeg' or i.type == 'image/png' or i.type == 'image/gif':
				path = FILES_URL + '/' + i.path
				try:
					t = thumbnail(path)
					m = thumbnail(path, 200)
					
					if t:
						i.thumbnail = t
					
					if m:
						i.thumbnail_medium = m
				except:
					path = ''
			
			i.published = True
			i.save()

			if request.user.is_authenticated():
				request.user.get_profile().add_point()
			
			return HttpResponseRedirect('/datoteka/' + i.path)
		except:
			#revert db/fs - delete created folder/file and remove DB entry
			
			try:
				if len(code) > 0 and len(url) > 0:
					os.remove(FILES_URL + '/' + code + '/' + url)
					os.rmdir(FILES_URL + '/' + code)
			except:
				#there might be a problem with removing folder/file
				None
			
			#try removing entry from DB
			try:
				i = Item.objects.get(random_string=randomString, published=False)
				i.delete()
			except:
				#entry not found, apparently we didn't create one therefore we don't need to remove folder/file
				None
			
			return render_to_response('items/index.html', {'latest_files_list': latest_files, 'error': error},
		context_instance=RequestContext(request))
	
	if 'uploaded_files' in request.session:
		x = request.session['uploaded_files']
	
	return render_to_response('items/index.html', {'latest_files_list': latest_files},
		context_instance=RequestContext(request))
Beispiel #6
0
 def addThumbnail(self):
     """ Add a fixed thumbnail
         The thumbnail in the library is pretty big, so this is pretty useless.
     """
     import thumbnail
     self.thumbnail = thumbnail.thumbnail()
Beispiel #7
0
 def addThumbnail(self):
     """ Add a fixed thumbnail
         The thumbnail in the library is pretty big, so this is pretty useless.
     """
     import thumbnail
     self.thumbnail = thumbnail.thumbnail()