当前位置: 首页>>代码示例>>Python>>正文


Python Profile.query方法代码示例

本文整理汇总了Python中models.Profile.query方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.query方法的具体用法?Python Profile.query怎么用?Python Profile.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Profile的用法示例。


在下文中一共展示了Profile.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getProfiles

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def getProfiles(self, request):
     """Return users (regardless if they are speakers)."""
     profiles = Profile.query()
     # return set of ProfileForm objects
     return ProfileForms(
         profiles=[self.toProfileForm(profile) for profile in profiles]
     )
开发者ID:arizonatribe,项目名称:app-engine-demo,代码行数:9,代码来源:conference.py

示例2: post

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
  def post(self):
    first_name = cgi.escape(self.request.get('first'))
    last_name = cgi.escape(self.request.get('last'))
    profession = cgi.escape(self.request.get('profession'))
    employer = cgi.escape(self.request.get('employer'))
    user_key = ndb.Key(urlsafe=self.request.get('user_key'))
    about = cgi.escape(self.request.get('about'))

    # Decode user key
    user = user_key.get()
    user.first_name = first_name
    user.last_name = last_name
    user.profession = profession
    user.employer = employer
    user.lower_profession = profession.lower()
    user.lower_employer = employer.lower()
    if employer.lower().replace(" ", "") not in user.subscriptions:
      user.subscriptions.append(employer.lower().replace(" ", ""))
    user.lower_first_name = first_name.lower()
    user.lower_last_name = last_name.lower()
    user.put()

    #Update profile
    profile = Profile.query(Profile.owner == user.key).get()
    if profile:
      profile.about = about
      profile.put()
    self.redirect('/profile/{}'.format(user.username))
开发者ID:cthavy,项目名称:Ninja-Frontend,代码行数:30,代码来源:main.py

示例3: deleteSession

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def deleteSession(self, request):
        """Delete a session"""
        # Get current user
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')
        user_id = getUserId(user)

        # Get Session Key
        session_key = ndb.Key(urlsafe=request.websafeSessionKey)
        # check that session exists
        if not session_key:
            raise endpoints.NotFoundException(
                'No session found with key: %s' % request.websafeSessionKey)

        # Check that user matches conference organizer
        conference_key = session_key.get().conferenceKey
        if user_id != conference_key.get().organizerUserId:
            raise ConflictException(
                'Only the conference organizer can delete sessions for the conference')

        session_key.delete()

        # Delete session_key from profile wishlists
        profiles = Profile.query()
        for profile in profiles:
            if session_key in profile.sessionWishlist:
                profile.sessionWishlist.remove(session_key)
                profile.put()
        return StringMessage(data='Session deleted')
开发者ID:cpwhidden,项目名称:Conference-Central,代码行数:32,代码来源:conference.py

示例4: getConferencesByPopularity

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def getConferencesByPopularity(self, request):
        """Return conferences by popularity"""
        # fetch conference from key
        conf = Conference.query().fetch()

        # Check that conference exists
        if not conf:
            raise endpoints.NotFoundException("No conference found with this key: %s" % request.websafeConferenceKey)
        conf_list = []

        for c in conf:
            count = Profile.query().filter(Profile.conferenceKeysToAttend == c.key.urlsafe()).count()
            conf_list.append({"conf": c, "count": count})
        conf_list = sorted(conf_list, key=lambda conf: conf["count"], reverse=True)

        # need to fetch organiser displayName from profiles
        # get all keys and use get_multi for speed
        organisers = [(ndb.Key(Profile, c.organizerUserId)) for c in conf]
        profiles = ndb.get_multi(organisers)

        # put display names in a dict for easier fetching
        names = {}
        for profile in profiles:
            names[profile.key.id()] = profile.displayName

        # return individual ConferenceForm object per Conference
        return ConferenceForms(
            items=[self._copyConferenceToForm(c["conf"], names[c["conf"].organizerUserId]) for c in conf_list]
        )
开发者ID:jdvalera,项目名称:Udacity-Full-Stack,代码行数:31,代码来源:conference.py

