Beispiel #1
0
def group_perm(request): #'/permission', 'GET'
	url = request.scheme + '://' + request.host + request.path
	print('url->', url)
	if get_const_value(request, 'is_admin') == "false" and not is_admin(request): return web.HTTPFound('/conf')
	if not user_has_permission(request, 'ss:work_rb', 'view'): return 'You have no permission.'#return '{"result": "fail", "error": "%s"}' % cgi.escape(ct("You have no permission."))
	t = ''

	for res in request.db.doc.find({'type':'group'}).sort('_id', 1):
		if t: t += ', '
		t += '"' +res['_id']+ '":{"id":"'+ res['_id'] + '", "title":"' + res['_id'] +'", "type":"checkbox", "is_editable":"true"}'
	t = '{' + t + '}'
	# return templ('libs.perm:permission', request, dict(map_=t.decode('UTF-8'), url = url, proc_id='group_perm'))
	return templ('libs.perm:permission', request, dict(map_=json.loads(t), url = url, proc_id='group_perm'))
Beispiel #2
0
async def users_group(request): #@route('/users', method='GET')
	url = request.scheme + '://' + request.host + request.path
	print('url->', url)

	if get_const_value(request, 'is_admin') == "false" and not is_admin(request): return web.HTTPFound('/conf')
	if not user_has_permission(request, 'ss:work_rb', 'view'): return 'You have no permission.'
	t = ''
	for res in request.db.doc.find({'type':'group'}).sort('_id', 1):
		if t: t += ', '
		t += '"' +res['_id']+ '":{"id":"'+ res['_id'] + '", "title":"' + res['_id'] +'", "type":"checkbox", "is_editable":"true"}'
	t = '{' + t + '}'
	# return templ('libs.perm:permission', request, dict(map_=t.decode('UTF-8'), url = url, proc_id='users_group'))
	return templ('libs.perm:permission', request, dict(map_=t, url = url, proc_id='users_group'))
Beispiel #3
0
async def users_group_post(request):
	""" Отображает список прав ролей для таблицы установки прав"""
	if not user_is_logged_in(request): return {"result": "fail", "error": "The session ended Login", "need_action":"login"}
	data = await request.post()
	filter = json.loads(data['filter'])
	data=[]
	roles = get_perm(request)
	condition = {'doc_type':'des:users'}

	if 'title' in filter['column'] and filter['column']['title']:
		regex = re.compile( str(filter['column']['title']['val']), re.I | re.UNICODE)
		condition['doc.name.'+cur_lang(request)] = regex

#	pages, req = get_pagination2(condition)

	count = 0
	for list_users in request.db.doc.find(condition):
		results = []
		skip = False
		for role in roles:
			val = list_users['_id'] in roles[role]
			if role in filter['column'] and filter['column'][role]:
				if filter['column'][role]['val'] == 't' and not val or filter['column'][role]['val'] == 'f' and val:
					skip = True
					continue
			results.append((role, ins_img(val), val))
		if skip: continue
		count += 1
		user_name = ct(request, list_users['doc']['name']) if 'name' in list_users['doc'] else 'no name'
		data.append( build_row_report_name(title=user_name, results=results, level=0, id=list_users['_id'], parent='_', child=[] ) )

	# cur_page = int(request.GET['page']) if 'page' in request.GET else 1
	cur_page = int(filter['page']['current']) if 'page' in filter else 1
	limit = int(get_const_value(request, 'doc_page_limit'))

	count = int(ceil(count/limit))

	data = data[(cur_page - 1) * limit : cur_page * limit]
	pages = {'count': count, 'current':cur_page, 'next': 0, 'prev':0}
	head = report_cons_head([('title', 'Пользователи')]+[(i, i) for i in roles], 'checkbox', 'true')

	# print( {"result":"ok", "head":head, "data":json.dumps( data ), "pages":json.dumps( pages)} )
	# print('data->', data)
	# return response_json(request, {"result":"ok", "head":head, "data":json.dumps( data ), "pages":json.dumps( pages)})
	print('heqd->', head)
	return response_json(request, {"result":"ok", "head":head, "data":data, "pages":pages })
