From f963e559d5cdb459859c87681889eae31420a018 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sun, 27 May 2012 21:05:36 +0200 Subject: [PATCH] Make it possible to turn off visibilty of versions in the feature matrix Turn the feature matrix fields into their own class and add a paramter for visible_default to it. Turning this off will hide them from view. In the future this could be expanded to make it dynamic, but for now let's just stick to being able to statically hide them. --- pgweb/featurematrix/models.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pgweb/featurematrix/models.py b/pgweb/featurematrix/models.py index 46f80fca..a23167eb 100644 --- a/pgweb/featurematrix/models.py +++ b/pgweb/featurematrix/models.py @@ -24,19 +24,24 @@ class FeatureGroup(PgModel, models.Model): # Return a list of all the columns for the matrix return [b for a,b in versions] +class FeatureMatrixField(models.IntegerField): + def __init__(self, verbose_name, visible_default=True): + super(FeatureMatrixField, self).__init__(null=False, blank=False, default=0, verbose_name=verbose_name, choices=choices) + self.visible_default = visible_default + class Feature(PgModel, models.Model): group = models.ForeignKey(FeatureGroup, null=False, blank=False) featurename = models.CharField(max_length=100, null=False, blank=False) featuredescription = models.TextField(null=False, blank=True) #WARNING! All fields that start with "v" will be considered versions! - v74 = models.IntegerField(null=False, blank=False, default=0, verbose_name="7.4", choices=choices) - v80 = models.IntegerField(null=False, blank=False, default=0, verbose_name="8.0", choices=choices) - v81 = models.IntegerField(null=False, blank=False, default=0, verbose_name="8.1", choices=choices) - v82 = models.IntegerField(null=False, blank=False, default=0, verbose_name="8.2", choices=choices) - v83 = models.IntegerField(null=False, blank=False, default=0, verbose_name="8.3", choices=choices) - v84 = models.IntegerField(null=False, blank=False, default=0, verbose_name="8.4", choices=choices) - v90 = models.IntegerField(null=False, blank=False, default=0, verbose_name="9.0", choices=choices) - v91 = models.IntegerField(null=False, blank=False, default=0, verbose_name="9.1", choices=choices) + v74 = FeatureMatrixField(verbose_name="7.4") + v80 = FeatureMatrixField(verbose_name="8.0") + v81 = FeatureMatrixField(verbose_name="8.1") + v82 = FeatureMatrixField(verbose_name="8.2") + v83 = FeatureMatrixField(verbose_name="8.3") + v84 = FeatureMatrixField(verbose_name="8.4") + v90 = FeatureMatrixField(verbose_name="9.0") + v91 = FeatureMatrixField(verbose_name="9.1") purge_urls = ('/about/featurematrix/.*', ) @@ -54,5 +59,5 @@ class Feature(PgModel, models.Model): else: return 'detail/%s/' % self.id -versions = [(f.name,f.verbose_name) for f in Feature()._meta.fields if f.name.startswith('v')] +versions = [(f.name,f.verbose_name) for f in Feature()._meta.fields if f.name.startswith('v') and f.visible_default] -- 2.39.5