本文整理汇总了Python中fas.model.Groups.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Groups.by_name方法的具体用法?Python Groups.by_name怎么用?Python Groups.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fas.model.Groups
的用法示例。
在下文中一共展示了Groups.by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def view(self, groupname, order_by='username'):
'''View group'''
sort_map = { 'username': 'people_1.username',
'creation': 'person_roles_creation',
'approval': 'person_roles_approval',
'role_status': 'person_roles_role_status',
'role_type': 'person_roles_role_type',
'sponsor': 'people_2.username',
}
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if not can_view_group(person, group):
turbogears.flash(_("You cannot view '%s'") % group.name)
turbogears.redirect('/group/list')
return dict()
# Also return information on who is not sponsored
unsponsored = PersonRoles.query.join('group').join('member',
aliased=True).outerjoin('sponsor', aliased=True).filter(
and_(Groups.name==groupname,
PersonRoles.role_status=='unapproved')).order_by(sort_map[order_by])
unsponsored.json_props = {'PersonRoles': ['member']}
members = PersonRoles.query.join('group').join('member', aliased=True).filter(
People.username.like('%')
).outerjoin('sponsor', aliased=True).filter(
Groups.name==groupname,
).order_by(sort_map[order_by])
return dict(group=group, sponsor_queue=unsponsored,
members=list(members))
示例2: invite
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def invite(self, groupname, language):
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
person = person.filter_private()
subject = _('Invitation to join the Fedora Team!', language)
text = _('''
%(fullname)s <%(user)[email protected]%(hostname)s> has invited you to join the Fedora
Project! We are a community of users and developers who produce a
complete operating system from entirely free and open source software
(FOSS). %(fullname)s thinks that you have knowledge and skills
that make you a great fit for the Fedora community, and that you might
be interested in contributing.
How could you team up with the Fedora community to use and develop your
skills? Check out http://fedoraproject.org/join-fedora for some ideas.
Our community is more than just software developers -- we also have a
place for you whether you're an artist, a web site builder, a writer, or
a people person. You'll grow and learn as you work on a team with other
very smart and talented people.
Fedora and FOSS are changing the world -- come be a part of it!'''
% {'fullname': person.human_name,
'user': person.username,
'hostname': config.get('email_host')}, language)
return dict(person=person, group=group, invite_subject=subject,
invite_text=text, selected_language=language)
示例3: invite
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def invite(self, groupname):
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
person = person.filter_private()
return dict(person=person, group=group)
示例4: sendinvite
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def sendinvite(self, groupname, target):
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if is_approved(person, group):
invite_subject = _('Come join The Fedora Project!')
invite_text = _('''
%(user)s <%(email)s> has invited you to join the Fedora
Project! We are a community of users and developers who produce a
complete operating system from entirely free and open source software
(FOSS). %(user)s thinks that you have knowledge and skills
that make you a great fit for the Fedora community, and that you might
be interested in contributing.
How could you team up with the Fedora community to use and develop your
skills? Check out http://fedoraproject.org/join-fedora for some ideas.
Our community is more than just software developers -- we also have a
place for you whether you're an artist, a web site builder, a writer, or
a people person. You'll grow and learn as you work on a team with other
very smart and talented people.
Fedora and FOSS are changing the world -- come be a part of it!''') % \
{'user': person.username, 'email': person.email}
send_mail(target, invite_subject, invite_text)
turbogears.flash(_('Message sent to: %s') % target)
turbogears.redirect('/group/view/%s' % group.name)
else:
turbogears.flash(_("You are not in the '%s' group.") % group.name)
person = person.filter_private()
return dict(target=target, person=person, group=group)
示例5: members
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def members(self, groupname, search=u'a*', role_type=None,
order_by='username'):
'''View group'''
sort_map = { 'username': 'people_1.username',
'creation': 'person_roles_creation',
'approval': 'person_roles_approval',
'role_status': 'person_roles_role_status',
'role_type': 'person_roles_role_type',
'sponsor': 'people_2.username',
}
if not isinstance(search, unicode) and isinstance(search, basestring):
search = unicode(search, 'utf-8', 'replace')
re_search = search.translate({ord(u'*'): ur'%'}).lower()
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if not can_view_group(person, group):
turbogears.flash(_("You cannot view '%s'") % group.name)
turbogears.redirect('/group/list')
return dict()
# return all members of this group that fit the search criteria
members = PersonRoles.query.join('group').join('member', aliased=True).filter(
People.username.like(re_search)
).outerjoin('sponsor', aliased=True).filter(
Groups.name==groupname,
).order_by(sort_map[order_by])
if role_type:
members = members.filter(PersonRoles.role_type==role_type)
group.json_props = {'PersonRoles': ['member']}
return dict(group=group, members=members, search=search)
示例6: save
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def save(self, groupname, display_name, owner, group_type,
needs_sponsor=0, user_can_remove=1, prerequisite='',
url='', mailing_list='', mailing_list_url='', invite_only=0,
irc_channel='', irc_network='', joinmsg='', apply_rules="None"):
'''Edit a group'''
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
changed = []
#TODO: check any mandatory fields
if not group_type:
turbogears.flash(_("Group type cannot by empty!"))
turbogears.redirect('/group/edit/%s' % group.name)
if not can_edit_group(person, group):
turbogears.flash(_("You cannot edit '%s'.") % group.name)
turbogears.redirect('/group/view/%s' % group.name)
else:
owner = People.by_username(owner)
if prerequisite:
prerequisite = Groups.by_name(prerequisite)
try:
for field, _validator in GroupSave().fields.items():
if field in ['groupname']:
continue
if getattr(group, field) != locals()[field]:
setattr(group, field, locals()[field])
changed.append(field)
session.flush()
except:
turbogears.flash(_('The group details could not be saved.'))
else:
Log(author_id=person.id, description='%s edited group %s' %
(person.username, group.name))
fas.fedmsgshim.send_message(topic="group.update", msg={
'agent': person.username,
'group': group.name,
'fields': changed,
})
turbogears.flash(_('The group details have been saved.'))
turbogears.redirect('/group/view/%s' % group.name)
return dict(group=group)
示例7: group_by_name
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def group_by_name(self, groupname):
try:
group = Groups.by_name(groupname)
group.json_props = {
'Groups': ('approved_roles', 'unapproved_roles')}
return dict(success=True, group=group)
except InvalidRequestError:
return dict(success=False)
示例8: save
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def save(self, groupname, display_name, owner, group_type,
needs_sponsor=0, user_can_remove=1, prerequisite='',
url='', mailing_list='', mailing_list_url='', invite_only=0,
irc_channel='', irc_network='', joinmsg='', apply_rules="None"):
'''Edit a group'''
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if not can_edit_group(person, group):
turbogears.flash(_("You cannot edit '%s'.") % group.name)
turbogears.redirect('/group/view/%s' % group.name)
else:
try:
owner = People.by_username(owner)
group.display_name = display_name
group.owner = owner
group.group_type = group_type
group.needs_sponsor = bool(needs_sponsor)
group.user_can_remove = bool(user_can_remove)
if prerequisite:
prerequisite = Groups.by_name(prerequisite)
group.prerequisite = prerequisite
else:
group.prerequisite = None
group.url = url
group.mailing_list = mailing_list
group.mailing_list_url = mailing_list_url
if invite_only:
group.invite_only = True
else:
group.invite_only = False
group.irc_channel = irc_channel
group.irc_network = irc_network
group.joinmsg = joinmsg
group.apply_rules = apply_rules
# Log here
session.flush()
except:
turbogears.flash(_('The group details could not be saved.'))
else:
Log(author_id=person.id, description='%s edited group %s' %
(person.username, group.name))
turbogears.flash(_('The group details have been saved.'))
turbogears.redirect('/group/view/%s' % group.name)
return dict(group=group)
示例9: validate_python
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def validate_python(self, value, state):
# pylint: disable-msg=C0111
try:
# Just make sure the group already exists
# pylint: disable-msg=W0612
group = Groups.by_name(value)
except InvalidRequestError:
raise validators.Invalid(self.message('no_group', state, group=value),
value, state)
示例10: edit
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def edit(self, groupname):
'''Display edit group form'''
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if not can_admin_group(person, group):
turbogears.flash(_("You cannot edit '%s'.") % group.name)
turbogears.redirect('/group/view/%s' % group.name)
return dict(group=group)
示例11: create
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def create(self, name, display_name, owner, group_type, invite_only=0,
needs_sponsor=0, user_can_remove=1, prerequisite='',
joinmsg='', apply_rules='None'):
'''Create a group'''
groupname = name
person = People.by_username(turbogears.identity.current.user_name)
person_owner = People.by_username(owner)
if not can_create_group(person):
turbogears.flash(_('Only FAS administrators can create groups.'))
turbogears.redirect('/')
try:
owner = People.by_username(owner)
group = Groups()
group.name = name
group.display_name = display_name
group.owner_id = person_owner.id
group.group_type = group_type
group.needs_sponsor = bool(needs_sponsor)
if invite_only:
group.invite_only = True
else:
group.invite_only = False
group.user_can_remove = bool(user_can_remove)
if prerequisite:
prerequisite = Groups.by_name(prerequisite)
group.prerequisite = prerequisite
group.joinmsg = joinmsg
group.apply_rules = apply_rules
# Log group creation
Log(author_id=person.id, description='%s created group %s' %
(person.username, group.name))
session.flush()
except TypeError:
turbogears.flash(_("The group: '%s' could not be created.") % groupname)
return dict()
else:
try:
owner.apply(group, person) # Apply...
session.flush()
owner.sponsor(group, person)
owner.upgrade(group, person)
owner.upgrade(group, person)
except KeyError:
turbogears.flash(_("The group: '%(group)s' has been created, but '%(user)s' could not be added as a group administrator.") % {'group': group.name, 'user': owner.username})
else:
fas.fedmsgshim.send_message(topic="group.create", msg={
'agent': { 'username': person.username, },
'group': { 'name': group.name, },
})
turbogears.flash(_("The group: '%s' has been created.") % group.name)
turbogears.redirect('/group/view/%s' % group.name)
return dict()
示例12: view
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def view(self, groupname, order_by='username'):
'''View group'''
sort_map = { 'username': 'people_1.username',
'creation': 'person_roles_creation',
'approval': 'person_roles_approval',
'role_status': 'person_roles_role_status',
'role_type': 'person_roles_role_type',
'sponsor': 'people_2.username',
}
username = turbogears.identity.current.user_name
person = People.by_username(username)
group = Groups.by_name(groupname)
if not can_view_group(person, group):
turbogears.flash(_("You cannot view '%s'") % group.name)
turbogears.redirect('/group/list')
return dict()
# Also return information on who is not sponsored
unsponsored = PersonRoles.query.join('group').join('member',
aliased=True).outerjoin('sponsor', aliased=True).filter(
and_(Groups.name==groupname,
PersonRoles.role_status=='unapproved')).options(
eagerload('member')).order_by(sort_map[order_by])
# Filter out privacy sensitive information
unsponsored = list(unsponsored)
for person in unsponsored:
person.member.filter_private()
# This is a really, really slow query in some cases, and we only
# render it in this view if there are < 10 members. This is a rare case
# where it makes sense to perform a count query first.
# However, for consistency, we should probably count in the template.
# So instead of sending list(members) back to the template, let's
# send the members query object, then in the template, we can check
# if we need to convert it to a list or not.
members = PersonRoles.query.join('group').join('member', aliased=True).filter(
People.username.like('%')
).outerjoin('sponsor', aliased=True).filter(
Groups.name==groupname,
).order_by(sort_map[order_by])
# At the present time members is only PersonRoles info
# so we don't have to filter that.
return dict(group=group, sponsor_queue=unsponsored, members=members)
示例13: downgrade
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def downgrade(self, groupname, targetname):
'''Upgrade user in group'''
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
group = Groups.by_name(groupname)
if not can_downgrade_user(person, group):
turbogears.flash(_("You cannot downgrade '%s'") % target.username)
turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
return dict()
else:
try:
target.downgrade(group, person)
except fas.DowngradeError, e:
turbogears.flash(_('%(name)s could not be downgraded in %(group)s: %(error)s') % \
{'name': target.username, 'group': group.name, 'error': e})
turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
else:
示例14: sponsor
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def sponsor(self, groupname, targetname):
'''Sponsor user'''
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
group = Groups.by_name(groupname)
if not can_sponsor_user(person, group):
turbogears.flash(_("You cannot sponsor '%s'") % target.username)
turbogears.redirect('/group/view/%s' % group.name)
return dict()
else:
try:
target.sponsor(group, person)
except fas.SponsorError, e:
turbogears.flash(_("%(user)s could not be sponsored in %(group)s: %(error)s") % \
{'user': target.username, 'group': group.name, 'error': e})
turbogears.redirect('/group/view/%s' % group.name)
else:
示例15: remove
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import by_name [as 别名]
def remove(self, groupname, targetname):
'''Remove user from group'''
# TODO: Add confirmation?
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
group = Groups.by_name(groupname)
if not can_remove_user(person, group, target):
turbogears.flash(_("You cannot remove '%(user)s' from '%(group)s'.") % \
{'user': target.username, 'group': group.name})
turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
return dict()
else:
try:
target.remove(group, target)
except fas.RemoveError, e:
turbogears.flash(_("%(user)s could not be removed from %(group)s: %(error)s") % \
{'user': target.username, 'group': group.name, 'error': e})
turbogears.redirect(cherrypy.request.headerMap.get("Referer", "/"))
else: