示例#1
0
def upload_file(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        ###
        if form.is_valid():
            user = request.user
            auth = (user.is_authenticated()
                    and user.is_active) and True or False
            ###
            img = CropImg(request.FILES, 'file', MIN_W, MIN_H, MIN_DPI)
            ###
            if img.is_valid():
                di = DataImg()
                ###
                char_id = md5(''.join(
                    [SECRET_KEY[8],
                     str(datetime.datetime.now())])).hexdigest()
                ###
                di.save(obj=img, img=char_id)
                ###
                p = Crop.objects.create(img=char_id,
                                        img_stretch=STRETCH_INIT,
                                        img_type=1,
                                        img_size=SIZE_INIT,
                                        img_effect=1,
                                        qty=1,
                                        x1=0,
                                        y1=0,
                                        x2=0,
                                        y2=0,
                                        status=False)
                ###
                if auth:
                    p.user = user
                else:
                    p.nouser = request.NOUSER.get()
                ###
                p.save()
                ###
                json = {
                    'error': 0,
                    'message': u'Изображение обработано',
                    'id': p.id,
                }
            else:
                json = {
                    'error': 1,
                    'message': u"Ошибка: %s" % img.error,
                    'id': '',
                }
        else:
            json = {
                'error': 1,
                'message': u"Ошибка: Загрузите правильное изображение",
                'id': '',
            }
    ###
    return HttpResponse(simplejson.dumps(json))
示例#2
0
def upload_file(request):
	json = {'error':1, 'message':u"Ошибка: Не найдена опция", 'url':'',}
	###
	try:
		opt_id = int(request.GET.get('id', 0))
	except:
		return HttpResponseRedirect(reverse(REDIRECT))
	###
	if opt_id > 0 and request.method == 'POST':
		user = request.user
		auth = (user.is_authenticated() and user.is_active) and True or False
		###
		q = auth and Q(user=user.id, pk=opt_id) or Q(nouser=request.NOUSER.get(), pk=opt_id)
		###
		p = Mosaic.objects.filter(q)
		###
		if p.exists():
			p = Mosaic.objects.get(q)
			form = UploadForm(request.POST, request.FILES)
			###
			if form.is_valid():
				send_data = form.cleaned_data
				###
				img = CropImg(request.FILES, 'file', MIN_W, MIN_H, MIN_DPI)
				###
				if img.is_valid():
					di = DataImg()
					###
					char_id = md5(''.join([SECRET_KEY[8], str(datetime.datetime.now())])).hexdigest()
					###
					if p.table_type == 1:	size = TYPE_SIZE_1
					if p.table_type == 2:	size = TYPE_SIZE_2
					if p.table_type == 3:	size = TYPE_SIZE_3
					###
					send_data['div_id'] = int(send_data['div_id'])
					###
					di.save(obj=img, img=char_id, w=size[send_data['div_id']][0], h=size[send_data['div_id']][1])
					###
					send_data['effect'] = int(send_data['effect'])
					###
					if send_data['effect'] == 2 or send_data['effect'] == 3:
						di.effect(char_id, send_data['effect'], size[send_data['div_id']][0], size[send_data['div_id']][1])
					###
					setattr(p, 'f_%s' % send_data['div_id'], char_id)
					###
					p.save()
					###
					url = ''.join([MEDIA_URL, MEDIA_URL_FILES, DIR_THUMBS, char_id, '.', IMG_EXT])
					###
					json = {'error':0, 'message':u'Файл успешно загружен', 'url':url,}
				else:
					json = {'error':1, 'message':u"Ошибка: %s" % img.error, 'url':'',}
			else:
				json = {'error':1, 'message':u"Ошибка: Ошибка отправки исходных данных", 'url':'',}
		else:
			json = {'error':1, 'message':u"Ошибка: Загрузите правильное изображение", 'url':'',}
	###
	return HttpResponse(simplejson.dumps(json))
示例#3
0
 def effect(self, img='', eff=1):
     ret = False
     ###
     f = self.f % img
     t = self.t % img
     ###
     self.url = ''.join([
         MEDIA_URL, MEDIA_URL_FILES, DIR_THUMBS, img, '.', IMG_EXT, '?r=',
         str(random.random())
     ])
     ###
     if os.path.isfile(t):
         obj = CropImg(f, None, MIN_W, MIN_H, MIN_DPI)
         ###
         if eff == 3:
             obj.sepia()
         ###
         if eff == 2:
             obj.BlackWhite()
         ###
         obj.resize(THUMB_W, THUMB_X)
         obj.save(t)
         ###
         ret = True
     ###
     return ret
示例#4
0
 def size(self, img=''):
     f = self.f % img
     t = self.t % img
     ###
     sf = CropImg(f, None, MIN_W, MIN_H, MIN_DPI).getOriginSize()
     st = CropImg(t, None, MIN_W, MIN_H, MIN_DPI).getOriginSize()
     ###
     return {
         'fw': sf[0],
         'fh': sf[1],
         'tw': st[0],
         'th': st[1],
     }
示例#5
0
def upload_file(request):
	if request.method == 'POST':
		form = UploadForm(request.POST, request.FILES)
		###
		if form.is_valid():
			user = request.user
			auth = (user.is_authenticated() and user.is_active) and True or False
			###
			img = CropImg(request.FILES, 'file', MIN_W, MIN_H, MIN_DPI)
			###
			if img.is_valid():
				di = DataImg()
				###
				char_id = md5(''.join([SECRET_KEY[8], str(datetime.datetime.now())])).hexdigest()
				###
				di.save(obj=img, img=char_id)
				###
				p = Crop.objects.create(
					img = char_id,
					img_stretch = STRETCH_INIT,
					img_type = 1,
					img_size = SIZE_INIT,
					img_effect = 1,
					qty = 1,
					x1 = 0,
					y1 = 0,
					x2 = 0,
					y2 = 0,
					status = False
				)
				###
				if auth:
					p.user = user
				else:
					p.nouser = request.NOUSER.get()
				###
				p.save()
				###
				json = {'error':0, 'message':u'Изображение обработано', 'id':p.id,}
			else:
				json = {'error':1, 'message':u"Ошибка: %s" % img.error, 'id':'',}
		else:
			json = {'error':1, 'message':u"Ошибка: Загрузите правильное изображение", 'id':'',}
	###
	return HttpResponse(simplejson.dumps(json))
示例#6
0
def to_crop(request):
    user = request.user
    auth = (user.is_authenticated() and user.is_active) and True or False
    ###
    img = CropImg(''.join([MEDIA_ROOT, request.GET.get('img', 0)]), None,
                  MIN_W, MIN_H, MIN_DPI)
    #img = Image.open(''.join([MEDIA_ROOT, request.GET.get('img', 0)]))
    ###
    di = DataImg()
    ###
    char_id = md5(''.join([SECRET_KEY[8],
                           str(datetime.datetime.now())])).hexdigest()
    ###
    di.save(obj=img, img=char_id)
    ###
    p = Crop.objects.create(img=char_id,
                            img_stretch=STRETCH_INIT,
                            img_type=1,
                            img_size=SIZE_INIT,
                            img_effect=1,
                            qty=1,
                            x1=0,
                            y1=0,
                            x2=0,
                            y2=0)
    ###
    if auth:
        p.user = user
    else:
        p.nouser = request.NOUSER.get()
    ###
    p.save()
    ###
    json = {
        'error': 0,
        'message': 'Файл успешно загружен',
        'id': p.id,
    }
    ###
    return HttpResponseRedirect(''.join(['/crop/option/?id=', str(p.id)]))
示例#7
0
	def effect(self, img='', eff=1):
		ret = False
		###
		f = self.f % img
		t = self.t % img
		###
		self.url = ''.join([MEDIA_URL, MEDIA_URL_FILES, DIR_THUMBS, img, '.', IMG_EXT, '?r=', str(random.random())])
		###
		if os.path.isfile(t):
			obj = CropImg(f, None, MIN_W, MIN_H, MIN_DPI)
			###
			if eff == 3:
				obj.sepia()
			###
			if eff == 2:
				obj.BlackWhite()
			###
			obj.resize(THUMB_W, THUMB_X)
			obj.save(t)
			###
			ret = True
		###
		return ret