7

Adds variant count

This commit is contained in:
Jasper Berghoef
2017-05-31 15:59:14 +02:00
committed by Michael van Tellingen
parent cb03a36ba2
commit 961a58505a
2 changed files with 15 additions and 1 deletions

View File

@ -79,6 +79,16 @@ class Segment(ClusterableModel):
"""Return the amount of days the segment has been active.""" """Return the amount of days the segment has been active."""
return count_active_days(self.enable_date, self.disable_date) return count_active_days(self.enable_date, self.disable_date)
def get_used_pages(self):
pass
def get_created_variants(self):
page_classes = [page_class for page_class
in PersonalisablePage.__subclasses__()]
pages = [page.objects.filter(segment=self) for page in page_classes]
return list(itertools.chain(*pages))
def get_rules(self): def get_rules(self):
"""Retrieve all rules in the segment.""" """Retrieve all rules in the segment."""
related_rules = [rule.objects.filter(segment=self) related_rules = [rule.objects.filter(segment=self)

View File

@ -39,7 +39,7 @@ class SegmentModelAdmin(ModelAdmin):
dashboard_view_class = SegmentModelDashboardView dashboard_view_class = SegmentModelDashboardView
menu_icon = 'fa-snowflake-o' menu_icon = 'fa-snowflake-o'
add_to_settings_menu = False add_to_settings_menu = False
list_display = ('name', 'persistent', 'match_any', 'status', 'statistics') list_display = ('name', 'persistent', 'match_any', 'status', 'variant_count', 'statistics')
index_view_extra_js = ['js/commons.js', 'js/index.js'] index_view_extra_js = ['js/commons.js', 'js/index.js']
index_view_extra_css = ['css/index.css'] index_view_extra_css = ['css/index.css']
form_view_extra_js = ['js/commons.js', 'js/form.js'] form_view_extra_js = ['js/commons.js', 'js/form.js']
@ -55,6 +55,10 @@ class SegmentModelAdmin(ModelAdmin):
return view_class.as_view(**kwargs)(request) return view_class.as_view(**kwargs)(request)
def variant_count(self, obj):
return _("{pages} pages").format(
pages=len(obj.get_created_variants()))
def statistics(self, obj): def statistics(self, obj):
return _("{visits} visits in {days} days").format( return _("{visits} visits in {days} days").format(
visits=obj.visit_count, days=obj.get_active_days()) visits=obj.visit_count, days=obj.get_active_days())