Exemplo n.º 1
0
def upload_file(request):
    if request.method == 'POST':
        try:
            filename = request.FILES.keys()[0]
            file = File(request.FILES[filename])
            picture = Picture(slug=request.GET.get('slug'), )
            picture.file.save(file.name, file)
            picture.save()
            print picture.modified
            print picture.slug
            print picture.file.name
            data = {"success": True}
        except:
            data = {
                'error': 'invalid image data',
                'errors': 'something went wrong',
            }
        return HttpResponse(json.dumps(data), mimetype="application/json")
    return HttpResponseNotAllowed([
        'POST',
    ])
Exemplo n.º 2
0
def upload_file(request):
    if request.method == 'POST':
        try:
            filename = request.FILES.keys()[0]
            file = File(request.FILES[filename])
            picture = Picture(
                slug=request.GET.get('slug'),
            )
            picture.file.save(file.name, file)
            picture.save()
            print picture.modified
            print picture.slug
            print picture.file.name
            data = {"success": True}
        except:
            data = {
                'error': 'invalid image data',
                'errors': 'something went wrong',
            }
        return HttpResponse(json.dumps(data), mimetype="application/json")
    return HttpResponseNotAllowed(['POST', ])
Exemplo n.º 3
0
def PictureCreateView(request):
    if request.POST:
        try:
            f = request.FILES.get('file')
            name = f.name.split('.')
            f.name = "%s.%s" % (random_string(32), name[len(name)-1])
            name = f.name
            p = Picture(user=request.user, file=f)
            p.save()

            image = "%s/%s" % (settings.MEDIA_ROOT, upload_to(p, name))
            thumb = pil.create_thumb(image)
            thumb_address = "%s/%s" % (settings.MEDIA_ROOT, thumb_upload_to(p, name))
            thumb.save(thumb_address)
            thumb_address = "%s%s/%s" % (settings.MEDIA_URL, thumb_upload_url(p.user.patient), name)
            p.thumb = thumb_address
            p.save()
            
            data = [{'id': p.id, 'name': f.name, 'url': settings.MEDIA_URL + upload_url(p.user.patient) + "/" + f.name.replace(" ", "_"), 'thumbnail_url': settings.MEDIA_URL + thumb_upload_url(p.user.patient) + "/" + f.name.replace(" ", "_"), 'delete_url': reverse('upload-delete', args=[p.id]), 'delete_type': "DELETE"}]
        except:
            raise
            data = [{'status': 'Error', 'error': 'Error', 'message': 'Failed to submit files'}]
    else:
        data = []
        response = JSONResponse(data, {}, "text/plain")
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
    response = JSONResponse(data, {}, "application/json")
    response['Content-Disposition'] = 'inline; filename=files.json'
    return response
def multiple_uploader(request):
    if request.POST:
        if request.FILES == None:
            raise Http404("No objects uploaded")
        f = request.FILES['file']

        a = Picture()
        a.creator = request.user
        a.file.save(f.name, f)
        a.save()

        result = [{'name': f.name,
                   'size': f.size,
                   'url': a.file.url,
                 },]

        response_data = simplejson.dumps(result)
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else:
        return HttpResponse('Only POST accepted')
Exemplo n.º 5
0
def saveInPictureDatabase(file):
    try:
        pic = Picture()
        tick = time.time()

        strtick = str(tick).replace('.', '_')

        logger.write('S', str(file.name))

        format = file.name[-4:]
        name = file.name[:-4]
        new_name = name + strtick + format

        pic.file.save(new_name, file)

        return new_name

    except Exception as e:
        logger.write('E', str('Error while saving to Picture Database'))
        raise e
Exemplo n.º 6
0
def desk2(request):
	if request.method == 'POST':
		pyJSON=defaultdict(dict)
		user=[]
		fi = open('/home/wall/log.txt','r')
		data = fi.read()
		fi.close()
		fo = open('/home/wall/log.txt','w')
		fo.write(data.replace('\x00', ''))
		fo.close()
		f=open('/home/wall/log.txt','r')



		for line in f:
			line=line[:-1]
			tmp = re.search(r'(.*).unison.tmp', line, re.M)
			if tmp:
				continue
		#	for item in [' CREATE ',' ATTRIB ',' CREATE,ISDIR ',' MOVED_TO,ISDIR ',' MOVED_FROM,ISDIR ',' MOVED_FROM ',' MOVED_TO ',' MOVE_SELF ',' ATTRIB,ISDIR ']:
			a = re.search(r'(.*) CREATE (.*)', line, re.M)
			b = re.search(r'(.*) MOVED_TO (.*)', line, re.M)
			#print line
			userstart = line[42:]
			user = userstart.split('/')[0]
			
			if a:
				line = line.replace(' CREATE ','')
				
				try:
					pyJSON[user]['create'].append(line)
				except:
					pyJSON[user]['create'] = list()
					pyJSON[user]['create'].append(line)
			if b:
				line = line.replace(' MOVED_TO ','')
				try:
					pyJSON[user]['create'].append(line)
				except:
					pyJSON[user]['create'] = list()
					pyJSON[user]['create'].append(line)
			c = re.search(r'(.*) MOVED_FROM (.*)', line, re.M)
			d = re.search(r'(.*) DELETE (.*)', line, re.M)
			if c:
				line = line.replace(' MOVED_FROM ','')
				
				userstart = line[42:]
				user = userstart.split('/')[0]
				try:
					pyJSON[user]['delete'].append(line)
				except:
					pyJSON[user]['delete'] = list()
					pyJSON[user]['delete'].append(line)
			if d:
				line = line.replace(' DELETE ','')
				#if item == ' CREATE ' or item == ' MOVED_TO ':
				userstart = line[42:]
				user = userstart.split('/')[0]
				try:
					pyJSON[user]['delete'].append(line)
				except:
					pyJSON[user]['delete'] = list()
					pyJSON[user]['delete'].append(line)
		f.close()
		print pyJSON
		for item in pyJSON:
			u = User.objects.get(username = item)
			print u
			
			try:
				for a in pyJSON[item]['create']:
					p = Picture()
					p.file.name=a[33:]
					print a[33:]
					po=Picture(user=u, file=p.file)
					po.save()
			except:	
				print "no"
			try:
				for a in pyJSON[item]['delete']:
					p = Picture()
					p.file.name=a[33:]
					print a[33:]
					# po=Picture(user=u, file=p.file)
					b = Picture.objects.get(user=u,file=p.file)
					b.delete()
					print file
					print "isdeleted"
			except:
				print "no"