Create proper URL check for feature matrix entries
authorJonathan S. Katz <jonathan.katz@excoventures.com>
Sun, 30 Aug 2020 20:47:12 +0000 (16:47 -0400)
committerJonathan S. Katz <jonathan.katz@excoventures.com>
Sun, 30 Aug 2020 20:47:12 +0000 (16:47 -0400)
40d6891c had created a false illusion of working, which can
certainly be blamed on the patch author. That said, instead
of trying to work around what the standard Django filters
provide, it is more prudent to create a "URL checking"
function for the feature matrix descriptions. This can be
used both for the "featurelink" generation, as well as the
new check we make to get the stated goal of 40d6891c, i.e.
provide a clickable URL when that is the only content of a
feature description.

pgweb/featurematrix/models.py
templates/featurematrix/featuredetail.html

index 982c8c582b0835577a7773b0f1a764d00a49ac1e..1029dfc5ec940d5ef6c87aab5923c0435da5e6a3 100644 (file)
@@ -59,9 +59,16 @@ class Feature(models.Model):
         # Get a list of column based on all versions that are visible_default
         return [choices_map[getattr(self, a)] for a, b in versions]
 
+    def featuredescription_is_url(self):
+        """
+        Returns true if the entirety of the feautre description is a URL, or
+        at least gives off the appearance that it is.
+        """
+        return self.featuredescription.startswith('https://') or self.featuredescription.startswith('http://')
+
     @property
     def featurelink(self):
-        if self.featuredescription.startswith('https://') or self.featuredescription.startswith('http://'):
+        if self.featuredescription_is_url():
             return self.featuredescription
         else:
             return 'detail/%s/' % self.id
index 717eab8aeca92e8586afe034c96cf025b354be34..e5edf0cfffa1afb99db03a5080ffc49212641df1 100644 (file)
@@ -5,7 +5,7 @@
 <h1>Feature Description</h1>
 <h2>{{feature.featurename}}</h2>
 <p>
-{% if feature.featurelink|truncatechars:4 == "http" %}
+{% if feature.featuredescription_is_url %}
   For more information, please visit : <a href="{{ feature.featurelink }}">{{ feature.featurelink }}</a>
 {% else %}
   {{ feature.featuredescription|markdown:"safe" }}