示例5: deleteConference

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def deleteConference(self, request):
        """Delete conference."""
        wsck = request.websafeConferenceKey
        conf = self._retrieveConference(wsck)
        if not conf:
            raise endpoints.NotFoundException('No conference found with key: %s' % wsck)

        # Remove the link between the sessions and this conference
        conf_sess = ConferenceSession.query(ancestor=conf.key)
        if conf_sess:
            for sess in conf_sess:
                wssk = sess.key.urlsafe()

                # Get all the wishlists that have this session in them and remove this session from them
                wishes = Wishlist.query(ndb.AND(Wishlist.sessions == wssk))
                for wish in wishes:
                    if wish and wssk in wish.sessions:
                        wish.sessions.remove(wssk)
                        wish.put()

                sess.key.delete()

        # Unregister the users from this conference if they are registered for it
        registered_users = Profile.query(ndb.AND(Profile.conferenceKeysToAttend == wsck))
        if registered_users:
            for reg_user in registered_users:
                if reg_user and wsck in reg_user.conferenceKeysToAttend:
                    reg_user.conferenceKeysToAttend.remove(wsck)
                    reg_user.put()

        conf.key.delete()

        return BooleanMessage(data=True)
开发者ID:arizonatribe,项目名称:app-engine-demo,代码行数:35,代码来源:conference.py

示例6: getTshirtsByConference

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def getTshirtsByConference(self, request):
        """Get the amount of t-shirts, grouped by size, that are needed for the given conference"""  # noqa
        # get Conference object from request; bail if not found
        wsck = request.websafeConferenceKey
        conf = ndb.Key(urlsafe=wsck).get()
        if not conf:
            raise endpoints.NotFoundException(
                'No conference found with key: %s' % request.websafeConferenceKey)  # noqa

        # Get all the people who are meant to attend the given conference
        q = Profile.query().filter(Profile.conferenceKeysToAttend == str(wsck))

        # Init a new TeeShirtSizeForm instance
        tShirts = TeeShirtSizeForm()

        # Loop through users attending the conference and add 1 unit
        # to the corresponging tshirt size group in the TeeShirtSizeForm
        # instance
        for user in q:
            setattr(
                tShirts,
                user.teeShirtSize,
                getattr(tShirts, user.teeShirtSize) + 1
            )

        # return TeeShirtSizeForm object
        return tShirts
开发者ID:iliketomatoes,项目名称:conference-app,代码行数:29,代码来源:conference.py

示例7: _checkSpeakerProfile

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def _checkSpeakerProfile(self, displayName):
     try:
         speaker = Profile.query(Profile.displayName == displayName).get()
         return True
     except:
         print "No one with displayName: {} has been registered".format(
             displayName)
         raise endpoints.NotFoundException(
             'No Profile found with key: %s' % displayName)
开发者ID:TomTheToad,项目名称:FullStack_Udacity_P4,代码行数:11,代码来源:conference.py

示例8: getAttendeesByConference

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def getAttendeesByConference(self, request):
     """Given a specified conference, return all attendees for the conference."""
     wsck = request.websafeConferenceKey
     profile = Profile.query()
     attendees = []
     for pro in profiles:
         if wsck in pro.conferenceKeysToAttend:
             attendees.append(pro)
     # return set of profileform objects
     return ProfileForms(items = [self.copyProfileToForm(attendee) for attendee in attendees])
开发者ID:minjiecode,项目名称:fullstack-nanodegree-vm,代码行数:12,代码来源:conference.py

示例9: getProfilesBySessionWishList

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def getProfilesBySessionWishList(self, request):
        """ Return all profiles who want to attend a particular session. """
        session = ndb.Key(urlsafe=request.sessionKey).get()
        if not session:
            raise endpoints.NotFoundException(
                'No session found with key: %s' % request.sessionKey)
        profiles = Profile.query().filter(Profile.session_wish_list == session.key.urlsafe())

        return ProfileForms(
            profiles=[self._copyProfileToForm(profile) for profile in profiles])
开发者ID:pshevade,项目名称:Conference-Central-App,代码行数:12,代码来源:conference.py

