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


Python User.gql方法代码示例

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


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

示例1: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def post(self):
        screen_name = self.request.get("screen_name")
        term = self.request.get("term")
        list_id = self.request.get("list_id")

        # convert list_id from string to long
        try:
            list_id = long(list_id) # long
        except:
            logging.error("Could not convert data to an integer.")
            return

        u = User.gql("WHERE screen_name = :name", name = screen_name).get()
        if u is None:
            logging.error("Could not find screen name: %s.", screen_name)
            return
        since_id = u.since_id
        token_key = u.token_key
        token_secret = u.token_secret

        # prepare Twitter API.
        auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        auth.set_access_token(token_key, token_secret)
        api = tweepy.API(auth)

        # if it's the first time this user is using this service,
        # check all the existing tweets.
        existing_retweets = set()
        if since_id is None:
            try:
                for t in Cursor(api.retweeted_by_me).items():
                    existing_retweets.add(t.retweeted_status.id)
            except tweepy.TweepError, e:
                logging.error(e)
                return
开发者ID:ronhuang,项目名称:tweetlog,代码行数:37,代码来源:main.py

示例2: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
 def get(self):
     email = self.get_current_user()
     user = User.gql("WHERE email = :1", email).get()
     if user is None:
         self.send_error(404)
     else:
         self.view("admin/profile.html", user=user,navIndex=1, menuIndex=2, error="")
开发者ID:youngpay,项目名称:myblog,代码行数:9,代码来源:admin.py

示例3: dispatch

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def dispatch(self):
        # Define temporary variables.
        self.user = users.get_current_user()
        logUrl = ""
        linkText = ""

        if self.user:
            user = User.gql("WHERE email = :1", self.user.email()).get()
            if not user:
                user = User(email=self.user.email())
                user.put()
            self.user = user
            url = users.create_logout_url(dest_url="/")
            linkText = "Logout"
        else:
            url = users.create_login_url(dest_url="/")
            linkText = "Login"
        self.templateVars["user"] = self.user
        self.templateVars["loginLinkText"] = linkText
        self.templateVars["loginLinkURL"] = url

        allowed = [r"^static/*", r"^/$"]
        # If the user is logged in, or you are accessing any file in the static
        # directory you allow access.
        if self.user or any(re.match(path, self.request.path) for path in allowed):
            super(CheckLogin, self).dispatch()
        else:
            return webapp2.redirect("/")
开发者ID:dcastro9,项目名称:personal_site,代码行数:30,代码来源:admin.py

示例4: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def post(self):
        title = self.get_argument("title", default=None)
        if title is None or len(title) == 0:
            self.view("admin/article-new.html", menuIndex=1, error=u"请输入标题")
            return
        
        email = self.get_current_user()
        user = User.gql("WHERE email = :1", email).get()

        source = self.get_argument("cleanSource", default=" ")
        html = self.get_argument("content", default=" ")
        slug = " "
        if source != " ":
            slug = source.replace("\r\n", " ").replace("\t", "  ")[0:200]

        date = datetime.datetime.now() + datetime.timedelta(hours=8)

        entry = Entry(author=user.key(),
            slug=slug, 
            title=title, 
            html=html, 
            body_source=source,
            published=date,
            updated=date)
        try:
            entry.put()
            self.dispatch(msg=u"创建成功", to=u"文章列表页", toUrl="/admin/article", seconds=2)
        except:
            self.view("admin/article-new.html", menuIndex=1, error=u"创建失败")
开发者ID:youngpay,项目名称:myblog,代码行数:31,代码来源:admin.py

示例5: github_auth

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
def github_auth():

    h = helpers.Helpers()

    access_token = h.requestAccessToken(request.args.get('code'))
    logging.info('access_token = %s', access_token)

    h.setAccessToken(access_token)

    # get user data
    user_data = json.loads(h.logged_user())
    logging.info('user data = %s', user_data)
    
    # check if user exists
    user = User.gql('WHERE github_id = :1', user_data['id']).get()
    if user:
        logging.info('user found %s', user)
        # change access token
        user.access_token = access_token
    else:
        # new user
        user = User(login=user_data['login'],
                github_id=user_data['id'],
                name=user_data['name'],
                access_token=access_token,
                repo_to_write='')
    
    # save user    
    user.put()
    
    session['access_token'] = access_token
    session['github_id'] = user.github_id
    session['login'] = user.login
    
    return redirect(url_for('select_repo'))
