def get(self, request, id): context = context_processors.base_variables_all(request) user = User.objects.filter(id=id) groups = Role.objects.all() page = request.GET.get('page', 1) paginator = Paginator(groups, 1) try: groups = paginator.page(page) except PageNotAnInteger: groups = paginator.page(1) except EmptyPage: groups = paginator.page(paginator.num_pages) if user: context["user_data"] = user.values()[0] # context["user_id"] = int(id) # print(context["user_data"]["id"], context["user_id"]) context["groups"] = groups user_groups = User_role.objects.filter(user_id=id) if user_groups: context["user_groups"] = list( user_groups.values_list("role_id", flat=True)) else: messages.error(request, "user doesnot exist") return render(request, 'account/users.html', context) return render(request, 'account/change_user.html', context)
def post(self, request): context = context_processors.base_variables_all(request) group_name = request.POST["groupname"] if self.validate_group_name_character(group_name): if self.validate_group_name_length(group_name): if self.validate_group_name_exists(group_name): try: Role.objects.create(name=group_name) group_id = Role.objects.get(name=group_name).id messages.success( request, "%s successfully added to the group" % group_name) if "addanother" in request.POST: return redirect('add_group') elif "continue" in request.POST: return redirect('change_group', id=group_id) except Exception: messages.error( request, "%s adding to group failed" % group_name) return redirect('add_group') else: context[ "error_msg"] = " %s group name already exists" % group_name else: context["error_msg"] = " %s group name is < 5" % group_name else: context["error_msg"] = "group name must be all alphabet character" context["group_name"] = group_name return render(request, 'account/add_group.html', context)
def get(self, request): if 'user' not in request.session: return redirect('login') context = base_variables_all(request) keys = self.get_api_key() if keys: context["keys"] = keys[0] return render(request, 'security/api_key.html', context)
def get(self, request, user_id): img_path = '/home/nishchit/data/images/predictions/' + filename[int( user_id)] files = os.listdir(img_path) filelist = [] for file in files: filelist.append([file, filename[int(user_id)]]) context = context_processors.base_variables_all(request) context['image'] = img[int(user_id)] context['filelist'] = filelist context['id'] = user_id # i = user_id # print(img[i]) return render(request, 'selected_image.html', context)
def get(self, request, id): context = context_processors.base_variables_all(request) permissions = Permission.objects.all() try: context["group"] = Role.objects.get(id=id) except Exception as e: print(e) context["permissions"] = permissions group_permission = Role_permission.objects.filter(role_id=id) if group_permission: context["group_permissions"] = list( group_permission.values_list("permission_id", flat=True)) return render(request, 'account/change_group.html', context)
def get(self, request): context = context_processors.base_variables_all(request) user_list = User.objects.all() page = request.GET.get('page', 1) paginator = Paginator(user_list, 2) try: users = paginator.page(page) except PageNotAnInteger: users = paginator.page(1) except EmptyPage: users = paginator.page(paginator.num_pages) context["users_data"] = users context["users_list"] = user_list return render(request, 'account/users.html', context)
def post(self, request): context = context_processors.base_variables_all(request) username = request.POST["username"] password1 = request.POST["password1"] password2 = request.POST["password2"] if self.username_exists(username): if self.username_validate_pattern(username): if self.password_validate_length(password1): if self.password_validate_numeric(password1): if self.confirm_password(password1, password2): salt = get_salt() hashed_password = hash_string(salt, password1) User.objects.create( user_name=username, salt=salt, hashed_password=hashed_password) user_id = User.objects.get(user_name=username).id context["success_msg"] = "successfully added user" messages.success( request, '%s successfully added' % username) if "addanother" in request.POST: return redirect('add_user') elif "continue" in request.POST: return redirect('change_user', id=user_id) else: context["error_msg"] = "password mismatched" else: context["error_msg"] = "password is all numeric" else: context["error_msg"] = "password length is less than 8" else: context["error_msg"] = "username pattern is invalid" else: context["error_msg"] = "username already exists" context["username"] = username context["password1"] = password1 context["password2"] = password2 return render(request, 'account/add_user.html', context)
def get(self, request): context = context_processors.base_variables_all(request) return render(request, 'account/add_group.html', context)
def get(self, request): context = context_processors.base_variables_all(request) groups = Role.objects.all() context["groups_data"] = groups return render(request, 'account/groups.html', context)
def get(self, request): # if 'user' not in request.session: # return redirect('login') context = context_processors.base_variables_all(request) return render(request, "settings/setting.html", context)
def get(self, request, id): user_data = User.objects.get(id=id) context = context_processors.base_variables_all(request) context['user_data'] = user_data # print(context['user_data'].user_name) return render(request, 'account/change_password.html', context)
def get(self, request): # if 'user' in request.session: img_path = '/home/nishchit/data/images/predictions/' files = os.listdir(img_path) img = [] all_images = [] all_name = [] # mos =[] data = {} filename = [] for file in files: img_r = [] img_b = [] img_g = [] date = '2019-05-20' path = img_path + file + '/' + date + '/' if os.path.exists(path): listfile = listdir(path) smallest = nsmallest(9, listfile) # print(smallest) if smallest != []: for image in smallest: abs_path = path + image img_r.append(cv2.imread(abs_path)[:, :, 0]) img_b.append(cv2.imread(abs_path)[:, :, 1]) img_g.append(cv2.imread(abs_path)[:, :, 2]) # print(img_b) mos_r = montage(np.asarray(img_r)) mos_b = montage(np.asarray(img_b)) mos_g = montage(np.asarray(img_g)) mos = [] mos.append(mos_r) mos.append(mos_b) mos.append(mos_g) cv2.imwrite("/home/data/r4.jpg", mos_r) cv2.imwrite("/home/data/b4.jpg", mos_b) cv2.imwrite("/home/data/g4.jpg", mos_g) mos = np.stack(np.asarray(mos), -1) # print(mos.shape) mon = ('/home/nishchit/data/images/' + '%s.jpg') % file cv2.imwrite(mon, mos) all_images.append(mon) # print(all_images) # for image in all_images: # name = (image[-7:-4]) with open(mon, "rb") as image_file: # print(image_file) fs.put(image_file, content_type="image/jpeg", filename=file) f_id = db.fs.files.find_one({'filename': file}) image = (b64encode( (fs.get(f_id['_id']).read())).decode('utf8')) img.append(image) filename.append(file) global img, filename context = context_processors.base_variables_all(request) context['img'] = img return render(request, 'images.html', context)
def get(self, request, user_date): print(user_date) context = context_processors.base_variables_all(request) return render(request, 'dashboard.html', context)