class RegulationLandingPage(RoutablePageMixin, CFGOVPage): """Landing page for eregs.""" header = StreamField([ ('hero', molecules.Hero()), ], blank=True) content = StreamField([ ('notification', molecules.Notification()), ('full_width_text', RegulationsListingFullWidthText()), ], blank=True) # General content tab content_panels = CFGOVPage.content_panels + [ StreamFieldPanel('header'), StreamFieldPanel('content'), ] # Tab handler interface edit_handler = TabbedInterface([ ObjectList(content_panels, heading='General Content'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar'), ObjectList(CFGOVPage.settings_panels, heading='Configuration'), ]) objects = CFGOVPageManager() subpage_types = ['regulations3k.RegulationPage', 'RegulationsSearchPage'] template = 'regulations3k/landing-page.html' def get_context(self, request, *args, **kwargs): context = super(CFGOVPage, self).get_context(request, *args, **kwargs) context.update({ 'get_secondary_nav_items': get_secondary_nav_items, }) return context @route(r'^recent-notices-json/$', name='recent_notices') def recent_notices(self, request): fr_api_url = 'https://www.federalregister.gov/api/v1/' fr_documents_url = fr_api_url + 'documents.json' params = { 'fields_list': ['html_url', 'title'], 'per_page': '3', 'order': 'newest', 'conditions[agencies][]': 'consumer-financial-protection-bureau', 'conditions[type][]': 'RULE', 'conditions[cfr][title]': '12', } response = requests.get(fr_documents_url, params=params) if response.status_code != 200: return HttpResponse(status=response.status_code) return JsonResponse(response.json())
class DocumentDetailPage(AbstractFilterPage): content = StreamField([ ('full_width_text', organisms.FullWidthText()), ('expandable', organisms.Expandable()), ('expandable_group', organisms.ExpandableGroup()), ('notification', molecules.Notification()), ('table_block', organisms.AtomicTableBlock( table_options={'renderer': 'html'})), ('feedback', v1_blocks.Feedback()), ], blank=True) edit_handler = AbstractFilterPage.generate_edit_handler( content_panel=StreamFieldPanel('content') ) template = 'document-detail/index.html' objects = PageManager() search_fields = AbstractFilterPage.search_fields + [ index.SearchField('content') ]
class ActivityIndexPage(CFGOVPage): """A model for the Activity Search page.""" subpage_types = ['teachers_digital_platform.ActivityPage'] objects = CFGOVPageManager() header = StreamField([ ('text_introduction', molecules.TextIntroduction()), ('notification', molecules.Notification()), ], blank=True) header_sidebar = StreamField([ ('image', TdpSearchHeroImage()), ], blank=True) results = {} activity_setups = None content_panels = CFGOVPage.content_panels + [ StreamFieldPanel('header'), StreamFieldPanel('header_sidebar'), ] edit_handler = TabbedInterface([ ObjectList(content_panels, heading='General Content'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar/Footer'), ObjectList(CFGOVPage.settings_panels, heading='Configuration'), ]) @classmethod def can_create_at(cls, parent): # You can only create one of these! return super(ActivityIndexPage, cls).can_create_at(parent) \ and not cls.objects.exists() def get_template(self, request): template = 'teachers_digital_platform/activity_index_page.html' if 'partial' in request.GET: template = 'teachers_digital_platform/activity_search_facets_and_results.html' # noqa: E501 return template def dsl_search(self, request, *args, **kwargs): """Search using Elasticsearch 7 and django-elasticsearch-dsl.""" all_facets = copy.copy(self.activity_setups.facet_setup) selected_facets = {} card_setup = self.activity_setups.ordered_cards total_activities = len(card_setup) search_query = request.GET.get('q', '') facet_called = any( [request.GET.get(facet, '') for facet in FACET_LIST] ) # If there's no query or facet request, we can return cached setups: if not search_query and not facet_called: payload = { 'search_query': search_query, 'results': list(card_setup.values()), 'total_results': total_activities, 'total_activities': total_activities, 'selected_facets': selected_facets, 'all_facets': all_facets, 'expanded_facets': ALWAYS_EXPANDED, } self.results = payload results_per_page = validate_results_per_page(request) paginator = Paginator(payload['results'], results_per_page) current_page = validate_page_number(request, paginator) paginated_page = paginator.page(current_page) context_update = { 'facets': all_facets, 'activities': paginated_page, 'total_results': total_activities, 'results_per_page': results_per_page, 'current_page': current_page, 'paginator': paginator, 'show_filters': bool(selected_facets), } return context_update dsl_search = ActivityPageDocument().search() if search_query: terms = search_query.split() for term in terms: dsl_search = dsl_search.query( "bool", must=Q("multi_match", query=term, fields=SEARCH_FIELDS) ) else: dsl_search = dsl_search.sort('-date') for facet, facet_config in FACET_MAP: if facet in request.GET and request.GET.get(facet): facet_ids = [ value for value in request.GET.getlist(facet) if value.isdigit() ] selected_facets[facet] = facet_ids for facet, pks in selected_facets.items(): dsl_search = dsl_search.query( "bool", should=[Q("match", **{facet: pk}) for pk in pks] ) facet_search = dsl_search.update_from_dict(FACET_DICT) total_results = dsl_search.count() dsl_search = dsl_search[:total_results] response = dsl_search.execute() results = [ card_setup[str(hit.id)] for hit in response[:total_results] ] facet_response = facet_search.execute() facet_counts = {facet: getattr( facet_response.aggregations, f"{facet}_terms").buckets for facet in FACET_LIST} all_facets = parse_dsl_facets( all_facets, facet_counts, selected_facets ) payload = { 'search_query': search_query, 'results': results, 'total_results': total_results, 'total_activities': total_activities, 'selected_facets': selected_facets, 'all_facets': all_facets, } # List all facet blocks that need to be expanded conditionally_expanded = { facet_name for facet_name, facet_items in all_facets.items() if any( facet['selected'] is True for facet in facet_items ) } expanded_facets = ALWAYS_EXPANDED.union(set(conditionally_expanded)) payload.update({ 'expanded_facets': expanded_facets, }) self.results = payload results_per_page = validate_results_per_page(request) paginator = Paginator(payload['results'], results_per_page) current_page = validate_page_number(request, paginator) paginated_page = paginator.page(current_page) context_update = { 'facets': all_facets, 'activities': paginated_page, 'total_results': total_results, 'results_per_page': results_per_page, 'current_page': current_page, 'paginator': paginator, 'show_filters': bool(selected_facets), } return context_update def get_context(self, request, *args, **kwargs): if not self.activity_setups: self.activity_setups = get_activity_setup() context_update = self.dsl_search(request, *args, **kwargs) context = super(ActivityIndexPage, self).get_context(request) context.update(context_update) return context class Meta: verbose_name = "TDP Activity search page"
class ActivityIndexPage(CFGOVPage): """ A model for the Activity Search page. """ subpage_types = ['teachers_digital_platform.ActivityPage'] objects = CFGOVPageManager() header = StreamField([ ('text_introduction', molecules.TextIntroduction()), ('notification', molecules.Notification()), ], blank=True) header_sidebar = StreamField([ ('image', TdpSearchHeroImage()), ], blank=True) results = {} content_panels = CFGOVPage.content_panels + [ StreamFieldPanel('header'), StreamFieldPanel('header_sidebar'), ] edit_handler = TabbedInterface([ ObjectList(content_panels, heading='General Content'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar/Footer'), ObjectList(CFGOVPage.settings_panels, heading='Configuration'), ]) @classmethod def can_create_at(cls, parent): # You can only create one of these! return super(ActivityIndexPage, cls).can_create_at(parent) \ and not cls.objects.exists() def get_template(self, request): template = 'teachers_digital_platform/activity_index_page.html' if 'partial' in request.GET: template = 'teachers_digital_platform/activity_search_facets_and_results.html' # noqa: E501 return template def get_context(self, request, *args, **kwargs): facet_map = ( ('building_block', (ActivityBuildingBlock, False, 10)), ('school_subject', (ActivitySchoolSubject, False, 25)), ('topic', (ActivityTopic, True, 25)), ('grade_level', (ActivityGradeLevel, False, 10)), ('age_range', (ActivityAgeRange, False, 10)), ('student_characteristics', (ActivityStudentCharacteristics, False, 10)), # noqa: E501 ('activity_type', (ActivityType, False, 10)), ('teaching_strategy', (ActivityTeachingStrategy, False, 25)), ('blooms_taxonomy_level', (ActivityBloomsTaxonomyLevel, False, 25)), # noqa: E501 ('activity_duration', (ActivityDuration, False, 10)), ('jump_start_coalition', (ActivityJumpStartCoalition, False, 25)), ('council_for_economic_education', (ActivityCouncilForEconEd, False, 25)), # noqa: E501 ) search_query = request.GET.get('q', '') # haystack cleans this string sqs = SearchQuerySet().models(ActivityPage).filter(live=True) total_activities = sqs.count() # Load selected facets selected_facets = {} facet_queries = {} for facet, facet_config in facet_map: sqs = sqs.facet(str(facet), size=facet_config[2]) if facet in request.GET and request.GET.get(facet): selected_facets[facet] = [ int(value) for value in request.GET.getlist(facet) if value.isdigit() ] facet_queries[facet] = facet + '_exact:' + ( " OR " + facet + "_exact:").join( [str(value) for value in selected_facets[facet]]) payload = { 'search_query': search_query, 'results': [], 'total_results': 0, 'total_activities': total_activities, 'selected_facets': selected_facets, 'facet_queries': facet_queries, 'all_facets': {}, } # Apply search query if it exists, but don't apply facets if search_query: sqs = sqs.filter(content=search_query).order_by( '-_score', '-date') # noqa: E501 else: sqs = sqs.order_by('-date') # Get all facets and their counts facet_counts = sqs.facet_counts() all_facets = self.get_all_facets(facet_map, sqs, facet_counts, facet_queries, selected_facets) # noqa: E501 # List all facet blocks that need to be expanded always_expanded = {'building_block', 'topic', 'school_subject'} conditionally_expanded = { facet_name for facet_name, facet_items in all_facets.items() if any(facet['selected'] is True for facet in facet_items) } expanded_facets = always_expanded.union(set(conditionally_expanded)) payload.update({ 'facet_counts': facet_counts, 'all_facets': all_facets, 'expanded_facets': expanded_facets, }) # Apply all the active facet values to our search results for facet_narrow_query in facet_queries.values(): sqs = sqs.narrow(facet_narrow_query) results = [activity.object for activity in sqs] total_results = sqs.count() payload.update({ 'results': results, 'total_results': total_results, }) self.results = payload results_per_page = validate_results_per_page(request) paginator = Paginator(payload['results'], results_per_page) current_page = validate_page_number(request, paginator) paginated_page = paginator.page(current_page) context = super(ActivityIndexPage, self).get_context(request) context.update({ 'facet_counts': facet_counts, 'facets': all_facets, 'activities': paginated_page, 'total_results': total_results, 'results_per_page': results_per_page, 'current_page': current_page, 'paginator': paginator, 'show_filters': bool(facet_queries), }) return context def get_all_facets(self, facet_map, sqs, facet_counts, facet_queries, selected_facets): # noqa: E501 all_facets = {} if 'fields' in facet_counts: for facet, facet_config in facet_map: class_object, is_nested, max_facet_count = facet_config all_facets_sqs = sqs other_facet_queries = [ facet_query for facet_query_name, facet_query in facet_queries.items() # noqa: E501 if facet != facet_query_name ] for other_facet_query in other_facet_queries: all_facets_sqs = all_facets_sqs.narrow( str(other_facet_query)) # noqa: E501 narrowed_facet_counts = all_facets_sqs.facet_counts() if 'fields' in narrowed_facet_counts and facet in narrowed_facet_counts[ 'fields']: # noqa: E501 narrowed_facets = [ value[0] for value in narrowed_facet_counts['fields'][facet] ] # noqa: E501 narrowed_selected_facets = selected_facets[ facet] if facet in selected_facets else [ ] # noqa: E501 if is_nested: all_facets[facet] = self.get_nested_facets( class_object, narrowed_facets, narrowed_selected_facets) else: all_facets[facet] = self.get_flat_facets( class_object, narrowed_facets, narrowed_selected_facets) return all_facets def get_flat_facets(self, class_object, narrowed_facets, selected_facets): final_facets = [{ 'selected': result['id'] in selected_facets, 'id': result['id'], 'title': result['title'], } for result in class_object.objects.filter( pk__in=narrowed_facets).values('id', 'title')] # noqa: E501 return final_facets def get_nested_facets(self, class_object, narrowed_facets, selected_facets, parent=None): # noqa: E501 if not parent: flat_final_facets = [{ 'selected': result['id'] in selected_facets, 'id': result['id'], 'title': result['title'], 'parent': result['parent'], } for result in class_object.objects.filter( pk__in=narrowed_facets).get_ancestors(True).values( 'id', 'title', 'parent')] # noqa: E501 final_facets = [] root_facets = [ root_facet for root_facet in flat_final_facets if root_facet['parent'] is None ] # noqa: E501 for root_facet in root_facets: children_list = self.get_nested_facets( class_object, narrowed_facets, selected_facets, root_facet['id']) # noqa: E501 child_selected = any(child['selected'] is True or child['child_selected'] is True for child in children_list # noqa: E501 ) final_facets.append({ 'selected': root_facet['selected'], 'child_selected': child_selected, 'id': root_facet['id'], 'title': root_facet['title'], 'parent': root_facet['parent'], 'children': children_list }) return final_facets else: children = [ { 'selected': result['id'] in selected_facets or result['parent'] in selected_facets, # noqa: E501 'id': result['id'], 'title': result['title'], 'parent': result['parent'], 'children': self.get_nested_facets(class_object, narrowed_facets, selected_facets, result['id']), # noqa: E501 'child_selected': any(child['selected'] is True or child['child_selected'] is True for child in # noqa: E501 self.get_nested_facets(class_object, narrowed_facets, selected_facets, result['id']) # noqa: E501 ) } for result in class_object.objects.filter( pk__in=narrowed_facets).filter( parent_id=parent).values('id', 'title', 'parent') ] # noqa: E501 return children class Meta: verbose_name = "TDP Activity search page"
class SublandingPage(CFGOVPage): portal_topic = models.ForeignKey( 'v1.PortalTopic', blank=True, null=True, related_name='portal_pages', on_delete=models.SET_NULL, help_text='Select a topic if this is a MONEY TOPICS portal page.') header = StreamField([ ('hero', molecules.Hero()), ], blank=True) content = StreamField([ ('text_introduction', molecules.TextIntroduction()), ('notification', molecules.Notification()), ('featured_content', organisms.FeaturedContent()), ('full_width_text', organisms.FullWidthText()), ('info_unit_group', organisms.InfoUnitGroup()), ('well', organisms.Well()), ('snippet_list', organisms.ResourceList()), ('post_preview_snapshot', organisms.PostPreviewSnapshot()), ('contact', organisms.MainContactInfo()), ('table_block', organisms.AtomicTableBlock( table_options={'renderer': 'html'} )), ('reg_comment', organisms.RegComment()), ('feedback', v1_blocks.Feedback()), ], blank=True) sidebar_breakout = StreamField([ ('slug', blocks.CharBlock(icon='title')), ('heading', blocks.CharBlock(icon='title')), ('paragraph', blocks.RichTextBlock(icon='edit')), ('breakout_image', blocks.StructBlock([ ('image', ImageChooserBlock()), ('is_round', blocks.BooleanBlock(required=False, default=True, label='Round?')), ('icon', blocks.CharBlock(help_text='Enter icon class name.')), ('heading', blocks.CharBlock(required=False, label='Introduction Heading')), ('body', blocks.TextBlock(required=False, label='Introduction Body')), ], heading='Breakout Image', icon='image')), ('related_posts', organisms.RelatedPosts()), ('job_listing_list', JobListingList()), ], blank=True) # General content tab content_panels = CFGOVPage.content_panels + [ StreamFieldPanel('header'), StreamFieldPanel('content'), FieldPanel('portal_topic'), ] sidebar_panels = [ StreamFieldPanel('sidebar_breakout'), ] + CFGOVPage.sidefoot_panels # Tab handler interface edit_handler = TabbedInterface([ ObjectList(content_panels, heading='General Content'), ObjectList(sidebar_panels, heading='Sidebar'), ObjectList(CFGOVPage.settings_panels, heading='Configuration'), ]) template = 'sublanding-page/index.html' objects = PageManager() search_fields = CFGOVPage.search_fields + [ index.SearchField('content'), index.SearchField('header') ] def get_browsefilterable_posts(self, limit): filter_pages = [p.specific for p in self.get_appropriate_descendants() if 'FilterablePage' in p.specific_class.__name__ and 'archive' not in p.title.lower()] posts_list = [] for page in filter_pages: eligible_children = AbstractFilterPage.objects.live().filter( CFGOVPage.objects.child_of_q(page) ) form = FilterableListForm(filterable_pages=eligible_children, wagtail_block=None) for post in form.get_page_set(): posts_list.append(post) return sorted(posts_list, key=lambda p: p.date_published, reverse=True)[:limit]
class EnforcementActionPage(AbstractFilterPage): sidebar_header = models.CharField( default='Action details', max_length=100 ) court = models.CharField(default='', max_length=150, blank=True) institution_type = models.CharField(max_length=50, choices=[ ('Nonbank', 'Nonbank'), ('Bank', 'Bank') ]) content = StreamField([ ('full_width_text', organisms.FullWidthText()), ('expandable', organisms.Expandable()), ('expandable_group', organisms.ExpandableGroup()), ('notification', molecules.Notification()), ('table_block', organisms.AtomicTableBlock( table_options={'renderer': 'html'})), ('feedback', v1_blocks.Feedback()), ], blank=True) content_panels = [ StreamFieldPanel('header'), StreamFieldPanel('content') ] metadata_panels = [ MultiFieldPanel([ FieldPanel('sidebar_header'), FieldPanel('court'), FieldPanel('institution_type'), FieldPanel('date_filed'), FieldPanel('tags', 'Tags'), ], heading='Basic Metadata'), MultiFieldPanel([ InlinePanel( 'docket_numbers', label="Docket Number", min_num=1 ), ], heading='Docket Number'), MultiFieldPanel([ InlinePanel('statuses', label="Enforcement Status", min_num=1), ], heading='Enforcement Status'), MultiFieldPanel([ InlinePanel('categories', label="Categories", min_num=1, max_num=2), ], heading='Categories'), ] settings_panels = [ MultiFieldPanel(CFGOVPage.promote_panels, 'Settings'), MultiFieldPanel([ FieldPanel('preview_title'), FieldPanel('preview_subheading'), FieldPanel('preview_description'), FieldPanel('secondary_link_url'), FieldPanel('secondary_link_text'), ImageChooserPanel('preview_image'), ], heading='Page Preview Fields', classname='collapsible'), FieldPanel('authors', 'Authors'), MultiFieldPanel([ FieldPanel('date_published'), FieldPanel('comments_close_by'), ], 'Relevant Dates', classname='collapsible'), MultiFieldPanel(Page.settings_panels, 'Scheduled Publishing'), FieldPanel('language', 'Language'), ] edit_handler = TabbedInterface([ ObjectList( AbstractFilterPage.content_panels + content_panels, heading='General Content' ), ObjectList(metadata_panels, heading='Metadata'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar'), ObjectList(settings_panels, heading='Configuration') ]) template = 'enforcement-action/index.html' objects = PageManager() search_fields = AbstractFilterPage.search_fields + [ index.SearchField('content') ]
class AbstractFilterPage(CFGOVPage): header = StreamField([ ('article_subheader', blocks.RichTextBlock(icon='form')), ('text_introduction', molecules.TextIntroduction()), ('item_introduction', organisms.ItemIntroduction()), ('notification', molecules.Notification()), ], blank=True) preview_title = models.CharField(max_length=255, null=True, blank=True) preview_subheading = models.CharField( max_length=255, null=True, blank=True) preview_description = RichTextField(null=True, blank=True) secondary_link_url = models.CharField( max_length=500, null=True, blank=True) secondary_link_text = models.CharField( max_length=255, null=True, blank=True) preview_image = models.ForeignKey( 'v1.CFGOVImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) date_published = models.DateField(default=date.today) date_filed = models.DateField(null=True, blank=True) comments_close_by = models.DateField(null=True, blank=True) # Configuration tab panels settings_panels = [ MultiFieldPanel(CFGOVPage.promote_panels, 'Settings'), InlinePanel('categories', label="Categories", max_num=2), FieldPanel('tags', 'Tags'), MultiFieldPanel([ FieldPanel('preview_title'), FieldPanel('preview_subheading'), FieldPanel('preview_description'), FieldPanel('secondary_link_url'), FieldPanel('secondary_link_text'), ImageChooserPanel('preview_image'), ], heading='Page Preview Fields', classname='collapsible'), FieldPanel('schema_json', 'Structured Data'), FieldPanel('authors', 'Authors'), MultiFieldPanel([ FieldPanel('date_published'), FieldPanel('date_filed'), FieldPanel('comments_close_by'), ], 'Relevant Dates', classname='collapsible'), MultiFieldPanel(Page.settings_panels, 'Scheduled Publishing'), FieldPanel('language', 'Language'), MultiFieldPanel(CFGOVPage.archive_panels, 'Archive'), ] # This page class cannot be created. is_creatable = False objects = CFGOVPageManager() search_fields = CFGOVPage.search_fields + [ index.SearchField('header') ] @classmethod def generate_edit_handler(self, content_panel): content_panels = [ StreamFieldPanel('header'), content_panel, ] return TabbedInterface([ ObjectList(self.content_panels + content_panels, heading='General Content'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar'), ObjectList(self.settings_panels, heading='Configuration'), ]) # Returns an image for the page's meta Open Graph tag @property def meta_image(self): parent_meta = super(AbstractFilterPage, self).meta_image return parent_meta or self.preview_image
class EnforcementActionPage(AbstractFilterPage): public_enforcement_action = models.CharField(max_length=150, blank=True) initial_filing_date = models.DateField(null=True, blank=True) settled_or_contested_at_filing = models.CharField(max_length=10, choices=[('Settled', 'Settled'), ('Contested', 'Contested')], blank=True) court = models.CharField(default='', max_length=150, blank=True) content = StreamField([ ('full_width_text', organisms.FullWidthText()), ('expandable', organisms.Expandable()), ('expandable_group', organisms.ExpandableGroup()), ('notification', molecules.Notification()), ('table_block', organisms.AtomicTableBlock(table_options={'renderer': 'html'})), ('feedback', v1_blocks.Feedback()), ], blank=True) content_panels = [StreamFieldPanel('header'), StreamFieldPanel('content')] metadata_panels = [ FieldPanel('public_enforcement_action'), FieldPanel('initial_filing_date'), InlinePanel('defendant_types', label='Defendant/Respondent Type'), InlinePanel('categories', label="Forum", min_num=1, max_num=2), FieldPanel('court'), InlinePanel('docket_numbers', label="Docket Number", min_num=1), FieldPanel('settled_or_contested_at_filing'), InlinePanel('statuses', label="Status", min_num=1), InlinePanel('products', label="Products"), InlinePanel('at_risk_groups', label="At Risk Groups"), InlinePanel('statutes', label="Statutes/Regulations"), InlinePanel('enforcement_dispositions', label='Final Disposition'), ] settings_panels = [ MultiFieldPanel(CFGOVPage.promote_panels, 'Settings'), MultiFieldPanel([ FieldPanel('preview_title'), FieldPanel('preview_subheading'), FieldPanel('preview_description'), FieldPanel('secondary_link_url'), FieldPanel('secondary_link_text'), ImageChooserPanel('preview_image'), ], heading='Page Preview Fields', classname='collapsible'), FieldPanel('authors', 'Authors'), MultiFieldPanel([ FieldPanel('date_published'), FieldPanel('comments_close_by'), ], 'Relevant Dates', classname='collapsible'), MultiFieldPanel(Page.settings_panels, 'Scheduled Publishing'), FieldPanel('language', 'Language'), MultiFieldPanel(CFGOVPage.archive_panels, 'Archive'), ] edit_handler = TabbedInterface([ ObjectList(AbstractFilterPage.content_panels + content_panels, heading='General Content'), ObjectList(metadata_panels, heading='Metadata'), ObjectList(CFGOVPage.sidefoot_panels, heading='Sidebar'), ObjectList(settings_panels, heading='Configuration') ]) template = 'enforcement-action/index.html' objects = PageManager() search_fields = AbstractFilterPage.search_fields + [ index.SearchField('content') ] @classmethod def all_actions(cls): # Return the collection of all Enforcement Action Pages. # Exclude any pages in the Trash or otherwise not a child of the # EnforcementActionsFilterPage. try: # TODO: find a less hacky way to get only the pages in the # correct part of the page tree pg_id = 1327 parent_page = Page.objects.get(id=pg_id) query = cls.objects.child_of(parent_page) except (Page.DoesNotExist): query = cls.objects query = query.filter(initial_filing_date__isnull=False) query = query.live().order_by('-initial_filing_date') return query def get_context(self, request): context = super(EnforcementActionPage, self).get_context(request) dispositions = self.enforcement_dispositions.all() context.update({ 'total_consumer_relief': sum(disp.final_order_consumer_redress + disp.final_order_other_consumer_relief for disp in dispositions), 'total_cmp': sum(disp.final_order_civil_money_penalty for disp in dispositions), 'defendant_types': [ d.get_defendant_type_display() for d in self.defendant_types.all() ], 'statutes': [s.statute for s in self.statutes.all()], 'products': [p.product for p in self.products.all()], 'at_risk_groups': [g.at_risk_group for g in self.at_risk_groups.all()] }) return context
class BrowsePage(CFGOVPage): header = StreamField([ ('text_introduction', molecules.TextIntroduction()), ('featured_content', organisms.FeaturedContent()), ('notification', molecules.Notification()), ], blank=True) content = StreamField([ ('full_width_text', organisms.FullWidthText()), ('info_unit_group', organisms.InfoUnitGroup()), ('simple_chart', organisms.SimpleChart()), ('expandable_group', organisms.ExpandableGroup()), ('expandable', organisms.Expandable()), ('well', organisms.Well()), ('video_player', organisms.VideoPlayer()), ('snippet_list', organisms.ResourceList()), ('table_block', organisms.AtomicTableBlock(table_options={'renderer': 'html'})), ('feedback', v1_blocks.Feedback()), ('raw_html_block', blocks.RawHTMLBlock(label='Raw HTML block')), ('conference_registration_form', ConferenceRegistrationForm()), ('chart_block', organisms.ChartBlock()), ('mortgage_chart_block', organisms.MortgageChartBlock()), ('mortgage_map_block', organisms.MortgageMapBlock()), ('mortgage_downloads_block', MortgageDataDownloads()), ('data_snapshot', organisms.DataSnapshot()), ('job_listing_table', JobListingTable()), ('yes_checklist', YESChecklist()), ], blank=True) secondary_nav_exclude_sibling_pages = models.BooleanField(default=False) share_and_print = models.BooleanField( default=False, help_text="Include share and print buttons above page content.") # General content tab content_panels = CFGOVPage.content_panels + [ StreamFieldPanel('header'), FieldPanel('share_and_print'), StreamFieldPanel('content'), ] sidefoot_panels = CFGOVPage.sidefoot_panels + [ FieldPanel('secondary_nav_exclude_sibling_pages'), ] # Tab handler interface edit_handler = TabbedInterface([ ObjectList(content_panels, heading='General Content'), ObjectList(sidefoot_panels, heading='Sidebar'), ObjectList(CFGOVPage.settings_panels, heading='Configuration'), ]) template = 'browse-basic/index.html' objects = PageManager() search_fields = CFGOVPage.search_fields + [ index.SearchField('content'), index.SearchField('header') ] @property def page_js(self): return (super(BrowsePage, self).page_js + ['secondary-navigation.js']) def get_context(self, request, *args, **kwargs): context = super(BrowsePage, self).get_context(request, *args, **kwargs) context.update({'get_secondary_nav_items': get_secondary_nav_items}) return context