本文整理汇总了Python中mediadrop.model.User.by_user_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_user_name方法的具体用法?Python User.by_user_name怎么用?Python User.by_user_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediadrop.model.User
的用法示例。
在下文中一共展示了User.by_user_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_new_user
# 需要导入模块: from mediadrop.model import User [as 别名]
# 或者: from mediadrop.model.User import by_user_name [as 别名]
def create_new_user(username, config):
from mediadrop.model import DBSession, User, fetch_row, Group
user = User.by_user_name(username)
if user is None:
try:
print "MIDDLEWARE"
print config
l = ldap.initialize(config['ldap_url'])
l.simple_bind_s(config['ldap_binddn'], config['ldap_pw'])
filter = '(samaccountname=%s)' % username
r = l.search_s(config['ldap_base'],ldap.SCOPE_SUBTREE, filter, ['displayname', 'mail'])
l.unbind_s()
user_attrs = {}
for dn, entry in r:
for attr, v in entry.iteritems():
user_attrs[attr] = v[0]
except ldap.LDAPError:
l.unbind_s()
new_user = fetch_row(User, "new")
new_user.display_name = user_attrs['displayName']
new_user.email_address = user_attrs['mail']
new_user.user_name = username
query = DBSession.query(Group).filter(Group.group_name.in_(['authenticated']))
new_user.groups = list(query.all())
DBSession.add(new_user)
DBSession.commit()
示例2: comment
# 需要导入模块: from mediadrop.model import User [as 别名]
# 或者: from mediadrop.model.User import by_user_name [as 别名]
def comment(self, slug, body='', **kwargs):
"""Post a comment from :class:`~mediadrop.forms.comments.PostCommentForm`.
:param slug: The media :attr:`~mediadrop.model.media.Media.slug`
:returns: Redirect to :meth:`view` page for media.
"""
def result(success, message=None, comment=None):
if request.is_xhr:
result = dict(success=success, message=message)
if comment:
result['comment'] = render('comments/_list.html',
{'comment_to_render': comment},
method='xhtml')
return result
elif success:
return redirect(action='view')
else:
return self.view(slug, name=name, email=email, body=body,
**kwargs)
if request.settings['comments_engine'] != 'builtin':
abort(404)
akismet_key = request.settings['akismet_key']
if akismet_key:
akismet = Akismet(agent=USER_AGENT)
akismet.key = akismet_key
akismet.blog_url = request.settings['akismet_url'] or \
url_for('/', qualified=True)
akismet.verify_key()
data = {'comment_author': name.encode('utf-8'),
'user_ip': request.environ.get('REMOTE_ADDR'),
'user_agent': request.environ.get('HTTP_USER_AGENT', ''),
'referrer': request.environ.get('HTTP_REFERER', 'unknown'),
'HTTP_ACCEPT': request.environ.get('HTTP_ACCEPT')}
if akismet.comment_check(body.encode('utf-8'), data):
return result(False, _(u'Your comment has been rejected.'))
media = fetch_row(Media, slug=slug)
request.perm.assert_permission(u'view', media.resource)
c = Comment()
#name = filter_vulgarity(name)
#c.author = AuthorWithIP(name, email, request.environ['REMOTE_ADDR'])
user = User.by_user_name(request.environ['HTTP_REMOTE_USER'])
c.author = AuthorWithIP(user.display_name, None, request.environ['REMOTE_ADDR'])
c.subject = 'Re: %s' % media.title
c.body = filter_vulgarity(body)
require_review = request.settings['req_comment_approval']
if not require_review:
c.reviewed = True
c.publishable = True
media.comments.append(c)
DBSession.flush()
send_comment_notification(media, c)
if require_review:
message = _('Thank you for your comment! We will post it just as '
'soon as a moderator approves it.')
return result(True, message=message)
else:
return result(True, comment=c)