def search(request) -> HttpResponse: """Search for tasks user has permission to see. """ query_string = '' if request.POST: form = SearchForm(request.POST) if form.is_valid(): query_string = form.cleaned_data.get('q', '').strip() else: if "q" in request.GET: query_string = request.GET["q"].strip() initial = {'q': query_string} form = SearchForm(initial=initial) context = {"form": form} if query_string != '': found_tasks = Task.objects.filter(is_active=True).filter( Q(title__icontains=query_string) | Q(note__icontains=query_string)) else: found_tasks = None # Only include tasks that are in groups of which this user is a member: # if not request.user.is_superuser: if found_tasks is not None: if not staff_check(request.user): # pai found_tasks = found_tasks.filter( Q(created_by=request.user) | Q(assigned_to=request.user) | Q(assigned_to__isnull=True, task_list__group__in=get_user_groups(request.user))) # Pagination paginator = Paginator(found_tasks if found_tasks is not None else [], 10) page_number = request.GET.get('page') page_obj = paginator.get_page(page_number) context["page_obj"] = page_obj context["query_string"] = query_string context["found_tasks"] = found_tasks return render(request, "todo/search_results.html", context)
def list_lists(request) -> HttpResponse: editor = Editor.objects.filter(user=request.user).first() if editor: if not editor.chief: raise PermissionDenied else: lists = Book.objects.filter(editor=None, rejected=False, completed=False).order_by("name") list_count = lists.count() else: author = Writer.objects.filter(user=request.user) if author == None: raise PermissionDenied else: lists = Book.objects.filter(editor=None, rejected=False, author__in=author, completed=False).order_by("name") list_count = lists.count() thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) context = { "lists": lists, "thedate": thedate, "searchform": searchform, "list_count": list_count, } return render(request, "todo/list_lists.html", context)
def list_lists(request): """ Homepage view - list of lists a user can view, and ability to add a list. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. group_count = request.user.groups.all().count() if group_count == 0: messages.error(request, "You do not yet belong to any groups. Ask your administrator to add you to one.") # Only show lists to the user that belong to groups they are members of. # Superusers see all lists if request.user.is_superuser: list_list = List.objects.all().order_by('group', 'name') else: list_list = List.objects.filter(group__in=request.user.groups.all()).order_by('group', 'name') # Count everything list_count = list_list.count() # Note admin users see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: item_count = Item.objects.filter(completed=0).count() else: item_count = Item.objects.filter(completed=0).filter(list__group__in=request.user.groups.all()).count() return render_to_response('todo/list_lists.html', locals(), context_instance=RequestContext(request))
def list_lists(request): """ Homepage view - list of lists a user can view, and ability to add a list. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. if request.user.groups.all().count() == 0: messages.error( request, "You do not yet belong to any groups. Ask your administrator to add you to one." ) # Superusers see all lists if request.user.is_superuser: list_list = List.objects.all().order_by('group', 'name') else: list_list = List.objects.filter( group__in=request.user.groups.all()).order_by('group', 'name') list_count = list_list.count() # superusers see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: item_count = Item.objects.filter(completed=0).count() else: item_count = Item.objects.filter(completed=0).filter( list__group__in=request.user.groups.all()).count() return render(request, 'todo/list_lists.html', locals())
def list_lists(request): """ Homepage view - list of lists a user can view, and ability to add a list. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. if request.user.groups.all().count() == 0: messages.error( request, "Ваш обліковий запит не додано до жодної групи. Попросіть адміністрацію аби додали вас до групи" ) # Superusers see all lists if request.user.is_superuser: list_list = List.objects.all().order_by('group', 'name') else: list_list = List.objects.filter( group__in=request.user.groups.all()).order_by('group', 'name') list_count = list_list.count() # superusers see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: item_count = Item.objects.filter(completed=0).count() else: item_count = Item.objects.filter(completed=0).filter( list__group__in=request.user.groups.all()).count() return render(request, 'todo/list_lists.html', locals())
def search(request): response_data = {} if request.method == "POST": if request.user.is_authenticated: form = SearchForm(request.POST) if form.is_valid(): string = form.data['result'] response_data = { 'todo_list': Todos.search_todos(string, request.user) } result = 'Success' else: result = 'Form is not valid' else: result = 'user is not authenticated' response_data['result'] = result return HttpResponse(json.dumps(response_data), content_type="application/json") else: return HttpResponseRedirect('/')
def list_lists(request) -> HttpResponse: """Homepage view - list of lists a user can view, and ability to add a list. """ thedate = timezone.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. if not request.user.is_superuser: # pai if not get_user_groups(request.user).exists(): messages.warning( request, "You do not yet belong to any groups. Ask your administrator to add you to one.", ) lists = TaskList.objects.filter(is_active=True).order_by( "group__name", "name") # superusers see all lists, so count shouldn't filter by just lists the admin belongs to # pai disabled if not staff_check(request.user): task_count = ( Task.objects.filter(is_active=True).filter(completed=False).filter( task_list__group__in=get_user_groups(request.user)).filter( Q(created_by=request.user) | Q(assigned_to=request.user)) # pai .count()) lists = lists.filter(group__in=get_user_groups(request.user)) else: task_count = (Task.objects.filter(is_active=True).filter( completed=False).count()) list_count = lists.count() # Pagination paginator = Paginator(lists, 20) page_number = request.GET.get('page') page_obj = paginator.get_page(page_number) context = { "lists": lists, "thedate": thedate, "searchform": searchform, "list_count": list_count, "task_count": task_count, 'page_obj': page_obj } return render(request, "todo/list_lists.html", context)
def list(catname, sort, name): if name == '0': if sort == 'priority': data1 = Task.query.filter_by(category = catname, status = 1).order_by(Task.priority.desc()).all() elif sort == 'adding order' : data1 = Task.query.filter_by(category = catname, status = 1).order_by(Task.id.desc()).all() elif sort == 'none' : data1 = Task.query.filter_by(category = catname, status = 1) else : if sort == 'priority': data1 = Task.query.filter_by(name = name, category = catname, status = 1).order_by(Task.priority.desc()).all() elif sort == 'adding order': data1 = Task.query.filter_by(name = name, category = catname, status = 1).order_by(Task.id.desc()).all() elif sort == 'none' : data1 = Task.query.filter_by(name = name, category = catname, status = 1).all() form = SearchForm() num = catname if form.validate_on_submit(): newname = form.name.data newnum = dict(choices2).get(form.sort.data) return redirect(url_for('list', catname = num, sort = newnum, name = newname)) return render_template('full_list.html', title = 'full-list', data1 = data1, form = form)
def index(request): sort_type = request.GET.get("sort_type", "new") todo = Todos.get_todos(sort_type, request.POST.get('status'), user=request.user) page = request.GET.get("page") try: page = int(page) except Exception as ex: page = 1 print(ex) if request.method == "GET": context = { 'title': "Todos index page", 'header': "Todos index page header", } user_lang = Language.objects.filter(user=request.user).first().lang if user_lang == "ru": lang = rus elif user_lang == "en": lang = eng else: lang = eng context['language'] = user_lang context['lang'] = lang user = request.user pages = Paginator(todo, 20) if (page < 1) or (page > len(pages.page_range)): page = 1 context['page'] = page context['todo_data'] = pages.page(page) context['back_paginate_btn'] = pages.page(page).has_previous() context['next_paginate_btn'] = pages.page(page).has_next() context['todo_pages'] = pages.page_range done_todos = Paginator(Todos.get_todos('AtoZ', 'done', user), 20) context['done_todos'] = done_todos.page(1).object_list context['done_pages'] = done_todos.page_range context['amount_of_todos'] = Todos.get_amounts(user) context['search_todo_form'] = SearchForm() context['add_todo_form'] = AddTodoForm() context['edit_todo_form'] = EditTodoForm() return render(request, "todo/index.html", context) else: response = paginate(todo, page) return response
def recm_skill(): form = SearchForm() key_word = "" val = request.form.get("val") if request.method == "POST" and val == "val1": key_word = request.form.get("key_word") data = pyytdata.PyYtData(key_word,10) # list to contain info of the video items = [] titles = data.get_titles() descriptions = data.get_descriptions() get_urls = data.get_image_urls() get_links = data.get_links() data1 = zip(titles,descriptions,get_urls,get_links) for i in data1: var = dict() var["title"] = i[0] var["description"] = i[1] var["image"] = i[2] var["link"] = i[3] items.append(var) # for j in items: # print(j) return render_template("recm_skill.html", val=val, items=items, form=form) if request.method == "POST" and val == "val2": key_word = request.form.get("key_word") result = scrape_google(key_word, 10, "en") items = [] for i in result: var = dict() link = i["link"] var["title"] = i["title"] var["description"] = i["description"] var["image"] = None items.append(var) return render_template("recm_skill.html", items=items, val=val, form=form) if request.method == "GET": return render_template("recm_skill.html", form=form) return render_template("recm_skill.html", form=form)
def list_lists(request) -> HttpResponse: """Homepage view - list of lists a user can view, and ability to add a list. Просмотр домашней страницы - список списков, которые пользователь может просматривать, и возможность добавления списка. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. # Убедитесь, что пользователь принадлежит хотя бы к одной группе. if not request.user.groups.all().exists(): messages.warning( request, "You do not yet belong to any groups. Ask your administrator to add you to one.", ) # Superusers see all lists # Суперпользователь видит все списки lists = TaskList.objects.all().order_by("group__name", "name") if not request.user.is_superuser: lists = lists.filter(group__in=request.user.groups.all()) list_count = lists.count() # superusers see all lists, so count shouldn't filter by just lists the admin belongs to # суперпользователи видят все списки, поэтому счетчик не должен фильтроваться только по спискам, # к которые принадлежат администратору if request.user.is_superuser: task_count = Task.objects.filter(completed=0).count() else: task_count = (Task.objects.filter(completed=0).filter( task_list__group__in=request.user.groups.all()).count()) context = { "lists": lists, "thedate": thedate, "searchform": searchform, "list_count": list_count, "task_count": task_count, } return render(request, "todo/list_lists.html", context)
def list_lists(request) -> HttpResponse: """Homepage view - list of lists a user can view, and ability to add a list. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) # Make sure user belongs to at least one group. if not request.user.groups.all().exists(): messages.warning( request, "You do not yet belong to any groups. Ask your administrator to add you to one.", ) # Superusers see all lists if request.user.is_superuser: lists = TaskList.objects.filter(archive_project=False).order_by("group", "name") else: lists = TaskList.objects.filter(group__in=request.user.groups.all(),archive_project=False).order_by( "group", "name" ) list_count = lists.count() # superusers see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: task_count = Task.objects.filter(completed=0).count() else: task_count = ( Task.objects.filter() .filter(task_list__group__in=request.user.groups.all()) .count() ) context = { "lists": lists, "thedate": thedate, "searchform": searchform, "list_count": list_count, "task_count": task_count, } return render(request, "todo/list_lists.html", context)
def list_lists(request, group_pk=None): """ Homepage view - list of lists a user can view, and ability to add a list. """ thedate = datetime.datetime.now() searchform = SearchForm(auto_id=False) group = get_object_or_404(models.Group, pk=group_pk) familygroup = get_object_or_404(FamilyGroup, group_id=group_pk) #list = get_object_or_404(List, group_id=group_pk) event = familygroup.event members = models.User.objects.filter(groups=group) user = request.user profile = user.userprofile # Make sure user belongs to at least one group. if request.user.groups.all().count() == 0: messages.error( request, "You do not yet belong to any groups. Ask your administrator to add you to one." ) # Superusers see all lists (TURN THIS BACK ON BEFORE GOING LIVE) #if request.user.is_superuser: # list_list = List.objects.all().order_by('group', 'name') #else: list_list = List.objects.filter( group__in=group_pk ) #request.user.groups.groupall()).order_by('group', 'name') list_count = list_list.count() # superusers see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: item_count = Item.objects.filter(completed=0).count() else: item_count = Item.objects.filter(completed=0).filter( list__group__in=request.user.groups.all()).count() return render(request, 'todo/list_lists.html', locals())