diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-20 17:12:27 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-20 17:13:52 +0100 |
commit | 96eee66985a22619eb71cacf396ee609058459fc (patch) | |
tree | c6a21923d5e313691afc406934b37ff7ae0d1df9 /chimere/models.py | |
parent | a489cfe6556d26af0e280d533f78c9a378cc4929 (diff) | |
download | Chimère-96eee66985a22619eb71cacf396ee609058459fc.tar.bz2 Chimère-96eee66985a22619eb71cacf396ee609058459fc.zip |
Inform OpenGraph tags (specialy for Facebook share)
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/chimere/models.py b/chimere/models.py index f08ff7a..d4b3219 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -634,6 +634,31 @@ class GeographicItem(models.Model): def geometry(self): return getattr(self, self.geom_attr).wkt + def text_description(self): + """ + Convert the html description into a text description + """ + if not hasattr(self, 'description'): + return "" + soup = BeautifulSoup(self.description) + # kill all script and style elements + for script in soup(["script", "style"]): + script.extract() # rip it out + + # get text + text = soup.get_text() + + # break into lines and remove leading and trailing space on each + lines = (line.strip() for line in text.splitlines()) + # break multi-headlines into a line each + chunks = (phrase.strip() for line in lines for phrase in + line.split(" ")) + # drop blank lines + text = '\n'.join(chunk for chunk in chunks if chunk) + # drop line breaks + text = text.replace('\n', ' ') + return text + def _get_geom_item_fk_name(self): geom_attr = self.geom_attr return GEOM_TO_GEOM_ITEM[geom_attr].lower() @@ -765,6 +790,12 @@ class GeographicItem(models.Model): for pict in self.pictures.all()] return picts + @property + def image(self): + if not self.pictures.count(): + return + return self.pictures.order_by('pk').all()[0] + def get_full_dict(self): dct = {} # get all property even the one not displayed @@ -851,6 +882,7 @@ class Marker(GeographicItem): is_front_page = models.NullBooleanField(_("Is front page"), blank=True, null=True) objects = models.GeoManager() + geom_attr = 'point' class Meta: ordering = ('status', 'name') @@ -884,10 +916,6 @@ class Marker(GeographicItem): def short_desc(self): return shortify(self.description) - @property - def geom_attr(self): - return 'point' - def getLatitude(self): """ Return the latitude @@ -1086,15 +1114,12 @@ class Polygon(GeographicItem): _("Inner color"), max_length=200, help_text=_("HTML code/name"), blank=True, null=True) objects = models.GeoManager() + geom_attr = 'polygon' class Meta: ordering = ('status', 'name') verbose_name = _("Polygon") - @property - def geom_attr(self): - return 'polygon' - def getGeoJSON(self, color="#000", inner_color='#0F0'): '''Return a GeoJSON string ''' @@ -1543,15 +1568,12 @@ class Route(GeographicItem): _("Color"), max_length=200, help_text=_("HTML code/name"), blank=True, null=True) objects = models.GeoManager() + geom_attr = 'route' class Meta: ordering = ('status', 'name') verbose_name = _("Route") - @property - def geom_attr(self): - return 'route' - def getGeoJSON(self, color="#000"): '''Return a GeoJSON string ''' |