def es_get_field_stats(request, field, FieldTable, hostname, key='host', count=20, from_date=0 , qfilter = None): data = render_template(TOP_QUERY, {'appliance_hostname': hostname, 'count': count, 'from_date': from_date, 'field': field}, qfilter = qfilter) es_url = get_es_url(from_date) req = urllib2.Request(es_url, data) try: out = urllib2.urlopen(req, timeout=TIMEOUT) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: if settings.ELASTICSEARCH_VERSION >= 2: data = data['aggregations']['table']['buckets'] else: data = data['facets']['table']['terms'] except: objects = FieldTable([]) tables.RequestConfig(request).configure(objects) return objects objects = [] if data != None: for elt in data: if settings.ELASTICSEARCH_VERSION >= 2: fstat = {key: elt['key'], 'count': elt['doc_count'] } else: fstat = {key: elt['term'], 'count': elt['count'] } objects.append(fstat) objects = FieldTable(objects) tables.RequestConfig(request).configure(objects) else: objects = FieldTable([]) tables.RequestConfig(request).configure(objects) return objects
def ruleset(request, ruleset_id, mode = 'struct', error = None): ruleset = get_object_or_404(Ruleset, pk=ruleset_id) if mode == 'struct': categories_list = {} sources = ruleset.sources.all() for sourceatversion in sources: cats = CategoryTable(ruleset.categories.filter(source = sourceatversion.source)) tables.RequestConfig(request, paginate={"per_page": 15}).configure(cats) categories_list[sourceatversion.source.name] = cats rules = RuleTable(ruleset.suppressed_rules.all()) tables.RequestConfig(request).configure(rules) context = {'ruleset': ruleset, 'categories_list': categories_list, 'sources': sources, 'rules': rules, 'mode': mode} if error: context['error'] = error elif mode == 'display': rules = RuleTable(ruleset.generate()) tables.RequestConfig(request).configure(rules) context = {'ruleset': ruleset, 'rules': rules, 'mode': mode} if error: context['error'] = error elif mode == 'export': rules = ruleset.generate() file_content = "# Rules file for " + ruleset.name + " generated by Scirius at " + str(datetime.now()) + "\n" for rule in rules: file_content += rule.content response = HttpResponse(file_content, content_type="text/plain") response['Content-Disposition'] = 'attachment; filename=scirius.rules' return response return scirius_render(request, 'rules/ruleset.html', context)
def edit_ruleset(request, ruleset_id): ruleset = get_object_or_404(Ruleset, pk=ruleset_id) if not request.user.is_staff: return scirius_render(request, 'rules/edit_ruleset.html', {'ruleset': ruleset, 'error': 'Unsufficient permissions'}) if request.method == 'POST': # If the form has been submitted... # check if this is a categories edit # ID is unique so we can just look by indice and add if request.POST.has_key('category'): # clean ruleset ruleset.categories.clear() # add updated entries for cat in request.POST.getlist('category_selection'): category = get_object_or_404(Category, pk=cat) ruleset.categories.add(category) ruleset.save() elif request.POST.has_key('rules'): for rule in request.POST.getlist('rule_selection'): rule_object = get_object_or_404(Rule, pk=rule) ruleset.suppressed_rules.remove(rule_object) ruleset.save() elif request.POST.has_key('sources'): # clean ruleset ruleset.sources.clear() # add updated entries for src in request.POST.getlist('source_selection'): source = get_object_or_404(SourceAtVersion, pk=src) ruleset.sources.add(source) ruleset.save() return redirect(ruleset) else: cats_selection = [] categories_list = {} sources = ruleset.sources.all() ruleset_cats = ruleset.categories.all() for sourceatversion in sources: src_cats = Category.objects.filter(source = sourceatversion.source) for pcats in src_cats: if pcats in ruleset_cats: cats_selection.append(str(pcats.id)) cats = EditCategoryTable(src_cats) tables.RequestConfig(request,paginate = False).configure(cats) categories_list[sourceatversion.source.name] = cats rules = EditRuleTable(ruleset.suppressed_rules.all()) tables.RequestConfig(request, paginate = False).configure(rules) context = {'ruleset': ruleset, 'categories_list': categories_list, 'sources': sources, 'rules': rules, 'cats_selection': ", ".join(cats_selection) } if request.GET.has_key('mode'): context['mode'] = request.GET['mode'] if context['mode'] == 'sources': all_sources = SourceAtVersion.objects.all() sources_selection = [] for source in sources: sources_selection.append(source.pk) sources_list = EditSourceAtVersionTable(all_sources) tables.RequestConfig(request, paginate = False).configure(sources_list) context['sources_list'] = sources_list context['sources_selection'] = sources_selection return scirius_render(request, 'rules/edit_ruleset.html', context)
def category(request, cat_id): cat = get_object_or_404(Category, pk=cat_id) rules = RuleTable(Rule.objects.filter(category=cat, state=True)) tables.RequestConfig(request).configure(rules) commented_rules = RuleTable(Rule.objects.filter(category=cat, state=False)) tables.RequestConfig(request).configure(commented_rules) category_path = [cat.source] # build table of rulesets and display if category is active rulesets = Ruleset.objects.all() rulesets_status = [] for ruleset in rulesets: status = 'Inactive' if cat in ruleset.categories.all(): status = 'Active' rulesets_status.append({ 'name': ruleset.name, 'pk': ruleset.pk, 'status': status }) rulesets_status = StatusRulesetTable(rulesets_status) tables.RequestConfig(request).configure(rulesets_status) context = { 'category': cat, 'rules': rules, 'commented_rules': commented_rules, 'object_path': category_path, 'rulesets': rulesets_status } return scirius_render(request, 'rules/category.html', context)
def get(self, request): """Handles GET requests.""" user_profile = models.UserProfile.objects.get(user=request.user) network = user_profile.network # Find subscribers that, with the current settings, will soon be # deactivated. Also divide that group up into "protected" and # "unprotected" subs. inactive_subs = network.get_outbound_inactive_subscribers( network.sub_vacuum_inactive_days) protected_subs = [] unprotected_subs = [] for sub in inactive_subs: if sub.prevent_automatic_deactivation: protected_subs.append(sub) else: unprotected_subs.append(sub) # Setup tables showing both groups of subs. protected_subs_table = django_tables.MinimalSubscriberTable( protected_subs) unprotected_subs_table = django_tables.MinimalSubscriberTable( unprotected_subs) tables.RequestConfig(request, paginate={ 'per_page': 25 }).configure(protected_subs_table) tables.RequestConfig(request, paginate={ 'per_page': 25 }).configure(unprotected_subs_table) # Set the context with various stats. context = { 'networks': get_objects_for_user(request.user, 'view_network', klass=models.Network), 'user_profile': user_profile, 'network': network, 'sub_vacuum_form': dashboard_forms.SubVacuumForm({ 'sub_vacuum_enabled': network.sub_vacuum_enabled, 'inactive_days': network.sub_vacuum_inactive_days, }), 'protected_subs': protected_subs, 'unprotected_subs': unprotected_subs, 'protected_subs_table': protected_subs_table, 'unprotected_subs_table': unprotected_subs_table, } # Render template. vacuum_template = template.loader.get_template( 'dashboard/network_detail/inactive-subscribers.html') html = vacuum_template.render(context, request) return http.HttpResponse(html)
def es_get_rules_stats(request, hostname, count=20, from_date=0, qfilter=None): templ = Template(TOP_QUERY) context = Context({ 'appliance_hostname': hostname, 'count': count, 'from_date': from_date, 'field': 'alert.signature_id' }) if qfilter != None: query_filter = " AND " + qfilter context['query_filter'] = re.sub('"', '\\"', query_filter) data = templ.render(context) es_url = get_es_url(from_date) req = urllib2.Request(es_url, data) try: out = urllib2.urlopen(req) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: if settings.ELASTICSEARCH_2X: data = data['aggregations']['table']['buckets'] else: data = data['facets']['table']['terms'] except: rules = ExtendedRuleTable([]) tables.RequestConfig(request).configure(rules) return rules rules = [] if data != None: for elt in data: try: if settings.ELASTICSEARCH_2X: sid = elt['key'] else: sid = elt['term'] rule = Rule.objects.get(sid=sid) except: print "Can not find rule with sid " + str(sid) continue if settings.ELASTICSEARCH_2X: rule.hits = elt['doc_count'] else: rule.hits = elt['count'] rules.append(rule) rules = ExtendedRuleTable(rules) tables.RequestConfig(request).configure(rules) else: rules = ExtendedRuleTable([]) tables.RequestConfig(request).configure(rules) return rules
def ruleset(request, ruleset_id, mode='struct', error=None): ruleset = get_object_or_404(Ruleset, pk=ruleset_id) if mode == 'struct': categories_list = {} sources = ruleset.sources.all() for sourceatversion in sources: cats = CategoryTable( ruleset.categories.filter(source=sourceatversion.source)) tables.RequestConfig(request, paginate={ "per_page": 15 }).configure(cats) categories_list[sourceatversion.source.name] = cats context = { 'ruleset': ruleset, 'categories_list': categories_list, 'sources': sources, 'mode': mode } disabled_rules = ruleset.suppressed_rules.all() if disabled_rules: disabled_rules = RuleTable(disabled_rules) tables.RequestConfig(request).configure(disabled_rules) context['disabled_rules'] = disabled_rules thresholds = Threshold.objects.filter(ruleset=ruleset, threshold_type='threshold') if thresholds: thresholds = RulesetThresholdTable(thresholds) tables.RequestConfig(request).configure(thresholds) context['thresholds'] = thresholds suppress = Threshold.objects.filter(ruleset=ruleset, threshold_type='suppress') if suppress: suppress = RulesetSuppressTable(suppress) tables.RequestConfig(request).configure(suppress) context['suppress'] = suppress if error: context['error'] = error elif mode == 'display': rules = RuleTable(ruleset.generate()) tables.RequestConfig(request).configure(rules) context = {'ruleset': ruleset, 'rules': rules, 'mode': mode} if error: context['error'] = error elif mode == 'export': file_content = ruleset.to_buffer() response = HttpResponse(file_content, content_type="text/plain") response['Content-Disposition'] = 'attachment; filename=scirius.rules' return response if hasattr(Probe.common, 'update_ruleset'): context['middleware_has_update'] = True return scirius_render(request, 'rules/ruleset.html', context)
def es_get_field_stats(request, field, FieldTable, hostname, key='host', count=20, from_date=0, qfilter=None): templ = Template(TOP_QUERY) context = Context({ 'appliance_hostname': hostname, 'count': count, 'from_date': from_date, 'field': field }) if qfilter != None: query_filter = " AND " + qfilter context['query_filter'] = re.sub('"', '\\"', query_filter) data = templ.render(context) es_url = get_es_url(from_date) req = urllib2.Request(es_url, data) try: out = urllib2.urlopen(req) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: if settings.ELASTICSEARCH_2X: data = data['aggregations']['table']['buckets'] else: data = data['facets']['table']['terms'] except: objects = FieldTable([]) tables.RequestConfig(request).configure(objects) return objects objects = [] if data != None: for elt in data: if settings.ELASTICSEARCH_2X: fstat = {key: elt['key'], 'count': elt['doc_count']} else: fstat = {key: elt['term'], 'count': elt['count']} objects.append(fstat) objects = FieldTable(objects) tables.RequestConfig(request).configure(objects) else: objects = FieldTable([]) tables.RequestConfig(request).configure(objects) return objects
def get_field_stats_table(self, request, sid, field, count=DEFAULT_COUNT): data = self.get_field_stats_dict(request, sid, field) if data is None: objects = tables.RuleHostTable([]) django_tables2.RequestConfig(request).configure(objects) return objects objects = [] for elt in data: fstat = {'host': elt['key'], 'count': int(elt['doc_count'])} objects.append(fstat) objects = tables.RuleHostTable(objects) django_tables2.RequestConfig(request).configure(objects) return objects
def es_get_rules_stats(request, hostname, count=20, from_date=0, qfilter=None): data = render_template(TOP_QUERY, { 'appliance_hostname': hostname, 'count': count, 'from_date': from_date, 'field': 'alert.signature_id' }, qfilter=qfilter) es_url = get_es_url(from_date) headers = {'content-type': 'application/json'} req = urllib2.Request(es_url, data, headers=headers) try: out = urllib2.urlopen(req, timeout=TIMEOUT) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: if settings.ELASTICSEARCH_VERSION >= 2: data = data['aggregations']['table']['buckets'] else: data = data['facets']['table']['terms'] except: rules = ExtendedRuleTable([]) tables.RequestConfig(request).configure(rules) return rules rules = [] if data != None: for elt in data: try: if settings.ELASTICSEARCH_VERSION >= 2: sid = elt['key'] else: sid = elt['term'] rule = Rule.objects.get(sid=sid) except: print "Can not find rule with sid " + str(sid) continue if settings.ELASTICSEARCH_VERSION >= 2: rule.hits = elt['doc_count'] else: rule.hits = elt['count'] rules.append(rule) rules = ExtendedRuleTable(rules) tables.RequestConfig(request).configure(rules) else: rules = ExtendedRuleTable([]) tables.RequestConfig(request).configure(rules) return rules
def search(request): context = {} length = 0 rules_width = 4 search = None if request.method == 'POST': if request.POST.has_key('search'): search = request.POST['search'] request.GET = request.GET.copy() request.GET.update({'search': search}) elif request.method == 'GET': if request.GET.has_key('search'): search = request.GET['search'] if search: rules = Rule.objects.filter(content__icontains=search) if len(rules) > 0: length += len(rules) rules = RuleTable(rules) tables.RequestConfig(request).configure(rules) else: rules = None categories = Category.objects.filter(name__icontains=search) if len(categories) > 0: length += len(categories) categories = CategoryTable(categories) tables.RequestConfig(request).configure(categories) else: rules_width += 4 categories = None rulesets = Ruleset.objects.filter(name__icontains=search) if len(rulesets) > 0: length += len(rulesets) rulesets = RulesetTable(rulesets) tables.RequestConfig(request).configure(rulesets) else: rules_width += 4 rulesets = None else: rules = None categories = None rulesets = None context = { 'rules': rules, 'rules_width': rules_width, 'categories': categories, 'rulesets': rulesets, 'motif': search, 'length': length } return scirius_render(request, 'rules/search.html', context)
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 bounced_email(request, username): person = get_object_or_404(Person, username=username) leader_list = [] for project in person.projects.filter(is_active=True): for leader in project.leaders.filter(is_active=True, login_enabled=True): leader_list.append({'project': project, 'leader': leader}) if request.method == 'POST': person.lock() send_bounced_warning(person, leader_list) 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') return HttpResponseRedirect(person.get_absolute_url()) leader_list = LeaderTable(leader_list) tables.RequestConfig(request).configure(leader_list) return render(template_name='karaage/people/person_bounced_email.html', context=locals(), request=request)
def es_get_sid_by_hosts(request, sid, count=20, from_date=0): data = render_template(SID_BY_HOST_QUERY, {'rule_sid': sid, 'alerts_number': count, 'from_date': from_date}) es_url = get_es_url(from_date) headers = {'content-type': 'application/json'} req = urllib2.Request(es_url, data, headers = headers) try: out = urllib2.urlopen(req, timeout=TIMEOUT) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: if settings.ELASTICSEARCH_VERSION >= 2: data = data['aggregations']['host']['buckets'] else: data = data['facets']['terms']['terms'] except: return None stats = [] if data != None: for elt in data: if settings.ELASTICSEARCH_VERSION >= 2: hstat = {'host': elt['key'], 'count': elt['doc_count']} else: hstat = {'host': elt['term'], 'count': elt['count']} stats.append(hstat) stats = RuleStatsTable(stats) tables.RequestConfig(request).configure(stats) else: return None return stats
def category(request, cat_id): cat = get_object_or_404(Category, pk=cat_id) rules = RuleTable(Rule.objects.filter(category=cat)) tables.RequestConfig(request).configure(rules) category_path = [cat.source] context = {'category': cat, 'rules': rules, 'object_path': category_path} return scirius_render(request, 'rules/category.html', context)
def project_list(request, queryset=None): if queryset is None: queryset = Project.objects.all() if not util.is_admin(request): queryset = queryset.filter( Q(leaders=request.user, is_active=True) | Q(institute__delegates=request.user, is_active=True) | Q(group__members=request.user, is_active=True)).distinct() queryset = queryset.select_related() q_filter = ProjectFilter(request.GET, queryset=queryset) table = ProjectTable(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)) return render_to_response('karaage/projects/project_list.html', { 'table': table, 'filter': q_filter, 'spec': spec, 'title': "Project list", }, context_instance=RequestContext(request))
def get_context_data(self, **kwargs): # Get a list of users who are active CUED members seeking mentors seekers = get_user_model().objects.\ filter(cued_member__is_active=True, mentorship_preferences__is_seeking_mentor=True).\ select_related('cued_member', 'cued_member__research_group', 'cued_member__research_group__division') # We want to annotate each seeker with the number of active mentee # relationships they are currently a part of seekers = seekers.\ annotate(mentors_count=Coalesce(Sum( Case(When(mentee_relationships__is_active=True, then=Value(1)), When(mentee_relationships__is_active=False, then=Value(0)), output_field=IntegerField()) ), 0)) f = MatchmakeFilter(self.request.GET, queryset=seekers) helper = FormHelper(f.form) helper.html5_required = True helper.error_text_inline = False helper.form_action = "" helper.form_method = "get" helper.add_input(Submit("submit", "Update filter")) f.form.helper = helper table = MatchmakeTable(f.qs, order_by='crsid', empty_text='No people match this filter') tables.RequestConfig(self.request, paginate=False).configure(table) return {'table': table, 'filter': f}
def application_list(request): """ a user wants to see all applications possible. """ if util.is_admin(request): queryset = Application.objects.all() else: queryset = Application.objects.get_for_applicant(request.user) q_filter = ApplicationFilter(request.GET, queryset=queryset) table = ApplicationTable(q_filter.qs.order_by("-expires")) 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)) return render(template_name="kgapplications/application_list.html", context={ 'table': table, 'filter': q_filter, 'spec': spec, 'title': "Application list", }, request=request)
def technical_resources(request): category = request.GET.get("category", "") if category in [ "regional_plans", "municipal_tools", "research_and_reports" ]: technical_resources = TechnicalResource.objects.filter( category=category) else: technical_resources = TechnicalResource.objects.all() if technical_resources: technical_resources = TechnicalResourceTable(technical_resources) # set default sort for the table and configure it so sorting is enabled technical_resources.order_by = "-publication_date" tables.RequestConfig(request, paginate=False).configure(technical_resources) context = { "title": "Technical Resources", "resources": technical_resources, "category": category, } return render(request, "web/resources.html", context)
def job_list(request): if not getattr(settings, 'USAGE_IS_PUBLIC', False): return HttpResponseForbidden('<h1>Access Denied</h1>') queryset = CPUJob.objects.select_related() q_filter = CPUJobFilter(request.GET, queryset=queryset) table = CPUJobTable(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)) return render( template_name='kgusage/job_list.html', context={ 'table': table, 'filter': q_filter, 'spec': spec, 'title': "Job list", }, request=request)
def get_context_data(self, **kwargs): context = super(PersonRankingTableView, self).get_context_data(**kwargs) filter = PersonRankingFilter(self.request.GET, queryset=self.get_queryset(), request=self.request) if not filter.form.is_valid(): filter._qs = filter.queryset.none() table = PersonRankingTable(filter.qs) django_tables2.RequestConfig(self.request, ).configure(table) context['filter'] = filter context['table'] = table context['action'] = _("add") context['object_name_plural'] = "person ranking" context['add_url'] = reverse_lazy('add_person') if 'item_roles' not in self.request.GET: messages.add_message( self.request, messages.WARNING, _("Please select a item role in the filter below.")) return context
def join_project(request, project_id=None): config = tables.RequestConfig(request, paginate={"per_page": 5}) person = request.user project_list = Project.objects.all() project_list = ProjectTable(project_list, prefix="all-") config.configure(project_list) delegate_project_list = Project.objects.filter(institute__delegates=person, is_active=True) delegate_project_list = ProjectTable(delegate_project_list, prefix="delegate-") config.configure(delegate_project_list) leader_project_list = Project.objects.filter(leaders=person, is_active=True) leader_project_list = ProjectTable(leader_project_list, prefix="leader-") config.configure(leader_project_list) return render_to_response('karaage/projects/join_project.html', { 'person': person, 'project_list': project_list, 'delegate_project_list': delegate_project_list, 'leader_project_list': leader_project_list }, context_instance=RequestContext(request))
def switch_rule(request, rule_id, operation = 'suppress'): rule_object = get_object_or_404(Rule, sid=rule_id) if not request.user.is_staff: context = { 'rule': rule_object, 'operation': operation, 'error': 'Unsufficient permissions' } return scirius_render(request, 'rules/suppress_rule.html', context) if request.method == 'POST': # If the form has been submitted... form = RulesetSuppressForm(request.POST) if form.is_valid(): # All validation rules pass ruleset = form.cleaned_data['ruleset'] disable_rules = rule_object.get_flowbits_group() if operation == 'suppress': if disable_rules: ruleset.suppressed_rules.add(*list(disable_rules)) else: ruleset.suppressed_rules.add(rule_object) elif operation == 'enable': if disable_rules: ruleset.suppressed_rules.remove(*list(disable_rules)) else: ruleset.suppressed_rules.remove(rule_object) ruleset.save() return redirect(rule_object) form = RulesetSuppressForm() rules = rule_object.get_flowbits_group() context = { 'rule': rule_object, 'form': form } if len(rules): rules = RuleTable(rules) tables.RequestConfig(request).configure(rules) context['rules'] = rules context['operation'] = operation return scirius_render(request, 'rules/suppress_rule.html', context)
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 build_source_diff(request, diff): for field in ["added", "deleted", "updated"]: if field == "deleted": diff[field] = DeletedRuleTable(diff[field]) else: diff[field] = UpdateRuleTable(diff[field]) tables.RequestConfig(request).configure(diff[field])
def profile_projects(request): config = tables.RequestConfig(request, paginate={"per_page": 5}) person = request.user project_list = person.projects.all() project_list = ProjectTable(project_list, prefix="mine-") config.configure(project_list) delegate_project_list = Project.objects.filter(institute__delegates=person, is_active=True) delegate_project_list = ProjectTable(delegate_project_list, prefix="delegate-") config.configure(delegate_project_list) leader_project_list = Project.objects.filter(leaders=person, is_active=True) leader_project_list = ProjectTable(leader_project_list, prefix="leader-") config.configure(leader_project_list) return render(template_name='karaage/projects/profile_projects.html', context={ 'person': person, 'project_list': project_list, 'delegate_project_list': delegate_project_list, 'leader_project_list': leader_project_list }, request=request)
def institute_list(request): queryset = Institute.objects.all() if not is_admin(request): queryset = institute_list.filter(is_active=True, delegates=request.user) q_filter = InstituteFilter(request.GET, queryset=queryset) table = InstituteTable(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)) return render(template_name='karaage/institutes/institute_list.html', context={ 'table': table, 'filter': q_filter, 'spec': spec, 'title': "Institute list", }, request=request)
def es_get_sid_by_hosts(request, sid, count=20, from_date=0): templ = Template(SID_BY_HOST_QUERY) context = Context({ 'rule_sid': sid, 'alerts_number': count, 'from_date': from_date }) data = templ.render(context) es_url = get_es_url(from_date) req = urllib2.Request(es_url, data) try: out = urllib2.urlopen(req) except: return None data = out.read() # returned data is JSON data = json.loads(data) # total number of results try: data = data['facets']['terms']['terms'] except: return None stats = [] if data != None: for elt in data: hstat = {'host': elt['term'], 'count': elt['count']} stats.append(hstat) stats = RuleStatsTable(stats) tables.RequestConfig(request).configure(stats) else: return None return stats
def scirius_listing(request, objectname, name, template='rules/object_list.html', table=None, adduri=None): # FIXME could be improved by generating function name from accounts.tables import UserTable from rules.tables import CategoryTable assocfn = {'Categories': CategoryTable, 'Users': UserTable} olist = objectname.objects.all() if olist: if table == None: data = assocfn[name](olist) else: data = table(olist) tables.RequestConfig(request).configure(data) data_len = len(olist) else: data = None data_len = 0 context = {'objects': data, 'name': name, 'objects_len': data_len} try: objectname.editable context['action'] = objectname.__name__.lower() except: pass if adduri: context['action'] = True context['adduri'] = adduri return scirius_render(request, template, context)
def get_software_recent_usage(context, software): queryset = CPUJob.objects.filter( software__software=software).select_related() table = CPUJobTable(queryset, prefix="software-%d-usage-" % software.pk) config = tables.RequestConfig(context['request'], paginate={"per_page": 5}) config.configure(table) return table