本文整理汇总了Python中rhodecode.lib.celerylib.run_task函数的典型用法代码示例。如果您正苦于以下问题:Python run_task函数的具体用法?Python run_task怎么用?Python run_task使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_task函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: reset_password
def reset_password(self, data):
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.lib import auth
user_email = data['email']
try:
try:
user = User.get_by_email(user_email)
new_passwd = auth.PasswordGenerator().gen_password(8,
auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
if user:
user.password = auth.get_crypt_password(new_passwd)
user.api_key = auth.generate_api_key(user.username)
Session().add(user)
Session().commit()
log.info('change password for %s' % user_email)
if new_passwd is None:
raise Exception('unable to generate new password')
except Exception:
log.error(traceback.format_exc())
Session().rollback()
run_task(tasks.send_email, user_email,
_('Your new password'),
_('Your new RhodeCode password:%s') % (new_passwd))
log.info('send new password mail to %s' % user_email)
except Exception:
log.error('Failed to update user password')
log.error(traceback.format_exc())
return True
开发者ID:greenboxindonesia,项目名称:rhodecode,代码行数:31,代码来源:user.py
示例2: send_password_link
def send_password_link(user_email):
try:
log = reset_user_password.get_logger()
except:
log = logging.getLogger(__name__)
from rhodecode.lib import auth
from rhodecode.model.db import User
try:
sa = get_session()
user = sa.query(User).filter(User.email == user_email).scalar()
if user:
link = url("reset_password_confirmation", key=user.api_key, qualified=True)
tmpl = """
Hello %s
We received a request to create a new password for your account.
You can generate it by clicking following URL:
%s
If you didn't request new password please ignore this email.
"""
run_task(send_email, user_email, "RhodeCode password reset link", tmpl % (user.short_contact, link))
log.info("send new password mail to %s", user_email)
except:
log.error("Failed to update user password")
log.error(traceback.format_exc())
return False
return True
开发者ID:pombredanne,项目名称:rhodecode,代码行数:35,代码来源:tasks.py
示例3: send_password_link
def send_password_link(user_email):
from rhodecode.model.notification import EmailNotificationModel
log = get_logger(send_password_link)
DBS = get_session()
try:
user = User.get_by_email(user_email)
if user:
log.debug('password reset user found %s' % user)
link = url('reset_password_confirmation', key=user.api_key,
qualified=True)
reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET
body = EmailNotificationModel().get_email_tmpl(reg_type,
**{'user':user.short_contact,
'reset_url':link})
log.debug('sending email')
run_task(send_email, user_email,
_("password reset link"), body)
log.info('send new password mail to %s' % user_email)
else:
log.debug("password reset email %s not found" % user_email)
except:
log.error(traceback.format_exc())
return False
return True
开发者ID:elfixit,项目名称:rhodecode,代码行数:27,代码来源:tasks.py
示例4: reset_password_link
def reset_password_link(self, data):
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.model.notification import EmailNotificationModel
user_email = data['email']
try:
user = User.get_by_email(user_email)
if user:
log.debug('password reset user found %s' % user)
link = url('reset_password_confirmation', key=user.api_key,
qualified=True)
reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET
body = EmailNotificationModel().get_email_tmpl(reg_type,
**{'user': user.short_contact,
'reset_url': link})
log.debug('sending email')
run_task(tasks.send_email, user_email,
_("Password reset link"), body, body)
log.info('send new password mail to %s' % user_email)
else:
log.debug("password reset email %s not found" % user_email)
except Exception:
log.error(traceback.format_exc())
return False
return True
开发者ID:greenboxindonesia,项目名称:rhodecode,代码行数:25,代码来源:user.py
示例5: reset_user_password
def reset_user_password(user_email):
try:
log = reset_user_password.get_logger()
except:
log = logging.getLogger(__name__)
from rhodecode.lib import auth
from rhodecode.model.db import User
try:
try:
sa = get_session()
user = sa.query(User).filter(User.email == user_email).scalar()
new_passwd = auth.PasswordGenerator().gen_password(8, auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
if user:
user.password = auth.get_crypt_password(new_passwd)
user.api_key = auth.generate_api_key(user.username)
sa.add(user)
sa.commit()
log.info("change password for %s", user_email)
if new_passwd is None:
raise Exception("unable to generate new password")
except:
log.error(traceback.format_exc())
sa.rollback()
run_task(send_email, user_email, "Your new RhodeCode password", "Your new RhodeCode password:%s" % (new_passwd))
log.info("send new password mail to %s", user_email)
except:
log.error("Failed to update user password")
log.error(traceback.format_exc())
return True
开发者ID:pombredanne,项目名称:rhodecode,代码行数:35,代码来源:tasks.py
示例6: reset_user_password
def reset_user_password(user_email):
from rhodecode.lib import auth
log = get_logger(reset_user_password)
DBS = get_session()
try:
try:
user = User.get_by_email(user_email)
new_passwd = auth.PasswordGenerator().gen_password(8,
auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
if user:
user.password = auth.get_crypt_password(new_passwd)
user.api_key = auth.generate_api_key(user.username)
DBS.add(user)
DBS.commit()
log.info('change password for %s' % user_email)
if new_passwd is None:
raise Exception('unable to generate new password')
except:
log.error(traceback.format_exc())
DBS.rollback()
run_task(send_email, user_email,
'Your new password',
'Your new RhodeCode password:%s' % (new_passwd))
log.info('send new password mail to %s' % user_email)
except:
log.error('Failed to update user password')
log.error(traceback.format_exc())
return True
开发者ID:elfixit,项目名称:rhodecode,代码行数:33,代码来源:tasks.py
示例7: create_fork
def create_fork(self, form_data, cur_user):
"""
Simple wrapper into executing celery task for fork creation
:param form_data:
:param cur_user:
"""
from rhodecode.lib.celerylib import tasks, run_task
run_task(tasks.create_repo_fork, form_data, cur_user)
开发者ID:greenboxindonesia,项目名称:rhodecode,代码行数:9,代码来源:repo.py
示例8: create_registration
def create_registration(self, form_data):
from rhodecode.lib.celerylib import tasks, run_task
try:
new_user = User()
for k, v in form_data.items():
if k != 'admin':
setattr(new_user, k, v)
self.sa.add(new_user)
self.sa.commit()
body = ('New user registration\n'
'username: %s\n'
'email: %s\n')
body = body % (form_data['username'], form_data['email'])
run_task(tasks.send_email, None,
_('[RhodeCode] New User registration'),
body)
except:
log.error(traceback.format_exc())
self.sa.rollback()
raise
开发者ID:lmamsen,项目名称:rhodecode,代码行数:22,代码来源:user.py
示例9: reset_password
def reset_password(self, data):
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.lib import auth
user_email = data["email"]
pre_db = True
try:
user = User.get_by_email(user_email)
new_passwd = auth.PasswordGenerator().gen_password(8, auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
if user:
user.password = auth.get_crypt_password(new_passwd)
user.api_key = auth.generate_api_key(user.username)
Session().add(user)
Session().commit()
log.info("change password for %s" % user_email)
if new_passwd is None:
raise Exception("unable to generate new password")
pre_db = False
run_task(
tasks.send_email,
user_email,
_("Your new password"),
_("Your new RhodeCode password:%s") % (new_passwd,),
)
log.info("send new password mail to %s" % user_email)
except Exception:
log.error("Failed to update user password")
log.error(traceback.format_exc())
if pre_db:
# we rollback only if local db stuff fails. If it goes into
# run_task, we're pass rollback state this wouldn't work then
Session().rollback()
return True
开发者ID:nzinfo,项目名称:rhodecode,代码行数:36,代码来源:user.py
示例10: redirect
category='error')
return redirect(url('admin_edit_setting', setting_id='hooks'))
if setting_id == 'email':
test_email = request.POST.get('test_email')
test_email_subj = 'RhodeCode TestEmail'
test_email_body = 'RhodeCode Email test'
test_email_html_body = EmailNotificationModel()\
.get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT,
body=test_email_body)
recipients = [test_email] if [test_email] else None
run_task(tasks.send_email, recipients, test_email_subj,
test_email_body, test_email_html_body)
h.flash(_('Email task created'), category='success')
return redirect(url('admin_settings'))
@HasPermissionAllDecorator('hg.admin')
def delete(self, setting_id):
"""DELETE /admin/settings/setting_id: Delete an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="DELETE" />
# Or using helpers:
# h.form(url('admin_setting', setting_id=ID),
# method='delete')
# url('admin_setting', setting_id=ID)
if setting_id == 'hooks':
hook_id = request.POST.get('hook_id')
开发者ID:elfixit,项目名称:rhodecode,代码行数:32,代码来源:settings.py
示例11: index
def index(self, repo_name):
e = request.environ
c.dbrepo = dbrepo = c.rhodecode_db_repo
c.following = self.scm_model.is_following_repo(repo_name,
self.rhodecode_user.user_id)
def url_generator(**kw):
return url('shortlog_home', repo_name=repo_name, size=10, **kw)
c.repo_changesets = RepoPage(c.rhodecode_repo, page=1,
items_per_page=10, url=url_generator)
if self.rhodecode_user.username == 'default':
#for default(anonymous) user we don't need to pass credentials
username = ''
password = ''
else:
username = str(self.rhodecode_user.username)
password = '@'
if e.get('wsgi.url_scheme') == 'https':
split_s = 'https://'
else:
split_s = 'http://'
qualified_uri = [split_s] + [url.current(qualified=True)\
.split(split_s)[-1]]
uri = u'%(proto)s%(user)s%(pass)s%(rest)s' \
% {'user': username,
'pass': password,
'proto': qualified_uri[0],
'rest': qualified_uri[1]}
c.clone_repo_url = uri
c.repo_tags = OrderedDict()
for name, hash in c.rhodecode_repo.tags.items()[:10]:
try:
c.repo_tags[name] = c.rhodecode_repo.get_changeset(hash)
except ChangesetError:
c.repo_tags[name] = EmptyChangeset(hash)
c.repo_branches = OrderedDict()
for name, hash in c.rhodecode_repo.branches.items()[:10]:
try:
c.repo_branches[name] = c.rhodecode_repo.get_changeset(hash)
except ChangesetError:
c.repo_branches[name] = EmptyChangeset(hash)
td = date.today() + timedelta(days=1)
td_1m = td - timedelta(days=calendar.mdays[td.month])
td_1y = td - timedelta(days=365)
ts_min_m = mktime(td_1m.timetuple())
ts_min_y = mktime(td_1y.timetuple())
ts_max_y = mktime(td.timetuple())
if dbrepo.enable_statistics:
c.no_data_msg = _('No data loaded yet')
run_task(get_commits_stats, c.dbrepo.repo_name, ts_min_y, ts_max_y)
else:
c.no_data_msg = _('Statistics are disabled for this repository')
c.ts_min = ts_min_m
c.ts_max = ts_max_y
stats = self.sa.query(Statistics)\
.filter(Statistics.repository == dbrepo)\
.scalar()
c.stats_percentage = 0
if stats and stats.languages:
c.no_data = False is dbrepo.enable_statistics
lang_stats_d = json.loads(stats.languages)
c.commit_data = stats.commit_activity
c.overview_data = stats.commit_activity_combined
lang_stats = [(x, {"count": y,
"desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
for x, y in lang_stats_d.items()]
c.trending_languages = json.dumps(OrderedDict(
sorted(lang_stats, reverse=True,
key=lambda k: k[1])[:10]
)
)
last_rev = stats.stat_on_revision
c.repo_last_rev = c.rhodecode_repo.count() - 1 \
if c.rhodecode_repo.revisions else 0
if last_rev == 0 or c.repo_last_rev == 0:
pass
else:
c.stats_percentage = '%.2f' % ((float((last_rev)) /
c.repo_last_rev) * 100)
else:
c.commit_data = json.dumps({})
c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10]])
c.trending_languages = json.dumps({})
c.no_data = True
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:rhodecode,代码行数:101,代码来源:summary.py
示例12: update
def update(self, setting_id):
"""PUT /admin/settings/setting_id: Update an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="PUT" />
# Or using helpers:
# h.form(url('admin_setting', setting_id=ID),
# method='put')
# url('admin_setting', setting_id=ID)
if setting_id == 'mapping':
rm_obsolete = request.POST.get('destroy', False)
invalidate_cache = request.POST.get('invalidate', False)
log.debug('rescanning repo location with destroy obsolete=%s'
% (rm_obsolete,))
if invalidate_cache:
log.debug('invalidating all repositories cache')
for repo in Repository.get_all():
ScmModel().mark_for_invalidation(repo.repo_name)
filesystem_repos = ScmModel().repo_scan()
added, removed = repo2db_mapper(filesystem_repos, rm_obsolete)
_repr = lambda l: ', '.join(map(safe_unicode, l)) or '-'
h.flash(_('Repositories successfully '
'rescanned added: %s ; removed: %s') %
(_repr(added), _repr(removed)),
category='success')
if setting_id == 'whoosh':
repo_location = self._get_hg_ui_settings()['paths_root_path']
full_index = request.POST.get('full_index', False)
run_task(tasks.whoosh_index, repo_location, full_index)
h.flash(_('Whoosh reindex task scheduled'), category='success')
if setting_id == 'global':
application_form = ApplicationSettingsForm()()
try:
form_result = application_form.to_python(dict(request.POST))
except formencode.Invalid, errors:
return htmlfill.render(
render('admin/settings/settings.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8"
)
try:
sett1 = RhodeCodeSetting.get_by_name_or_create('title')
sett1.app_settings_value = form_result['rhodecode_title']
Session().add(sett1)
sett2 = RhodeCodeSetting.get_by_name_or_create('realm')
sett2.app_settings_value = form_result['rhodecode_realm']
Session().add(sett2)
sett3 = RhodeCodeSetting.get_by_name_or_create('ga_code')
sett3.app_settings_value = form_result['rhodecode_ga_code']
Session().add(sett3)
Session().commit()
set_rhodecode_config(config)
h.flash(_('Updated application settings'), category='success')
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during updating '
'application settings'),
category='error')
开发者ID:adamscieszko,项目名称:rhodecode,代码行数:70,代码来源:settings.py
示例13: reset_password
def reset_password(self, data):
from rhodecode.lib.celerylib import tasks, run_task
run_task(tasks.reset_user_password, data['email'])
开发者ID:yujiro,项目名称:rhodecode,代码行数:3,代码来源:user.py
示例14: create_fork
def create_fork(self, form_data, cur_user):
from rhodecode.lib.celerylib import tasks, run_task
run_task(tasks.create_repo_fork, form_data, cur_user)
开发者ID:pombredanne,项目名称:rhodecode,代码行数:4,代码来源:repo.py
示例15: create
def create(self, created_by, subject, body, recipients=None,
type_=Notification.TYPE_MESSAGE, with_email=True,
email_kwargs={}):
"""
Creates notification of given type
:param created_by: int, str or User instance. User who created this
notification
:param subject:
:param body:
:param recipients: list of int, str or User objects, when None
is given send to all admins
:param type_: type of notification
:param with_email: send email with this notification
:param email_kwargs: additional dict to pass as args to email template
"""
from rhodecode.lib.celerylib import tasks, run_task
if recipients and not getattr(recipients, '__iter__', False):
raise Exception('recipients must be a list of iterable')
created_by_obj = self.__get_user(created_by)
if recipients:
recipients_objs = []
for u in recipients:
obj = self.__get_user(u)
if obj:
recipients_objs.append(obj)
recipients_objs = set(recipients_objs)
log.debug('sending notifications %s to %s' % (
type_, recipients_objs)
)
else:
# empty recipients means to all admins
recipients_objs = User.query().filter(User.admin == True).all()
log.debug('sending notifications %s to admins: %s' % (
type_, recipients_objs)
)
notif = Notification.create(
created_by=created_by_obj, subject=subject,
body=body, recipients=recipients_objs, type_=type_
)
if with_email is False:
return notif
# send email with notification
for rec in recipients_objs:
email_subject = NotificationModel().make_description(notif, False)
type_ = type_
email_body = body
kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)}
kwargs.update(email_kwargs)
email_body_html = EmailNotificationModel()\
.get_email_tmpl(type_, **kwargs)
run_task(tasks.send_email, rec.email, email_subject, email_body,
email_body_html)
return notif
开发者ID:elfixit,项目名称:rhodecode,代码行数:62,代码来源:notification.py
示例16: update
def update(self, setting_id):
"""PUT /admin/settings/setting_id: Update an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="PUT" />
# Or using helpers:
# h.form(url('admin_setting', setting_id=ID),
# method='put')
# url('admin_setting', setting_id=ID)
if setting_id == 'mapping':
rm_obsolete = request.POST.get('destroy', False)
log.debug('Rescanning directories with destroy=%s' % rm_obsolete)
initial = ScmModel().repo_scan()
log.debug('invalidating all repositories')
for repo_name in initial.keys():
invalidate_cache('get_repo_cached_%s' % repo_name)
added, removed = repo2db_mapper(initial, rm_obsolete)
h.flash(_('Repositories successfully'
' rescanned added: %s,removed: %s') % (added, removed),
category='success')
if setting_id == 'whoosh':
repo_location = self.get_hg_ui_settings()['paths_root_path']
full_index = request.POST.get('full_index', False)
run_task(tasks.whoosh_index, repo_location, full_index)
h.flash(_('Whoosh reindex task scheduled'), category='success')
if setting_id == 'global':
application_form = ApplicationSettingsForm()()
try:
form_result = application_form.to_python(dict(request.POST))
try:
hgsettings1 = RhodeCodeSetting.get_by_name('title')
hgsettings1.app_settings_value = \
form_result['rhodecode_title']
hgsettings2 = RhodeCodeSetting.get_by_name('realm')
hgsettings2.app_settings_value = \
form_result['rhodecode_realm']
hgsettings3 = RhodeCodeSetting.get_by_name('ga_code')
hgsettings3.app_settings_value = \
form_result['rhodecode_ga_code']
self.sa.add(hgsettings1)
self.sa.add(hgsettings2)
self.sa.add(hgsettings3)
self.sa.commit()
set_rhodecode_config(config)
h.flash(_('Updated application settings'),
category='success')
except Exception:
log.error(traceback.format_exc())
h.flash(_('error occurred during updating '
'application settings'),
category='error')
self.sa.rollback()
except formencode.Invalid, errors:
return htmlfill.render(
render('admin/settings/settings.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
开发者ID:elfixit,项目名称:rhodecode,代码行数:70,代码来源:settings.py
示例17: reset_password_link
def reset_password_link(self, data):
from rhodecode.lib.celerylib import tasks, run_task
run_task(tasks.send_password_link, data['email'])
开发者ID:yujiro,项目名称:rhodecode,代码行数:3,代码来源:user.py
示例18: get_commits_stats
#.........这里部分代码省略.........
last_rev, last_rev + parse_limit)
)
for cs in repo[last_rev:last_rev + parse_limit]:
log.debug('parsing %s' % cs)
last_cs = cs # remember last parsed changeset
k = lmktime([cs.date.timetuple()[0], cs.date.timetuple()[1],
cs.date.timetuple()[2], 0, 0, 0, 0, 0, 0])
if akc(cs.author) in co_day_auth_aggr:
try:
l = [timegetter(x) for x in
co_day_auth_aggr[akc(cs.author)]['data']]
time_pos = l.index(k)
except ValueError:
time_pos = False
if time_pos >= 0 and time_pos is not False:
datadict = \
co_day_auth_aggr[akc(cs.author)]['data'][time_pos]
datadict["commits"] += 1
datadict["added"] += len(cs.added)
datadict["changed"] += len(cs.changed)
datadict["removed"] += len(cs.removed)
else:
if k >= ts_min_y and k <= ts_max_y or skip_date_limit:
datadict = {"time": k,
"commits": 1,
"added": len(cs.added),
"changed": len(cs.changed),
"removed": len(cs.removed),
}
co_day_auth_aggr[akc(cs.author)]['data']\
.append(datadict)
else:
if k >= ts_min_y and k <= ts_max_y or skip_date_limit:
co_day_auth_aggr[akc(cs.author)] = {
"label": akc(cs.author),
"data": [{"time":k,
"commits":1,
"added":len(cs.added),
"changed":len(cs.changed),
"removed":len(cs.removed),
}],
"schema": ["commits"],
}
#gather all data by day
if k in commits_by_day_aggregate:
commits_by_day_aggregate[k] += 1
else:
commits_by_day_aggregate[k] = 1
overview_data = sorted(commits_by_day_aggregate.items(),
key=itemgetter(0))
if not co_day_auth_aggr:
co_day_auth_aggr[akc(repo.contact)] = {
"label": akc(repo.contact),
"data": [0, 1],
"schema": ["commits"],
}
stats = cur_stats if cur_stats else Statistics()
stats.commit_activity = json.dumps(co_day_auth_aggr)
stats.commit_activity_combined = json.dumps(overview_data)
log.debug('last revison %s' % last_rev)
leftovers = len(repo.revisions[last_rev:])
log.debug('revisions to parse %s' % leftovers)
if last_rev == 0 or leftovers < parse_limit:
log.debug('getting code trending stats')
stats.languages = json.dumps(__get_codes_stats(repo_name))
try:
stats.repository = dbrepo
stats.stat_on_revision = last_cs.revision if last_cs else 0
DBS.add(stats)
DBS.commit()
except:
log.error(traceback.format_exc())
DBS.rollback()
lock.release()
return False
# final release
lock.release()
# execute another task if celery is enabled
if len(repo.revisions) > 1 and CELERY_ON:
run_task(get_commits_stats, repo_name, ts_min_y, ts_max_y)
return True
except LockHeld:
log.info('LockHeld')
return 'Task with key %s already running' % lockkey
开发者ID:elfixit,项目名称:rhodecode,代码行数:101,代码来源:tasks.py
示例19: index
def index(self, repo_name):
c.dbrepo = dbrepo = c.rhodecode_db_repo
c.following = self.scm_model.is_following_repo(repo_name,
self.rhodecode_user.user_id)
def url_generator(**kw):
return url('shortlog_home', repo_name=repo_name, size=10, **kw)
c.repo_changesets = RepoPage(c.rhodecode_repo, page=1,
items_per_page=10, url=url_generator)
if self.rhodecode_user.username == 'default':
# for default(anonymous) user we don't need to pass credentials
username = ''
password = ''
else:
username = str(self.rhodecode_user.username)
password = '@'
parsed_url = urlparse(url.current(qualified=True))
default_clone_uri = '{scheme}://{user}{pass}{netloc}{path}'
uri_tmpl = config.get('clone_uri', default_clone_uri)
uri_tmpl = uri_tmpl.replace('{', '%(').replace('}', ')s')
decoded_path = safe_unicode(urllib.unquote(parsed_url.path))
uri_dict = {
'user': username,
'pass': password,
'scheme': parsed_url.scheme,
'netloc': parsed_url.netloc,
'path': decoded_path
}
uri = uri_tmpl % uri_dict
# generate another clone url by id
uri_dict.update(
{'path': decoded_path.replace(repo_name, '_%s' % c.dbrepo.repo_id)}
)
uri_id = uri_tmpl % uri_dict
c.clone_repo_url = uri
c.clone_repo_url_id = uri_id
c.repo_tags = OrderedDict()
for name, hash_ in c.rhodecode_repo.tags.items()[:10]:
try:
c.repo_tags[name] = c.rhodecode_repo.get_changeset(hash_)
except ChangesetError:
c.repo_tags[name] = EmptyChangeset(hash_)
c.repo_branches = OrderedDict()
for name, hash_ in c.rhodecode_repo.branches.items()[:10]:
try:
c.repo_branches[name] = c.rhodecode_repo.get_changeset(hash_)
except ChangesetError:
c.repo_branches[name] = EmptyChangeset(hash_)
td = date.today() + timedelta(days=1)
td_1m = td - timedelta(days=calendar.mdays[td.month])
td_1y = td - timedelta(days=365)
ts_min_m = mktime(td_1m.timetuple())
ts_min_y = mktime(td_1y.timetuple())
ts_max_y = mktime(td.timetuple())
if dbrepo.enable_statistics:
c.show_stats = True
c.no_data_msg = _('No data loaded yet')
run_task(get_commits_stats, c.dbrepo.repo_name, ts_min_y, ts_max_y)
else:
c.show_stats = False
c.no_data_msg = _('Statistics are disabled for this repository')
c.ts_min = ts_min_m
c.ts_max = ts_max_y
stats = self.sa.query(Statistics)\
.filter(Statistics.repository == dbrepo)\
.scalar()
c.stats_percentage = 0
if stats and stats.languages:
c.no_data = False is dbrepo.enable_statistics
lang_stats_d = json.loads(stats.languages)
c.commit_data = stats.commit_activity
c.overview_data = stats.commit_activity_combined
lang_stats = ((x, {"count": y,
"desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
for x, y in lang_stats_d.items())
c.trending_languages = json.dumps(
sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
)
last_rev = stats.stat_on_revision + 1
c.repo_last_rev = c.rhodecode_repo.count()\
if c.rhodecode_repo.revisions else 0
if last_rev == 0 or c.repo_last_rev == 0:
pass
else:
#.........这里部分代码省略.........
开发者ID:elfixit,项目名称:rhodecode,代码行数:101,代码来源:summary.py
示例20: create
def create(self, created_by, subject, body, recipients=None,
type_=Notification.TYPE_MESSAGE, with_email=True,
email_kwargs={}, email_subject=None):
"""
Creates notification of given type
:param created_by: int, str or User instance. User who created this
notification
:param subject:
:param body:
:param recipients: list of int, str or User objects, when None
is given send to all admins
:param type_: type of notification
:param with_email: send email with this notification
:param email_kwargs: additional dict to pass as args to email template
:param email_subject: use given subject as email subject
"""
from rhodecode.lib.celerylib import tasks, run_task
if recipients and not getattr(recipients, '__iter__', False):
raise Exception('recipients must be a list or iterable')
created_by_obj = self._get_user(created_by)
if recipients:
recipients_objs = []
for u in recipients:
obj = self._get_user(u)
if obj:
recipients_objs.append(obj)
else:
# TODO: inform user that requested operation couldn't be completed
log.error('cannot email unknown user %r', u)
recipients_objs = set(recipients_objs)
log.debug('sending notifications %s to %s' % (
type_, recipients_objs)
)
else:
# empty recipients means to all admins
recipients_objs = User.query().filter(User.admin == True).all()
log.debug('sending notifications %s to admins: %s' % (
type_, recipients_objs)
)
# TODO: inform user who are notified
notif = Notification.create(
created_by=created_by_obj, subject=subject,
body=body, recipients=recipients_objs, type_=type_
)
if not with_email:
return notif
#don't send email to person who created this comment
rec_objs = set(recipients_objs).difference(set([created_by_obj]))
# send email with notification to all other participants
for rec in rec_objs:
if not email_subject:
email_subject = NotificationModel()\
.make_description(notif, show_age=False)
type_ = type_
email_body = None # we set body to none, we just send HTML emails
## this is passed into template
kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)}
kwargs.update(email_kwargs)
email_body_html = EmailNotificationModel()\
.get_email_tmpl(type_, **kwargs)
run_task(tasks.send_email, rec.email, email_subject, email_body,
email_body_html)
return notif
开发者ID:adamscieszko,项目名称:rhodecode,代码行数:73,代码来源:notification.py
注:本文中的rhodecode.lib.celerylib.run_task函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论