def _global_template_context(): notify_admin = False if (current_user and current_user.is_authenticated and current_user.admin): key = NEWS_FEED_KEY + str(current_user.id) if sentinel.slave.get(key): notify_admin = True news = get_news() else: news = None # Cookies warning cookie_name = app.config['BRAND'] + "_accept_cookies" show_cookies_warning = False if request and (not request.cookies.get(cookie_name)): show_cookies_warning = True # Announcement sections announcement_levels = app.config.get('ANNOUNCEMENT_LEVELS') if announcement_levels: announcements = cache_users.get_announcements_cached( current_user, announcement_levels) for announcement in announcements: flash(announcement, 'announcement') if app.config.get('CONTACT_EMAIL'): # pragma: no cover contact_email = app.config.get('CONTACT_EMAIL') else: contact_email = '*****@*****.**' if app.config.get('CONTACT_TWITTER'): # pragma: no cover contact_twitter = app.config.get('CONTACT_TWITTER') else: contact_twitter = 'PYBOSSA' # Available plugins plugins = plugin_manager.plugins # LDAP enabled ldap_enabled = app.config.get('LDAP_HOST', False) return dict( brand=app.config['BRAND'], title=app.config['TITLE'], logo=app.config['LOGO'], copyright=app.config['COPYRIGHT'], description=app.config['DESCRIPTION'], terms_of_use=app.config['TERMSOFUSE'], data_use=app.config['DATAUSE'], enforce_privacy=app.config['ENFORCE_PRIVACY'], # version=pybossa.__version__, current_user=current_user, show_cookies_warning=show_cookies_warning, contact_email=contact_email, contact_twitter=contact_twitter, upload_method=app.config['UPLOAD_METHOD'], news=news, notify_admin=notify_admin, plugins=plugins, ldap_enabled=ldap_enabled)
def news(): """Get news from different ATOM RSS feeds.""" import feedparser from pybossa.core import sentinel from pybossa.news import get_news, notify_news_admins, FEED_KEY try: import cPickle as pickle except ImportError: # pragma: no cover import pickle urls = ['https://github.com/pybossa/pybossa/releases.atom', 'http://scifabric.com/blog/all.atom.xml'] score = 0 notify = False if current_app.config.get('NEWS_URL'): urls += current_app.config.get('NEWS_URL') for url in urls: d = feedparser.parse(url) tmp = get_news(score) if (len(tmp) == 0) or (tmp[0]['updated'] != d.entries[0]['updated']): sentinel.master.zadd(FEED_KEY, float(score), pickle.dumps(d.entries[0])) notify = True score += 1 if notify: notify_news_admins()
def _global_template_context(): notify_admin = False if current_user and current_user.is_authenticated(): if current_user.email_addr == current_user.name: flash(gettext("Please update your e-mail address in your" " profile page, right now it is empty!"), 'error') if (current_user and current_user.is_authenticated() and current_user.admin): key = NEWS_FEED_KEY + str(current_user.id) if sentinel.slave.get(key): notify_admin = True news = get_news() else: news = None # Cookies warning cookie_name = app.config['BRAND'] + "_accept_cookies" show_cookies_warning = False if request and (not request.cookies.get(cookie_name)): show_cookies_warning = True # Announcement sections if app.config.get('ANNOUNCEMENT'): announcement = app.config['ANNOUNCEMENT'] if current_user and current_user.is_authenticated(): for key in announcement.keys(): if key == 'admin' and current_user.admin: flash(announcement[key], 'info') if key == 'owner' and len(current_user.projects) != 0: flash(announcement[key], 'info') if key == 'user': flash(announcement[key], 'info') if app.config.get('CONTACT_EMAIL'): # pragma: no cover contact_email = app.config.get('CONTACT_EMAIL') else: contact_email = '*****@*****.**' if app.config.get('CONTACT_TWITTER'): # pragma: no cover contact_twitter = app.config.get('CONTACT_TWITTER') else: contact_twitter = 'PyBossa' return dict( brand=app.config['BRAND'], title=app.config['TITLE'], logo=app.config['LOGO'], copyright=app.config['COPYRIGHT'], description=app.config['DESCRIPTION'], terms_of_use=app.config['TERMSOFUSE'], data_use=app.config['DATAUSE'], enforce_privacy=app.config['ENFORCE_PRIVACY'], # version=pybossa.__version__, current_user=current_user, show_cookies_warning=show_cookies_warning, contact_email=contact_email, contact_twitter=contact_twitter, upload_method=app.config['UPLOAD_METHOD'], news=news, notify_admin=notify_admin)
def _global_template_context(): notify_admin = False if (current_user and current_user.is_authenticated() and current_user.admin): key = NEWS_FEED_KEY + str(current_user.id) if sentinel.slave.get(key): notify_admin = True news = get_news() else: news = None # Cookies warning cookie_name = app.config['BRAND'] + "_accept_cookies" show_cookies_warning = False if request and (not request.cookies.get(cookie_name)): show_cookies_warning = True # Announcement sections if app.config.get('ANNOUNCEMENT'): announcement = app.config['ANNOUNCEMENT'] if current_user and current_user.is_authenticated(): for key in announcement.keys(): if key == 'admin' and current_user.admin: flash(announcement[key], 'info') if key == 'owner' and len(current_user.projects) != 0: flash(announcement[key], 'info') if key == 'user': flash(announcement[key], 'info') if app.config.get('CONTACT_EMAIL'): # pragma: no cover contact_email = app.config.get('CONTACT_EMAIL') else: contact_email = '*****@*****.**' if app.config.get('CONTACT_TWITTER'): # pragma: no cover contact_twitter = app.config.get('CONTACT_TWITTER') else: contact_twitter = 'PYBOSSA' # Available plugins plugins = plugin_manager.plugins return dict( brand=app.config['BRAND'], title=app.config['TITLE'], logo=app.config['LOGO'], copyright=app.config['COPYRIGHT'], description=app.config['DESCRIPTION'], terms_of_use=app.config['TERMSOFUSE'], data_use=app.config['DATAUSE'], enforce_privacy=app.config['ENFORCE_PRIVACY'], # version=pybossa.__version__, current_user=current_user, show_cookies_warning=show_cookies_warning, contact_email=contact_email, contact_twitter=contact_twitter, upload_method=app.config['UPLOAD_METHOD'], news=news, notify_admin=notify_admin, plugins=plugins)
def test_get_news_with_score(self): mapping = dict() mapping[pickle.dumps(self.news)] = 0 sentinel.master.zadd(myset, mapping) news = get_news(score=1) assert len(news) == 0, len(news)
def test_get_news(self): mapping = dict() mapping[pickle.dumps(self.news)] = 0 sentinel.master.zadd(myset, mapping) news = get_news() assert len(news) == 1, len(news) news[0]['updated'] == self.news['updated'], news
def news(): """Get news from different ATOM RSS feeds.""" import feedparser from pybossa.core import sentinel from pybossa.news import get_news, notify_news_admins, FEED_KEY try: import cPickle as pickle except ImportError: # pragma: no cover import pickle urls = [ 'https://github.com/pybossa/pybossa/releases.atom', 'http://scifabric.com/blog/all.atom.xml' ] score = 0 notify = False if current_app.config.get('NEWS_URL'): urls += current_app.config.get('NEWS_URL') for url in urls: d = feedparser.parse(url) tmp = get_news(score) if (len(tmp) == 0) or (tmp[0]['updated'] != d.entries[0]['updated']): sentinel.master.zadd(FEED_KEY, float(score), pickle.dumps(d.entries[0])) notify = True score += 1 if notify: notify_news_admins()
def test_news(self, feedparser_mock): """Test NEWS works.""" feedparser_mock.return_value = self.d news() tmp = get_news() assert len(tmp) == 1, len(tmp) err_msg = "Notify user should be notified" assert self.get_notify_users() == '1', err_msg
def test_news(self, feedparser_mock): """Test NEWS works.""" user = UserFactory.create(admin=True) feedparser_mock.return_value = self.d news() tmp = get_news() assert len(tmp) == 1, len(tmp) err_msg = "Notify user should be notified" assert self.get_notify_users(user) == '1', err_msg
def test_news_no_new_items_no_notification(self, feedparser_mock): """Test NEWS no new items no notificaton works.""" feedparser_mock.return_value = self.d news() self.delete_notify() feedparser_mock.return_value = self.d news() tmp = get_news() assert len(tmp) == 1, len(tmp) err_msg = "Notify user should NOT be notified" assert self.get_notify_users() == None, err_msg
def _global_template_context(): notify_admin = False if (current_user and current_user.is_authenticated and current_user.admin): key = NEWS_FEED_KEY + str(current_user.id) if sentinel.slave.get(key): notify_admin = True news = get_news() else: news = None # Cookies warning cookie_name = app.config['BRAND'] + "_accept_cookies" show_cookies_warning = False if request and (not request.cookies.get(cookie_name)): show_cookies_warning = True # Announcement sections announcement_levels = app.config.get('ANNOUNCEMENT_LEVELS') if announcement_levels: announcements = cache_users.get_announcements_cached( current_user, announcement_levels) for announcement in announcements: flash(announcement, 'announcement') if app.config.get('CONTACT_EMAIL'): # pragma: no cover contact_email = app.config.get('CONTACT_EMAIL') else: contact_email = '*****@*****.**' if app.config.get('CONTACT_TWITTER'): # pragma: no cover contact_twitter = app.config.get('CONTACT_TWITTER') else: contact_twitter = 'PYBOSSA' # Available plugins plugins = plugin_manager.plugins # LDAP enabled ldap_enabled = app.config.get('LDAP_HOST', False) def get_wizard_steps(project=None): show_wizard = True if project is not None: if isinstance(project, dict): owners_id = project['owners_ids'] else: owners_id = project.owners_ids show_wizard = (current_user.subadmin and current_user.id in owners_id) or current_user.admin if not show_wizard: return json.dumps(dict(list=[])) wizard_steps = app.config.get('WIZARD_STEPS') or {} request_details = {'url': request.url, 'path': request.path} project_wizard = Wizard(project, wizard_steps, request_details) return json.dumps(dict(list=project_wizard.get_wizard_list())) return dict( brand=app.config['BRAND'], title=app.config['TITLE'], logo=app.config['LOGO'], copyright=app.config['COPYRIGHT'], description=app.config['DESCRIPTION'], terms_of_use=app.config['TERMSOFUSE'], data_use=app.config['DATAUSE'], enforce_privacy=app.config['ENFORCE_PRIVACY'], # version=pybossa.__version__, current_user=current_user, show_cookies_warning=show_cookies_warning, contact_email=contact_email, contact_twitter=contact_twitter, upload_method=app.config['UPLOAD_METHOD'], news=news, notify_admin=notify_admin, plugins=plugins, ldap_enabled=ldap_enabled, get_wizard_steps=get_wizard_steps, server_type=app.config['SERVER_TYPE'])
def test_get_news(self): sentinel.master.zadd(myset, 0, pickle.dumps(self.news)) news = get_news() assert len(news) == 1, len(news) news[0]['updated'] == self.news['updated'], news
def test_get_news_with_score(self): sentinel.master.zadd(myset, 0, pickle.dumps(self.news)) news = get_news(score=1) assert len(news) == 0, len(news)
def test_get_news_empty(self): news = get_news() assert len(news) == 0, len(news)
def test_get_news_with_score_empty(self): news = get_news(score=1) assert len(news) == 0, len(news)
def _global_template_context(): notify_admin = False if (current_user and current_user.is_authenticated and current_user.admin): key = NEWS_FEED_KEY + str(current_user.id) if sentinel.slave.get(key): notify_admin = True news = get_news() else: news = None # Cookies warning cookie_name = app.config['BRAND'] + "_accept_cookies" show_cookies_warning = False if request and (not request.cookies.get(cookie_name)): show_cookies_warning = True # Announcement sections if app.config.get('ANNOUNCEMENT'): announcement = app.config['ANNOUNCEMENT'] if current_user and current_user.is_authenticated: for key in announcement.keys(): if key == 'admin' and current_user.admin: flash(announcement[key], 'info') if key == 'owner' and len(current_user.projects) != 0: flash(announcement[key], 'info') if key == 'user': flash(announcement[key], 'info') if app.config.get('CONTACT_EMAIL'): # pragma: no cover contact_email = app.config.get('CONTACT_EMAIL') else: contact_email = '*****@*****.**' if app.config.get('CONTACT_TWITTER'): # pragma: no cover contact_twitter = app.config.get('CONTACT_TWITTER') else: contact_twitter = 'PYBOSSA' # Available plugins plugins = plugin_manager.plugins # LDAP enabled ldap_enabled = app.config.get('LDAP_HOST', False) return dict( brand=app.config['BRAND'], title=app.config['TITLE'], logo=app.config['LOGO'], copyright=app.config['COPYRIGHT'], description=app.config['DESCRIPTION'], terms_of_use=app.config['TERMSOFUSE'], data_use=app.config['DATAUSE'], enforce_privacy=app.config['ENFORCE_PRIVACY'], # version=pybossa.__version__, current_user=current_user, show_cookies_warning=show_cookies_warning, contact_email=contact_email, contact_twitter=contact_twitter, upload_method=app.config['UPLOAD_METHOD'], news=news, notify_admin=notify_admin, plugins=plugins, ldap_enabled=ldap_enabled)