def user_list(request, queryset=None, title=None): if queryset is None: queryset = Person.objects.all() if not common.is_admin(request): queryset = queryset.filter(pk=request.user.pk) queryset = queryset.select_related() q_filter = PersonFilter(request.GET, queryset=queryset) table = PersonTable(q_filter.qs) tables.RequestConfig(request).configure(table) spec = [] for name, value in six.iteritems(q_filter.form.cleaned_data): if value is not None and value != "": name = name.replace('_', ' ').capitalize() spec.append((name, value)) context = { 'table': table, 'filter': q_filter, 'spec': spec, 'title': title or "Person list", } return render(template_name="karaage/people/person_list.html", context=context, request=request)
def admin_index(request): config = tables.RequestConfig(request, paginate={"per_page": 5}) newest_people = Person.objects.order_by('-date_approved', '-id') newest_people = newest_people.filter(date_approved__isnull=False) newest_people = newest_people.select_related() newest_people = PersonTable( newest_people, orderable=False, prefix="people-") config.configure(newest_people) newest_projects = Project.objects.order_by('-date_approved') newest_projects = newest_projects.filter(date_approved__isnull=False) newest_projects = newest_projects.filter(is_active=True) newest_projects = newest_projects.select_related() newest_projects = ProjectTable( newest_projects, orderable=False, prefix="projects-") config.configure(newest_projects) recent_actions = LogEntry.objects.order_by('-action_time', '-id') recent_actions = LogEntryTable( recent_actions, orderable=False, prefix="actions-") config.configure(recent_actions) var = { 'newest_people': newest_people, 'newest_projects': newest_projects, 'recent_actions': recent_actions, } return render( template_name='karaage/common/index.html', context=var, request=request)
def bounced_email(request, username): person = get_object_or_404(Person, username=username) if request.method == 'POST': person.lock() send_bounced_warning(person) messages.success( request, "%s's account has been locked and emails have been sent" % person) common.log.change(person, 'Emails sent to project leaders and account locked') for ua in person.account_set.all(): ua.change_shell(ua.previous_shell) ua.change_shell(settings.BOUNCED_SHELL) return HttpResponseRedirect(person.get_absolute_url()) leader_list = Person.objects \ .filter( groups__members=person, groups__project__is_active=True) \ .filter(is_active=True) leader_list = PersonTable(leader_list, prefix="leader-") return render_to_response('karaage/people/person_bounced_email.html', locals(), context_instance=RequestContext(request))
def get_similar_people_table(context, applicant): queryset = applicant.similar_people() table = PersonTable( queryset, empty_text="(No potential duplicates found, please check manually)") config = tables.RequestConfig(context['request'], paginate={"per_page": 5}) config.configure(table) return table
def search(request): config = tables.RequestConfig(request, paginate={"per_page": 5}) if 'sitesearch' in request.GET and request.GET['sitesearch'].strip() != "": people_list = Person.objects.all() group_list = Group.objects.all() project_list = Project.objects.all() new_data = request.GET.copy() siteterms = new_data['sitesearch'].lower() term_list = siteterms.split(' ') # people query = Q() for term in term_list: q = Q(username__icontains=term) q = q | Q(short_name__icontains=term) q = q | Q(full_name__icontains=term) q = q | Q(email__icontains=term) query = query & q people_list = people_list.filter(query).distinct() people_list = PersonTable(people_list, prefix="people-") config.configure(people_list) # groups query = Q() for term in term_list: q = Q(name__icontains=term) | Q(description__icontains=term) query = query & q group_list = group_list.filter(query) group_list = GroupTable(group_list, prefix="group-") config.configure(group_list) # projects query = Q() for term in term_list: q = Q(pid__icontains=term) q = q | Q(name__icontains=term) q = q | Q(leaders__username__icontains=term) q = q | Q(leaders__short_name__icontains=term) q = q | Q(leaders__full_name__icontains=term) query = query & q project_list = project_list.filter(query).distinct() project_list = ProjectTable(project_list, prefix="project-") config.configure(project_list) return render( template_name='karaage/common/site_search.html', context=locals(), request=request) else: return HttpResponseRedirect(reverse('index'))
def institute_detail(request, institute_id): config = tables.RequestConfig(request, paginate={"per_page": 5}) institute = get_object_or_404(Institute, pk=institute_id) if not institute.can_view(request): return HttpResponseForbidden( '<h1>Access Denied</h1>' '<p>You do not have permission to view details' 'about this institute.</p>') project_list = institute.project_set.select_related() project_list = ProjectTable(project_list, prefix="project-") config.configure(project_list) person_list = Person.objects.filter( Q(institute__pk=institute_id) | Q(groups__institute=institute_id)) person_list = person_list.select_related() person_list = PersonTable(person_list, prefix="person-") config.configure(person_list) return render_to_response('karaage/institutes/institute_detail.html', locals(), context_instance=RequestContext(request))
def get_similar_people_table(context, applicant): queryset = applicant.similar_people() table = PersonTable(queryset) config = tables.RequestConfig(context['request'], paginate={"per_page": 5}) config.configure(table) return table