本文整理汇总了Python中fas.model.People.by_username方法的典型用法代码示例。如果您正苦于以下问题:Python People.by_username方法的具体用法?Python People.by_username怎么用?Python People.by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fas.model.People
的用法示例。
在下文中一共展示了People.by_username方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='yubikey').all())
return dict(admin=admin, person=person, configs=configs,target=target)
示例2: save
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def save(self, targetname, asterisk_enabled, asterisk_pass):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not cla_done(target):
turbogears.flash(_('You must sign the CLA to have access to this service.'))
turbogears.redirect('/user/view/%s' % target.username)
return dict()
if not can_edit_user(person, target):
turbogears.flash(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/asterisk')
return dict()
new_configs = {'enabled': asterisk_enabled, 'pass': asterisk_pass}
cur_configs = Configs.query.filter_by(person_id=target.id, application='asterisk').all()
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='asterisk', attribute=config, value=new_configs[config])
target.configs.append(c)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/asterisk/')
return dict()
示例3: reject
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def reject(self, person_name):
'''Reject a user's FPCA.
This method will remove a user from the FPCA group and any other groups
that they are in that require the FPCA. It is used when a person has
to fulfill some more legal requirements before having a valid FPCA.
Arguments
:person_name: Name of the person to reject.
'''
show = {}
show['show_postal_address'] = config.get('show_postal_address')
exc = None
user = People.by_username(turbogears.identity.current.user_name)
if not is_admin(user):
# Only admins can use this
turbogears.flash(_('You are not allowed to reject FPCAs.'))
exc = 'NotAuthorized'
else:
# Unapprove the cla and all dependent groups
person = People.by_username(person_name)
for role in person.roles:
if self._cla_dependent(role.group):
role.role_status = 'unapproved'
try:
session.flush()
except SQLError, error:
turbogears.flash(_('Error removing cla and dependent groups' \
' for %(person)s\n Error was: %(error)s') %
{'person': person_name, 'error': str(error)})
exc = 'sqlalchemy.SQLError'
示例4: reject
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def reject(self, person_name):
"""Reject a user's FPCA.
This method will remove a user from the FPCA group and any other groups
that they are in that require the FPCA. It is used when a person has
to fulfill some more legal requirements before having a valid FPCA.
Arguments
:person_name: Name of the person to reject.
"""
show = {}
show["show_postal_address"] = config.get("show_postal_address")
exc = None
user = People.by_username(turbogears.identity.current.user_name)
if not is_admin(user):
# Only admins can use this
turbogears.flash(_("You are not allowed to reject FPCAs."))
exc = "NotAuthorized"
else:
# Unapprove the cla and all dependent groups
person = People.by_username(person_name)
for role in person.roles:
if self._cla_dependent(role.group):
role.role_status = "unapproved"
try:
session.flush()
except DBAPIError, error:
turbogears.flash(
_("Error removing cla and dependent groups" " for %(person)s\n Error was: %(error)s")
% {"person": person_name, "error": str(error)}
)
exc = "DBAPIError"
示例5: save
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def save(self, targetname, yubikey_enabled, yubikey_prefix):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not can_edit_user(person, target):
ff.error(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/yubikey')
return dict()
new_configs = {'enabled': yubikey_enabled, 'prefix': yubikey_prefix}
cur_configs = Configs.query.filter_by(person_id=target.id, application='yubikey').all()
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='yubikey', attribute=config, value=new_configs[config])
target.configs.append(c)
mail_subject=_('Fedora Yubikey changed for %s' % target)
mail_text=_('''
You have changed your Yubikey on your Fedora account %s. If you did not make
this change, please contact [email protected]''' % target)
email='%[email protected]' % target
send_mail(email, mail_subject, mail_text)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/yubikey/')
return dict()
示例6: save
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def save(self, targetname, bugzilla_email):
person = People.by_username(turbogears.identity.current.user_name)
target = People.by_username(targetname)
if not can_edit_user(person, target):
turbogears.flash(_("You do not have permission to edit '%s'") % target.username)
turbogears.redirect('/bugzilla')
return dict()
new_configs = {'bugzilla_email': bugzilla_email}
cur_configs = Configs.query.filter_by(person_id=target.id, application='bugzilla').all()
if bugzilla_email == None:
session.delete(cur_configs[0])
turbogears.flash(_("Bugzilla specific email removed! This means your bugzilla email must be set to: %s" % target.email))
turbogears.redirect('/bugzilla/')
for config in cur_configs:
for new_config in new_configs.keys():
if config.attribute == new_config:
config.value = new_configs[new_config]
del(new_configs[new_config])
for config in new_configs:
c = Configs(application='bugzilla', attribute=config, value=new_configs[config])
target.configs.append(c)
turbogears.flash(_("Changes saved. Please allow up to 1 hour for changes to be realized."))
turbogears.redirect('/bugzilla/')
return dict()
示例7: edit
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=person.id, application='bugzilla').all())
if 'bugzilla_email' in configs:
email = configs['bugzilla_email']
else:
email = target.email
return dict(admin=admin, person=person, email=email, target=target)
示例8: edit
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def edit(self, targetname=None):
username = turbogears.identity.current.user_name
person = People.by_username(username)
target = People.by_username(targetname)
if not cla_done(target):
turbogears.flash(_('You must sign the CLA to have access to this service.'))
turbogears.redirect('/user/view/%s' % target.username)
return dict()
admin = is_admin(person)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='asterisk').all())
return dict(admin=admin, person=person, configs=configs,target=target)
示例9: create
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [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()
示例10: genkey
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def genkey(self):
username = turbogears.identity.current.user_name
person = People.by_username(username)
created = time.strftime("%Y-%m-%dT%H:%M:%S")
hexctr = "%012x" % person.id
publicname = hex2modhex(hexctr)
internalname = gethexrand(12)
aeskey = gethexrand(32)
lockcode = gethexrand(12)
try:
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
session.add(new_ykksm)
session.flush()
except IntegrityError:
session.rollback()
old_ykksm = session.query(Ykksm).filter_by(serialnr=person.id).all()[0]
session.delete(old_ykksm)
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
old_ykksm = new_ykksm
session.flush()
try:
old_ykval = session.query(Ykval).filter_by(yk_publicname=publicname).all()[0]
session.delete(old_ykval)
session.flush()
except IndexError:
# No old record? Maybe they never used their key
pass
string = "%s %s %s" % (publicname, internalname, aeskey)
return dict(key=string)
示例11: home
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def home(self):
user_name = turbogears.identity.current.user_name
person = People.by_username(user_name)
(cla_done, undeprecated_cla) = undeprecated_cla_done(person)
person = person.filter_private()
return dict(person=person, memberships=person['memberships'], cla=undeprecated_cla)
示例12: otp_validate
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def otp_validate(user_name, otp):
client_id = '1'
target = People.by_username(user_name)
configs = get_configs(Configs.query.filter_by(person_id=target.id, application='yubikey').all())
if not otp.startswith(configs['prefix']):
return False
server_prefix = config.get('yubi_server_prefix', 'http://localhost/yk-val/verify?id=')
auth_regex = re.compile('^status=(?P<rc>\w{2})')
server_url = server_prefix + client_id + "&otp=" + otp
fh = urllib2.urlopen(server_url)
for line in fh:
match = auth_regex.search(line.strip('\n'))
if match:
if match.group('rc') == 'OK':
return True
else:
return False
break
return False
示例13: index
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def index(self):
"""Display the FPCAs (and accept/do not accept buttons)"""
show = {}
show["show_postal_address"] = config.get("show_postal_address")
username = turbogears.identity.current.user_name
person = People.by_username(username)
try:
code_len = len(person.country_code)
except TypeError:
code_len = 0
if show["show_postal_address"]:
contactInfo = person.telephone or person.postal_address
if person.country_code == "O1" and not person.telephone:
turbogears.flash(_("A telephone number is required to " + "complete the FPCA. Please fill out below."))
elif not person.country_code or not person.human_name or not contactInfo:
turbogears.flash(
_(
"A valid country and telephone number "
+ "or postal address is required to complete the FPCA. "
+ "Please fill them out below."
)
)
else:
if not person.telephone or code_len != 2 or person.country_code == " ":
turbogears.flash(
_(
"A valid country and telephone number are"
+ " required to complete the FPCA. Please fill them "
+ "out below."
)
)
(cla, undeprecated_cla) = undeprecated_cla_done(person)
person = person.filter_private()
return dict(cla=undeprecated_cla, person=person, date=datetime.utcnow().ctime(), show=show)
示例14: invite
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [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)
示例15: list
# 需要导入模块: from fas.model import People [as 别名]
# 或者: from fas.model.People import by_username [as 别名]
def list(self, search='*', with_members=True):
username = turbogears.identity.current.user_name
person = People.by_username(username)
memberships = {}
groups = []
re_search = re.sub(r'\*', r'%', search).lower()
results = Groups.query.filter(Groups.name.like(re_search)).order_by('name').all()
if self.jsonRequest():
if with_members:
membersql = sqlalchemy.select([PersonRoles.person_id, PersonRoles.group_id, PersonRoles.role_type], PersonRoles.role_status=='approved').order_by(PersonRoles.group_id)
members = membersql.execute()
for member in members:
try:
memberships[member[1]].append({'person_id': member[0], 'role_type': member[2]})
except KeyError:
memberships[member[1]]=[{'person_id': member[0], 'role_type': member[2]}]
else:
memberships = []
for group in results:
if can_view_group(person, group):
groups.append(group)
if not len(groups):
turbogears.flash(_("No Groups found matching '%s'") % search)
return dict(groups=groups, search=search, memberships=memberships)