本文整理汇总了Python中souper.soup.get_soup函数的典型用法代码示例。如果您正苦于以下问题:Python get_soup函数的具体用法?Python get_soup怎么用?Python get_soup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_soup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _data
def _data(self):
# facultiesList = faculties(None).by_value.keys()
news = []
news_filtered = []
context = aq_inner(self.context)
portal_state = getMultiAdapter((context, self.request), name='plone_portal_state')
path = portal_state.navigation_root_path()
limit = self.data.count
state = self.data.state
portal = getSite()
current_user = api.user.get_current()
userid = current_user.id
soup_tags = get_soup('user_subscribed_tags', portal)
tags_soup = [r for r in soup_tags.query(Eq('id', userid))]
if tags_soup:
tags = tags_soup[0].attrs['tags']
news += self.get_news(context, state, path, limit, tags)
for newObject in news:
if newObject not in news_filtered and newObject['subject'] is not ():
news_filtered.append(newObject)
newsSorted = sorted(news_filtered, key=lambda new: new['date'], reverse=True)
return newsSorted
else:
return []
示例2: get_safe_member_by_id
def get_safe_member_by_id(username):
"""Gets user info from the repoze.catalog based user properties catalog.
This is a safe implementation for getMemberById portal_membership to
avoid useless searches to the LDAP server. It gets only exact matches (as
the original does) and returns a dict. It DOES NOT return a Member
object.
"""
portal = api.portal.get()
soup = get_soup('user_properties', portal)
username = username.lower()
records = [r for r in soup.query(Eq('id', username))]
if records:
properties = {}
for attr in records[0].attrs:
if records[0].attrs.get(attr, False):
properties[attr] = records[0].attrs[attr]
# Make sure that the key 'fullname' is returned anyway for it's used in
# the wild without guards
if 'fullname' not in properties:
properties['fullname'] = ''
return properties
else:
# No such member: removed? We return something useful anyway.
return {'username': username, 'description': '', 'language': '',
'home_page': '', 'name_or_id': username, 'location': '',
'fullname': ''}
示例3: test_group_sync
def test_group_sync(self):
sync_view = getMultiAdapter((self.portal, self.request), name='syncldapgroups')
sync_view.render()
soup = get_soup('ldap_groups', self.portal)
self.assertTrue(len(soup.data.keys()) > 0)
示例4: render
def render(self):
portal = getSite()
current_user = api.user.get_current()
userid = current_user.id
tag = self.request.form['tag']
soup_tags = get_soup('user_subscribed_tags', portal)
exist = [r for r in soup_tags.query(Eq('id', userid))]
if not exist:
record = Record()
record.attrs['id'] = userid
record.attrs['tags'] = [tag]
soup_tags.add(record)
else:
subscribed = [True for utag in exist[0].attrs['tags'] if utag == tag]
if subscribed:
exist[0].attrs['tags'].remove(tag)
else:
exist[0].attrs['tags'].append(tag)
soup_tags.reindex()
if IPloneSiteRoot.providedBy(self.context):
self.request.response.redirect(self.context.absolute_url() + '/alltags')
else:
self.request.response.redirect(self.context.absolute_url())
示例5: __call__
def __call__(self):
soup = get_soup(self.soup_name, self.context)
aaData = list()
length, lazydata = self.query(soup)
columns = self.columns
colnames = [_['id'] for _ in columns]
# todo json response header einbaun
def record2list(record):
result = list()
for colname in colnames:
coldef = self.column_def(colname)
renderer = coldef.get('renderer')
if renderer:
value = renderer(colname, record)
else:
value = record.attrs.get(colname, '')
result.append(value)
return result
for lazyrecord in self.slice(lazydata):
aaData.append(record2list(lazyrecord()))
data = {
"sEcho": int(self.request.form['sEcho']),
"iTotalRecords": soup.storage.length.value,
"iTotalDisplayRecords": length,
"aaData": aaData,
}
self.request.response.setHeader("Content-type", "application/json")
return json.dumps(data)
示例6: initialize
def initialize(self):
""" setup the storage
"""
alsoProvides(self.root, ISoupRoot)
locator = StorageLocator(self.root)
locator.storage(self.id)
self._soup = get_soup(self.id, self.root)
示例7: do_transition_for_booking
def do_transition_for_booking(booking, transition, order_data, event=False):
"""do any transition for a given single booking
this mixes main state and salaried!
"""
# XXX: currently we need to delete attribute before setting to a new
# value in order to persist change. fix in appropriate place.
if transition == interfaces.SALARIED_TRANSITION_SALARIED:
del booking.attrs['salaried']
booking.attrs['salaried'] = interfaces.SALARIED_YES
elif transition == interfaces.SALARIED_TRANSITION_OUTSTANDING:
del booking.attrs['salaried']
booking.attrs['salaried'] = interfaces.SALARIED_NO
elif transition == interfaces.STATE_TRANSITION_RENEW:
del booking.attrs['state']
booking.attrs['state'] = interfaces.STATE_NEW
# fix stock item available
order_data.decrease_stock([booking])
elif transition == interfaces.STATE_TRANSITION_PROCESS:
del booking.attrs['state']
booking.attrs['state'] = interfaces.STATE_PROCESSING
elif transition == interfaces.STATE_TRANSITION_FINISH:
del booking.attrs['state']
booking.attrs['state'] = interfaces.STATE_FINISHED
elif transition == interfaces.STATE_TRANSITION_CANCEL:
del booking.attrs['state']
booking.attrs['state'] = interfaces.STATE_CANCELLED
# fix stock item available
order_data.increase_stock([booking])
else:
raise ValueError(u"invalid transition: %s" % transition)
bookings_soup = get_soup('bda_plone_orders_bookings', order_data.context)
bookings_soup.reindex(records=[booking])
示例8: rebuild_soup
def rebuild_soup(self):
sid = self.request.form.get("id")
if not sid:
return self.redirect_base("No soup id given")
soup = get_soup(sid, self.context)
soup.rebuild()
msg = "%s rebuilt." % sid
return self.redirect_base(msg)
示例9: clear_soup
def clear_soup(self):
sid = self.request.form.get('id')
if not sid:
return self.redirect_base('No soup id given!')
soup = get_soup(sid, self.context)
soup.clear()
msg = '%s cleared.' % sid
return self.redirect_base(msg)
示例10: rebuild_length
def rebuild_length(self):
sid = self.request.form.get("id")
if not sid:
return self.redirect_base("No soup id given")
soup = get_soup(sid, self.context)
newlen = len(soup.storage.data)
soup.storage.length.set(newlen)
transaction.commit()
return self.redirect_base(u"Length of storage %s is %s" % (sid, newlen))
示例11: getMyTags
def getMyTags(self):
portal = getSite()
current_user = api.user.get_current()
userid = current_user.id
soup_tags = get_soup('user_subscribed_tags', portal)
tags_soup = [r for r in soup_tags.query(Eq('id', userid))]
return tags_soup[0].attrs['tags'] if tags_soup else []
示例12: remove_user_from_catalog
def remove_user_from_catalog(username):
portal = api.portal.get()
soup = get_soup('user_properties', portal)
exists = [r for r in soup.query(Eq('id', username))]
if exists:
user_record = exists[0]
del soup[user_record]
if IAMULEARN:
extender_name = api.portal.get_registry_record('genweb.controlpanel.core.IGenwebCoreControlPanelSettings.user_properties_extender')
# Make sure that, in fact we have such a extender in place
if extender_name in [a[0] for a in getUtilitiesFor(ICatalogFactory)]:
extended_soup = get_soup(extender_name, portal)
exist = []
exist = [r for r in extended_soup.query(Eq('id', username))]
if exist:
extended_user_record = exist[0]
del extended_soup[extended_user_record]
示例13: test_delete_community
def test_delete_community(self):
login(self.portal, 'ulearn.testuser1')
community = self.create_test_community()
gwuuid = IGWUUID(community).get()
api.content.delete(obj=community)
soup = get_soup('communities_acl', self.portal)
records = [r for r in soup.query(Eq('gwuuid', gwuuid))]
self.assertFalse(records)
示例14: get_editacl
def get_editacl(self, community):
# The user has role Manager
gwuuid = community.gwuuid
portal = api.portal.get()
soup = get_soup('communities_acl', portal)
records = [r for r in soup.query(Eq('gwuuid', gwuuid))]
editacl = dict(users=records[0].attrs['acl'].get('users', ''),
groups=records[0].attrs['acl'].get('groups', ''))
return editacl
示例15: render
def render(self):
query = self.request.form.get('q', '')
if query:
portal = api.portal.get()
soup = get_soup('ldap_groups', portal)
normalized_query = query.replace('.', ' ') + '*'
results = [dict(id=r.attrs.get('id')) for r in soup.query(Eq('searchable_id', normalized_query))]
return json.dumps(dict(results=results))
else:
return json.dumps(dict(id='No results yet.'))