示例10: GetUsersForConference

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def GetUsersForConference(self, request):
        """Get list of users attending a conference. """

        # get conference key
        wsck = request.websafeConferenceKey

        # Get list of user profiles that are registered to the conference
        profiles = Profile.query(Profile.conferenceKeysToAttend == wsck)

        return ProfileForms(items=[self._copyProfileToForm(profile) for profile in profiles])
开发者ID:TimHack,项目名称:P4-ConferenceCentral,代码行数:12,代码来源:conference.py

示例11: decorated_view

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def decorated_view(*args, **kwargs):
     user=users.get_current_user()
     if not user:
         return redirect(users.create_login_url(request.url))
     profile=Profile.query(Profile.user==user).get()
     if not profile:
         key=Campaign(name='Inbox', client=user, tally=0).put()
         profile=Profile(user=user, nickname=user.nickname(), email=user.email(), campaigns=[key], inbox=key)
     profile.put()
     kwargs['profile']=profile
     return func(*args, **kwargs)
开发者ID:motord,项目名称:1742834685,代码行数:13,代码来源:decorators.py

示例12: test_addSessionToWishlist

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def test_addSessionToWishlist(self):
     # Check that no profiles exist in datastore
     prof = Profile.query().get()
     self.assertEqual(prof, None)
     # Create conference and get websafe key
     conf = Conference(name='Test_conference')
     wck = conf.put()
     # Add a session
     props = {'name': 'Monkey Business', 'date': date(2015,8,8),
              'parent': wck, 'conferenceKey': wck.urlsafe(),
              'typeOfSession': 'lecture', 'startTime': time(18,15)}
     sk = Session(speaker=['Sarah', 'Frodo'], **props).put()
     # Test the endpoint (This also creates a Profile record)
     url = '/wishlist/{0}'.format(sk.urlsafe())
     res = urlfetch.fetch(self.urlbase + url, method='POST')
     self.assertEqual(res.status_code, 200)
     self.assertTrue(json.loads(res.content)['data'])
     sleep(0.1)
     # Get profile and check for one session key
     prof = Profile.query().get()
     self.assertEqual(len(prof.sessionKeysToAttend), 1)
开发者ID:Ripley6811,项目名称:FSND-P4-Conference-Organization-App,代码行数:23,代码来源:test_endpoints.py

示例13: getConferenceAttendees

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def getConferenceAttendees(self, request):
        """Query for users attending the specified conference."""

        # find all profiles containing the conference key
        # in their conferences to attend
        profiles = Profile.query(
            Profile.conferenceKeysToAttend == request.websafeConferenceKey)

        # return profiles of conference attendees
        return ProfileForms(
            profiles=[self._copyProfileToForm(profile) for profile in profiles]
        )
开发者ID:AndrBecker,项目名称:conference-central,代码行数:14,代码来源:conference.py

示例14: getSessionWishfulAttendees

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
    def getSessionWishfulAttendees(self, request):
        """Query for users wishing to attend the specified session."""

        # find all profiles containing the session key in their wishlist
        profiles = Profile.query(Profile.sessionKeysWishlist ==
                                 request.websafeSessionKey)

        # return profiles
        return ProfileForms(
                profiles=[self._copyProfileToForm(profile)
                          for profile in profiles]
        )
开发者ID:AndrBecker,项目名称:conference-central,代码行数:14,代码来源:conference.py

示例15: getSessionAttendees

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import query [as 别名]
 def getSessionAttendees(self, request):
     """Return requested session's attendees (by websafeSessionKey)."""
     # get Session object from request; bail if not found
     sesh = ndb.Key(urlsafe=request.websafeSessionKey).get()
     if not sesh:
         raise endpoints.NotFoundException(
             'No session found with key: %s' % request.websafeSessionKey)
     attendees = Profile.query()
     attendees = attendees.filter(request.websafeSessionKey ==
                                  Profile.sessionKeysInWishList)
     # return ProfileForms
     return ProfileForms(items=[self._copyProfileToForm(attendee)
                         for attendee in attendees])
开发者ID:Sean-Holcomb,项目名称:Conference-Organization-App,代码行数:15,代码来源:conference.py


注:本文中的models.Profile.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。