Repository: kartoza/prj.app

Issue:
Reshape html summary in atom/rss sponsors feed
Currently the sponsor items are looking like this:

```
<div>
<img
src="/media/images/projects/b9c08a00a74cba8e406e97f94a1f90595f5ac39d.png"
width="300px">
</div>
<p><span>Sponsorship level: Gold : 9000 EUR</span>
<br/>
<span>Sponsorship period: 21 June 2017 - 21 June 2018</span><br/>
<span>Amount sponsored: EUR 9000.00<span>
</p>
```

Is it (easy) possible in this html to change the following:
- make the img-element a full url (as I use the feed in qgis.org and it is easiest to just retrieve the images from changelog.qgis.org
- add some classes to the img-element and the p-element as then I can do some more styling.

An example:

```
<div>
<img src="http://changelog.qgis.org/media/images/projects/..5ac39d.png"
class="sponsor_img gold">
</div>
<p class="sponsor_body gold">
<span>Sponsorship level: Gold : 9000 EUR</span>
<br/>
<span>Sponsorship period: 21 June 2017 - 21 June 2018</span>
<br/>
<span>Amount sponsored: EUR 9000.00<span>
</p>
```




Discussion:
hi @rduivenvoorde ,
we have the `image_url` property for each sponsor using the full url in this page http://changelog.qgis.org/en/qgis/sponsors/json/ 
will that be able to help you?
@ann26 thanks for this.

Yes, I know it is there. It is also available in the atom version I use (http://changelog.qgis.org/en/qgis/sponsors/atom/). BUT my 'problem' is that I do want to take over the 'summary' (in atom) or 'description' (in rss) as verbatim as possible.
I have to create some html, and can not easily extract the information I need from both feeds:
- an description (NOT holding an relative url, OR holding a full url)
- an type of sponor (so I can style the different types gold/silver/bronze) differently
- an url
(- optionally(!) the sponsor start/end period so I can check validity)
If we are able to create/change the summary/description in the way I describe above, it will much easier for me to extract/use the information.
Note that I already can build it by running over the items and do a lot of guessing and 'find-replacing' of the summary to mold it in the way I can use it in the website sponsor list.

BUT if there is no way to influence the description/summary, for example if you use a library for it that lacks that functionality, then I'll use what there is now....
See #903 for another issue which makes I cannot easily use the feeds.


Resolving patch:
diff --git a/django_project/changes/feeds/sponsor.py b/django_project/changes/feeds/sponsor.py
--- a/django_project/changes/feeds/sponsor.py
+++ b/django_project/changes/feeds/sponsor.py
@@ -3,8 +3,9 @@
 __author__ = 'Anita Hapsari <anita@kartoza.com>'
 __date__ = '23/10/2017'
 
-from django.conf import settings
+import datetime
 from django.contrib.syndication.views import Feed
+from django.core.urlresolvers import reverse
 from django.utils.feedgenerator import Atom1Feed
 from django.shortcuts import get_object_or_404
 from base.models.project import Project
@@ -34,6 +35,7 @@ def get_object(self, request, *args, **kwargs):
         :raises: Http404
         """
         project_slug = kwargs.get('project_slug', None)
+        self.domain_path_url = request.build_absolute_uri(reverse('home'))
         return get_object_or_404(Project, slug=project_slug)
 
     def title(self, obj):
@@ -78,8 +80,10 @@ def items(self, obj):
         :returns: List of latest sponsor of a project
         :rtype: list
         """
+        today = datetime.datetime.now().date()
         return SponsorshipPeriod.objects.filter(
-            project=obj).order_by('-sponsorship_level__value', '-end_date')
+            project=obj, end_date__gte=today
+        ).order_by('-sponsorship_level__value', '-end_date')
 
     def item_title(self, item):
         """Return the title of the sponsor.
@@ -101,20 +105,26 @@ def item_description(self, item):
         :returns: description of the sponsor
         :rtype: str
         """
+        level_class = str(item.sponsorship_level.name).decode('utf-8').lower()
+        head, sep, tail = self.domain_path_url.partition('/en/')
+
         data = {
-            'media_url': settings.MEDIA_URL,
-            'sponsor_logo': item.sponsor.logo,
+            'domain': head,
+            'sponsor_logo': item.sponsor.logo.url,
             'sponsor_level': item.sponsorship_level,
             'start_date': item.start_date.strftime('%d %B %Y'),
             'end_date': item.end_date.strftime('%d %B %Y'),
             'currency': item.currency,
             'amount_sponsored': item.amount_sponsored,
+            'sponsor_class': level_class,
         }
 
         descriptions = \
             '<div>' \
-            '<img src="{media_url}{sponsor_logo}" width="300px"></div>' \
-            '<p><span>Sponsorship level: {sponsor_level}</span><br/>' \
+            '<img class="sponsor_img {sponsor_class}" ' \
+            'src="{domain}{sponsor_logo}" width="300px"></div>' \
+            '<p class="sponsor_body {sponsor_class}">' \
+            '<span>Sponsorship level: {sponsor_level}</span><br/>' \
             '<span>Sponsorship period: {start_date} - {end_date}</span><br/>' \
             '<span>Amount sponsored: {currency} {amount_sponsored}<span></p>'\
             .format(**data)


Test patch: