Project

General

Profile

0001-backoffice-remove-support-for-displaying-a-news-entr.patch

Frédéric Péters (absent jusqu’au 12/12), 07 Nov 2016 09:53 AM

Download (4.23 KB)

View differences:

Subject: [PATCH] backoffice: remove support for displaying a news entry on
 homescreen (#13880)

This effectively reverts 17effa588f1535b3aae0bc58aebdd4952c7f0d79 (#1781).
 wcs/qommon/backoffice/root.py | 76 -------------------------------------------
 wcs/qommon/publisher.py       |  1 -
 2 files changed, 77 deletions(-)
wcs/qommon/backoffice/root.py
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import hashlib
18
import os
19
import socket
20
import time
21
import urllib2
22

  
23 17
from quixote.directory import Directory, AccessControlled
24 18
from quixote import get_publisher, get_request, get_response
25
from quixote.html import htmltext, TemplateIO
26

  
27
try:
28
    import feedparser
29
except ImportError:
30
    feedparser = None
31 19

  
32 20
from qommon import errors
33
from qommon.storage import atomic_write
34 21

  
35 22
class BackofficeRootDirectory(AccessControlled, Directory):
36 23

  
......
64 51

  
65 52
        get_response().filter['in_backoffice'] = True
66 53

  
67
    def get_feed_url(self, language):
68
        feed_url = get_publisher().get_site_option('backoffice_feed_url')
69
        if feed_url == 'false':
70
            return None
71
        elif feed_url:
72
            return feed_url
73
        if not get_publisher().backoffice_feed_url:
74
            return None
75
        return get_publisher().backoffice_feed_url.get(language)
76

  
77
    def get_feed_filename(self, feed_url):
78
        md5_hash = hashlib.md5()
79
        md5_hash.update(feed_url)
80
        return os.path.join(get_publisher().app_dir, 'feed-' + md5_hash.hexdigest())
81

  
82
    def get_sidebar(self):
83
        if feedparser is None:
84
            return None
85
        feed_url = self.get_feed_url(get_request().language)
86
        if not feed_url:
87
            return None
88
        feed_filename = self.get_feed_filename(feed_url)
89
        if not os.path.exists(feed_filename):
90
            self.update_backoffice_feed()
91
            return None
92
        if os.stat(feed_filename)[8] < (time.time()-86400):
93
            self.update_backoffice_feed()
94

  
95
        feed = feedparser.parse(feed_filename)
96
        if not feed.entries:
97
            return None
98

  
99
        r = TemplateIO(html=True)
100
        publication_time = feed.entries[0]['published_parsed']
101
        if time.mktime(publication_time) > (time.time()-7*86400):
102
            r += htmltext('<div class="news recent">')
103
        else:
104
            r += htmltext('<div class="news">')
105
        r += htmltext('<h3>%s</h3>') % feed.entries[0]['title'].encode(get_publisher().site_charset)
106
        r += htmltext(feed.entries[0]['content'][0]['value'].encode(get_publisher().site_charset))
107
        r += htmltext('</div>')
108
        return r.getvalue()
109

  
110
    def update_backoffice_feed(self):
111
        job = get_response().add_after_job(
112
                    N_('Updating Backoffice Info Feed'),
113
                    self.update_backoffice_feed_real,
114
                    fire_and_forget=True)
115
        job.feed_language = get_request().language
116

  
117
    def update_backoffice_feed_real(self, job):
118
        feed_url = self.get_feed_url(job.feed_language)
119
        if not feed_url:
120
            return None
121
        try:
122
            fd = urllib2.urlopen(feed_url)
123
            s = fd.read()
124
            fd.close()
125
        except (urllib2.URLError, socket.error):
126
            return
127
        feed_filename = self.get_feed_filename(feed_url)
128
        atomic_write(feed_filename, s)
129

  
130 54
    def get_menu_items(self):
131 55
        return self.menu_items
wcs/qommon/publisher.py
70 70

  
71 71
    admin_help_url = None
72 72
    backoffice_help_url = None
73
    backoffice_feed_url = None
74 73

  
75 74
    root_directory_class = None
76 75
    backoffice_directory_class = None
77
-