本文整理汇总了Python中pybossa.pro_features.ProFeatureHandler类的典型用法代码示例。如果您正苦于以下问题:Python ProFeatureHandler类的具体用法?Python ProFeatureHandler怎么用?Python ProFeatureHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProFeatureHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_weekly_stats_update_projects
def get_weekly_stats_update_projects():
"""Return email jobs with weekly stats update for project owner."""
from sqlalchemy.sql import text
from pybossa.core import db
from pybossa.pro_features import ProFeatureHandler
feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
only_pros = feature_handler.only_for_pro('project_weekly_report')
only_pros_sql = 'AND "user".pro=true' if only_pros else ''
send_emails_date = current_app.config.get('WEEKLY_UPDATE_STATS')
today = datetime.today().strftime('%A').lower()
timeout = current_app.config.get('TIMEOUT')
if today.lower() == send_emails_date.lower():
sql = text('''
SELECT project.id
FROM project, "user", task
WHERE "user".id=project.owner_id %s
AND "user".subscribed=true
AND task.project_id=project.id
AND task.state!='completed'
UNION
SELECT project.id
FROM project
WHERE project.featured=true;
''' % only_pros_sql)
results = db.slave_session.execute(sql)
for row in results:
job = dict(name=send_weekly_stats_project,
args=[row.id],
kwargs={},
timeout=timeout,
queue='low')
yield job
示例2: test_better_stats_enabled_for_admin_user_always_returns_True
def test_better_stats_enabled_for_admin_user_always_returns_True(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.better_stats_enabled_for(self.admin, self.no_pro) is True
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.better_stats_enabled_for(self.admin, self.no_pro) is True
示例3: test_webhooks_enabled_for_admin_always_returns_True
def test_webhooks_enabled_for_admin_always_returns_True(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.webhooks_enabled_for(self.admin) is True
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.webhooks_enabled_for(self.admin) is True
示例4: test_autoimporter_enabled_for_admin_always_returns_True
def test_autoimporter_enabled_for_admin_always_returns_True(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.autoimporter_enabled_for(self.admin) is True
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.autoimporter_enabled_for(self.admin) is True
示例5: test_auditlog_enabled_for_pro_always_returns_True
def test_auditlog_enabled_for_pro_always_returns_True(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.auditlog_enabled_for(self.pro) is True
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.auditlog_enabled_for(self.pro) is True
示例6: notify_blog_users
def notify_blog_users(blog_id, project_id, queue='high'):
"""Send email with new blog post."""
from sqlalchemy.sql import text
from pybossa.core import db
from pybossa.core import blog_repo
from pybossa.pro_features import ProFeatureHandler
blog = blog_repo.get(blog_id)
users = 0
feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
only_pros = feature_handler.only_for_pro('notify_blog_updates')
timeout = current_app.config.get('TIMEOUT')
if blog.project.featured or (blog.project.owner.pro or not only_pros):
sql = text('''
SELECT email_addr, name from "user", task_run
WHERE task_run.project_id=:project_id
AND task_run.user_id="user".id
AND "user".subscribed=true
AND "user".restrict=false
GROUP BY email_addr, name, subscribed;
''')
results = db.slave_session.execute(sql, dict(project_id=project_id))
for row in results:
subject = "Project Update: %s by %s" % (blog.project.name,
blog.project.owner.fullname)
body = render_template('/account/email/blogupdate.md',
user_name=row.name,
blog=blog,
config=current_app.config)
html = render_template('/account/email/blogupdate.html',
user_name=row.name,
blog=blog,
config=current_app.config)
mail_dict = dict(recipients=[row.email_addr],
subject=subject,
body=body,
html=html)
job = dict(name=send_mail,
args=[mail_dict],
kwargs={},
timeout=timeout,
queue=queue)
enqueue_job(job)
users += 1
msg = "%s users notified by email" % users
return msg
示例7: get_export_task_jobs
def get_export_task_jobs(queue):
"""Export tasks to zip."""
from pybossa.core import project_repo
import pybossa.cache.projects as cached_projects
from pybossa.pro_features import ProFeatureHandler
feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES"))
if feature_handler.only_for_pro("updated_exports"):
if queue == "high":
projects = cached_projects.get_from_pro_user()
else:
projects = (p.dictize() for p in project_repo.get_all() if p.owner.pro is False)
else:
projects = (p.dictize() for p in project_repo.get_all())
for project in projects:
project_id = project.get("id")
job = dict(name=project_export, args=[project_id], kwargs={}, timeout=(10 * MINUTE), queue=queue)
yield job
示例8: get_autoimport_jobs
def get_autoimport_jobs(queue='low'):
"""Get autoimport jobs."""
from pybossa.core import project_repo
import pybossa.cache.projects as cached_projects
from pybossa.pro_features import ProFeatureHandler
feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
timeout = current_app.config.get('TIMEOUT')
if feature_handler.only_for_pro('autoimporter'):
projects = cached_projects.get_from_pro_user()
else:
projects = (p.dictize() for p in project_repo.get_all())
for project_dict in projects:
project = project_repo.get(project_dict['id'])
if project.has_autoimporter():
job = dict(name=import_tasks,
args=[project.id, True],
kwargs=project.get_autoimporter(),
timeout=timeout,
queue=queue)
yield job
示例9: get_export_task_jobs
def get_export_task_jobs(queue):
"""Export tasks to zip."""
from pybossa.core import project_repo
import pybossa.cache.projects as cached_projects
from pybossa.pro_features import ProFeatureHandler
feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
timeout = current_app.config.get('TIMEOUT')
if feature_handler.only_for_pro('updated_exports'):
if queue == 'high':
projects = cached_projects.get_from_pro_user()
else:
projects = (p.dictize() for p in project_repo.filter_by(published=True)
if p.owner.pro is False)
else:
projects = (p.dictize() for p in project_repo.filter_by(published=True))
for project in projects:
project_id = project.get('id')
job = dict(name=project_export,
args=[project_id], kwargs={},
timeout=timeout,
queue=queue)
yield job
示例10: get_autoimport_jobs
def get_autoimport_jobs(queue="low"):
"""Get autoimport jobs."""
from pybossa.core import project_repo
import pybossa.cache.projects as cached_projects
from pybossa.pro_features import ProFeatureHandler
feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES"))
if feature_handler.only_for_pro("autoimporter"):
projects = cached_projects.get_from_pro_user()
else:
projects = (p.dictize() for p in project_repo.get_all())
for project_dict in projects:
project = project_repo.get(project_dict["id"])
if project.has_autoimporter():
job = dict(
name=import_tasks,
args=[project.id],
kwargs=project.get_autoimporter(),
timeout=IMPORT_TASKS_TIMEOUT,
queue=queue,
)
yield job
示例11: test_better_stats_enabled_for_pro_owner_always_returns_True
def test_better_stats_enabled_for_pro_owner_always_returns_True(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.better_stats_enabled_for(self.no_pro, self.pro) is True
assert pro_enabled_handler.better_stats_enabled_for(self.anonymous, self.pro) is True
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.better_stats_enabled_for(self.no_pro, self.pro) is True
assert pro_disabled_handler.better_stats_enabled_for(self.anonymous, self.pro) is True
示例12: test_only_for_pro_returns_False_if_feature_is_for_everyone
def test_only_for_pro_returns_False_if_feature_is_for_everyone(self):
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.only_for_pro('auditlog') is False
示例13: test_autoimporter_enabled_for_non_pro_returns_False_if_enabled
def test_autoimporter_enabled_for_non_pro_returns_False_if_enabled(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.autoimporter_enabled_for(self.no_pro) is False
示例14: test_auditlog_enabled_for_non_pro_returns_True_if_disabled
def test_auditlog_enabled_for_non_pro_returns_True_if_disabled(self):
pro_disabled_handler = ProFeatureHandler(self.config_disabled)
assert pro_disabled_handler.auditlog_enabled_for(self.no_pro) is True
示例15: test_webhooks_enabled_for_non_pro_returns_False_if_enabled
def test_webhooks_enabled_for_non_pro_returns_False_if_enabled(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.webhooks_enabled_for(self.no_pro) is False