本文整理汇总了Python中pybossa.pro_features.ProFeatureHandler.only_for_pro方法的典型用法代码示例。如果您正苦于以下问题:Python ProFeatureHandler.only_for_pro方法的具体用法?Python ProFeatureHandler.only_for_pro怎么用?Python ProFeatureHandler.only_for_pro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybossa.pro_features.ProFeatureHandler
的用法示例。
在下文中一共展示了ProFeatureHandler.only_for_pro方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_weekly_stats_update_projects
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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: notify_blog_users
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例3: get_export_task_jobs
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例4: get_autoimport_jobs
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例5: get_export_task_jobs
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例6: get_autoimport_jobs
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例7: test_only_for_pro_returns_False_if_feature_is_for_everyone
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
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
示例8: test_only_for_pro_returns_True_if_feature_is_only_for_pro
# 需要导入模块: from pybossa.pro_features import ProFeatureHandler [as 别名]
# 或者: from pybossa.pro_features.ProFeatureHandler import only_for_pro [as 别名]
def test_only_for_pro_returns_True_if_feature_is_only_for_pro(self):
pro_enabled_handler = ProFeatureHandler(self.config_enabled)
assert pro_enabled_handler.only_for_pro('auditlog') is True