开发者ID:rabc,项目名称:Gitmark,代码行数:37,代码来源:views.py

示例6: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
	def post(self, user_id):
		#try:
			biz_id = self.request.get('biz')
			business_gql = Business.gql('where y_business_id = :1', biz_id)
  			if business_gql.count() == 0:
  				business = Business(y_business_id=biz_id)
  				business.put()
  				#self.error(404)
  				#self.response.out.write("biz not found")
  				return
  			else:
  				for biz in business_gql:
  					business = biz
  					break

  			user_gql = User.gql('where name = :1', user_id)
  			if user_gql.count() == 0:
  				#user = User(name=user_id, subscriptions=[])
  				#user.put()
  				self.error(404)
  				self.response.out.write("user not found")
  				return
  			else:
  				for u in user_gql:
  					user = u
  					if not business.key() in user.subscriptions:
  						user.subscriptions.append(business.key())
  						user.put()
  					break

  			businesses = self.list_all_subscriptions(user_id)
  			result = {'businesses': businesses}
  			result = json.dumps(result)
  			self.response.out.write(result)
开发者ID:wuhuwei,项目名称:lunchtrain,代码行数:36,代码来源:subscribe.py

示例7: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def get(self):
        cookies = Cookies(self, max_age = COOKIE_LIFE)
        token_key = None
        token_secret = None

        if "ulg" in cookies:
            token_key = cookies["ulg"]
        if "auau" in cookies:
            token_secret = cookies["auau"]

        if token_key is not None and token_secret is not None:
            user = User.gql("WHERE token_key=:key AND token_secret=:secret",
                            key=token_key, secret=token_secret).get()
            if user is not None:
                self.redirect("/manage")
                return

        # OAuth dance
        auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK)
        try:
            url = auth.get_authorization_url()
        except tweepy.TweepError, e:
            # Failed to get a request token
            msg = {'message': e}
            path = os.path.join(os.path.dirname(__file__), 'view', 'error.html')
            self.response.out.write(template.render(path, msg))
            return
开发者ID:ronhuang,项目名称:tweetlog,代码行数:29,代码来源:main.py

示例8: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def post(self):
        loged_in_user = User.gql("WHERE email='%s'" % self.request.get("email")).get()

        if User.preveri_geslo(self.request.get("password"), loged_in_user):
            self.create_cookie(user=loged_in_user)
            return self.render_template("home.html")
        else:
            self.write("NO!")
开发者ID:filippotocnik,项目名称:koncni-projekt,代码行数:10,代码来源:main.py

示例9: get_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
def get_user(cookie):
    if not cookie:
        return None
    if not cookie.has_key('sid'):
        return None
    access_token = memcache.get(cookie['sid'].value) #@UndefinedVariable
    if not access_token:
        return None
    return User.gql('WHERE accessToken=:1', access_token.key).get()
开发者ID:noboru-i,项目名称:kyouen-python,代码行数:11,代码来源:html.py

示例10: get_current_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
 def get_current_user(self):
     if users.get_current_user():
         user_list = User.gql("WHERE user = :1", users.get_current_user())
         if user_list.count() > 0:
             return user_list[0]
         user = User(user=users.get_current_user())
         user.put()
         return user
     return None
开发者ID:jkpluta,项目名称:jkpluta,代码行数:11,代码来源:base.py

示例11: worker_authors

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
def worker_authors(request):
    r = Repository.get(db.Key(request.POST["repo"]))
    logging.info("processing repository: %s" % r.name)
    base_url = "http://github.com/%s/%s" % (r.owner.name, r.name)
    url = base_url + "/network_meta"
    logging.info("  downloading network_meta from: %s" % url)
    try:
        s = urllib2.urlopen(url).read()
    except urllib2.HTTPError:
        logging.info("Probably bad repo, skipping.")
        return HttpResponse("Probably bad repo, skipping.\n")
    logging.info("  network_meta loaded")
    try:
        data = simplejson.loads(s)
    except ValueError:
        logging.info("Probably bad repo, skipping.")
        return HttpResponse("Probably bad repo, skipping.\n")
    logging.info("  network_meta parsed")
    dates = data["dates"]
    nethash = data["nethash"]
    url = "%s/network_data_chunk?nethash=%s&start=0&end=%d" % (base_url,
            nethash, len(dates)-1)
    logging.info("  downloading commits from: %s" % url)
    s = urllib2.urlopen(url).read()
    logging.info("  parsing commits...")
    data = simplejson.loads(s, encoding="latin-1")
    logging.info("  processing authors...")
    commits = data["commits"]
    m = [(x["author"], x["id"]) for x in commits]
    m = dict(m)
    logging.info(m)
    authors = m.keys()
    authors = list(set(authors))
    authors.sort()
    logging.info(authors)
    queue = get_github_queue()
    for author in authors:
        q = User.gql("WHERE name = :1", author)
        u = q.get()
        if u is None:
            u = User(name=author, email="None")
            u.save()
            task = taskqueue.Task(url="/hooks/worker/user_email/",
                    params={'user': u.key(),
                        'r_user_id': r.owner.name,
                        'r_repository': r.name,
                        'r_sha': m[u.name]
                        })
            queue.add(task)
        q = Author.gql("WHERE user = :1 AND repo = :2", u, r)
        a = q.get()
        if a is None:
            a = Author(repo=r, user=u)
            a.save()
    logging.info("  done.")
    return HttpResponse("OK\n")