Beispiel #4
0
async def get_pagination2(request, condition, collection='doc'):
	data = await request.post()
	filtered = json.loads(data.get('filter', '{}'))
	cur_page = int(request.GET['page']) if 'page' in request.GET else 1
	limit = int(get_const_value(request, 'doc_page_limit'))
	#	limit = 2
	if 'page' in filtered: page = filtered['page']
	else: page = {'current':1}

	skip = (page['current']-1)*limit
	count = float(request.db[collection].find(condition).count())
	count = int(ceil(count/limit))
	req = request.db[collection].find(condition).skip(skip).limit(limit)
	start_page = cur_page - 3
	if start_page<1: start_page = 1
	end_page = start_page + 7
	if end_page > count + 1: end_page = count + 1
	pages = {'count': count, 'current':page['current'], 'next': start_page, 'prev':end_page}
	return pages, req
Beispiel #5
0
def add_file_raw(request, proc_id, doc_id, raw, mime, file_name, water_mark = None, only_small=False, pref = 'def' ):
	""" save the file in a database from variable (raw file) """
	from core.core import get_const_value
	# img = Image.open( io.BytesIO(raw) )
	img = Image.open( raw )
	# img = raw
	# img = Image.open( io.StringIO(raw) )

	if pref == 'def':
		mid_size = 500
		sml_size = 250
	else:
		fl = get_settings('files')
		sml_size, mid_size = fl[pref]

	ttext = get_const_value(request, 'img_sign')
	if ttext and water_mark:
		watermark = Image.new("RGBA", img.size)
		waterdraw = ImageDraw.ImageDraw(watermark, "RGBA")
		waterdraw.text((10, img.size[1]-20), get_const_value('img_sign') )
		watermask = watermark.convert("L").point(lambda x: min(x, 200))
		watermark.putalpha(watermask)
		img.paste(watermark, None, watermark)

	# original image
	s = io.BytesIO()
	if mime == 'image/jpeg':
		img.save(s, 'JPEG', quality=90)
	elif mime == 'image/png':
		img.save(s, 'PNG', quality=90)
	elif mime == 'image/gif':
		img.save(s, 'GIF', quality=90)

	big_raw = s.getvalue()
	s.close()

	# reduced copy
	wpercent = (sml_size/float(img.size[0]))
	hsize = int((float(img.size[1])*float(wpercent)))
	size = (sml_size, hsize)

	small_img = img.resize(size, Image.ANTIALIAS)
	s = io.BytesIO()
	# small_img.convert('RGB')
	if mime == 'image/jpeg':
		small_img.save(s, 'JPEG', quality=65)
	elif mime == 'image/png':
		small_img.save(s, 'PNG', quality=65)
	elif mime == 'image/gif':
		small_img.save(s, 'GIF', quality=65)

	small_raw = s.getvalue()
	s.close()

	# 	middle copy, if provided
	if mid_size:
		wpercent = (mid_size/float(img.size[0]))
		hsize = int((float(img.size[1])*float(wpercent)))
		size = (mid_size, hsize)
		mid_img = img.resize(size, Image.ANTIALIAS)
		s = io.BytesIO()
		if mime == 'image/jpeg':
			mid_img.save(s, 'JPEG', quality=65)
		elif mime == 'image/png':
			mid_img.save(s, 'PNG', quality=65)
		elif mime == 'image/gif':
			mid_img.save(s, 'GIF', quality=65)
		mid_raw = s.getvalue()
		s.close()

	db = request.db
	fs = GridFS(db)

	fs.put(big_raw, file_name ='orig_'+file_name, doc_id = doc_id, proc_id=proc_id,  mime = mime)
	if mid_size:
		fs.put(mid_raw, file_name ='middle_'+file_name, doc_id = doc_id, proc_id=proc_id,  mime = mime)

	fs.put(small_raw, file_name ='thumb_'+file_name, doc_id = doc_id, proc_id=proc_id, mime = mime)
	return True