开发者ID:certik,项目名称:webhooks,代码行数:58,代码来源:views.py

示例12: create_repository_and_owner

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
def create_repository_and_owner(repository, name, email):
    if email == "None":
        q = User.gql("WHERE name = :1", name)
    else:
        q = User.gql("WHERE email = :1", email)
    u = q.get()
    if u is None:
        u = User(name=name, email=email)
        u.save()
    q = Repository.gql("WHERE name = :1 AND owner = :2", repository, u)
    r = q.get()
    if r is None:
        r = Repository(name=repository, owner=u)
        r.save()
    queue = get_github_queue()
    task = taskqueue.Task(url="/hooks/worker/authors/",
            params={'repo': r.key()})
    queue.add(task)
    return r, u
开发者ID:certik,项目名称:webhooks,代码行数:21,代码来源:views.py

示例13: clean_username

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
    def clean_username(self):
        """ Validate username """
        username = self.cleaned_data.get('username')
        validate_username(username)

        user = User.gql("WHERE username=:1", username).get()
        if user and user.id != self.session['user']['id']:
            raise forms.ValidationError('Username "%s" sudah terpakai.' % username)

        return username
开发者ID:ekaputra07,项目名称:bokerface,代码行数:12,代码来源:forms.py

示例14: place_page

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
def place_page(place_id=None):
    if request.method == 'POST':
        p = Place.get_by_id(place_id)

        # for add subscriber form
        if 'email' in request.form:
            email = request.form.get('email', '')
            if email not in [u.email for u in User.all()]:
                u = User(
                    email=email,
                    suscribed_at=datetime.datetime.now())
                u.put()
            else:
                u = User.gql("WHERE email = '{0}'".format(email)).get()

            up = UserPlace.all().filter('user =', u).filter('place =', p).get()
            
            if up:
                return "This user already exists in subscribers!"
            else:
                if u.places_subscribed.count() >= 4:
                    return "This user has maximum subscribing"
                up = UserPlace(
                    user=u,
                    place=p
                )
                up.put()

        # for add update form
        elif 'update_link' in request.form and 'update_info' in request.form:
            update_link = request.form.get('update_link', '')
            update_info = request.form.get('update_info', '')
            u = Update(
                place=p,
                link=update_link,
                info=update_info
            )
            u.put()

        # for add link form
        elif 'link_link' in request.form and 'link_description' in request.form:
            link_link = request.form.get('link_link', '')
            link_description = request.form.get('link_description', '')
            l = PlaceLink(
                place=p,
                link=link_link,
                description=link_description
            )
            l.put()

    p = Place.get_by_id(place_id)
    updates = [update for update in p.place_updates.order('-added_at')]
    links = [link for link in p.placelink_set.order('-added_at')]

    return render_template('place.html', place=p, updates=updates, links=links)
开发者ID:gromadco,项目名称:locograph,代码行数:57,代码来源:main.py

示例15: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import gql [as 别名]
 def post(self):
   j = self.request.get('from').split('/')[0]
   u = User.gql('WHERE jid = :1', j).get()
   if not u:
     u = User(jid=j)
     u.put()
   message = xmpp.Message(self.request.POST)
   
   r = query_bitly(message.body.strip().split(' ')[0], u)
   message.reply('\n'+r) # replied
   return
开发者ID:algby,项目名称:my-xmpp,代码行数:13,代码来源:main.py


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