Ejemplo n.º 1
0
    def get(self):
        
        geotags_query = Geotag.all()
        geotags = []
        users = []
        tags = []
        imgUrls = []
        
        for geotag in geotags_query:
        	user = geotag.user
        	tag = geotag.tag
        	imgUrl = geotag.imgUrl
        	if (user not in users): users.append(user)
        	if (tag not in tags): tags.append(tag)
        	if (imgUrl not in imgUrls): imgUrls.append(imgUrl)
        
        users.sort()
        tags.sort()
        
        
        template_values = {
            'geotags': geotags,
            'users': users,
            'tags': tags,
            'imgUrls': imgUrls,
        	}

        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
  def get(self):
    # CookieからChannel TokenIDを取得
    client_id = self.request.cookies.get('client_id', '')
    token = self.request.cookies.get('token', '')

    if not (len(client_id) and len(token)):
      # Channel TokenIDを生成
      client_id = str(uuid.uuid4())
      token = channel.create_channel(client_id, 24 * 60)

      # クッキーの有効期限として1日後の時間を取得
      after_one_day_time = (datetime.datetime.now() + datetime.timedelta(hours=33)).strftime('%a, %d-%b-%Y %H:%M:%S GMT')

      # client_idをクッキーに保存
      myCookie = 'client_id=%s; expires=%s;' % (client_id, after_one_day_time)
      self.response.headers.add_header('Set-Cookie', myCookie)

      # tokenをクッキーに保存
      myCookie = 'token=%s; expires=%s;' % (token, after_one_day_time)
      self.response.headers.add_header('Set-Cookie', myCookie)

    # 同時接続しているユーザーのClient ID一覧を取得
    users = memcache.get(USER_KEY)
    if not users:
      users = []

    # クッキーのtokenと同じユーザーが登録されているかどうか
    isAddUser = False
    for user in users:
      if user.token == token:
        isAddUser = True

    # クッキーのtokenと同じユーザーが登録されていなければ新規に作成
    if not isAddUser:
      # ユーザークラスを作成する
      user = User(client_id, token)

      # 新しいClient IDを追加する
      users.append(user)
      memcache.set(USER_KEY, users, 60*60*24)

    # データストアからワードデータの取得
    words, cursor, more = Word.query().order(-Word.word_id).fetch_page(11)

    # TODO デプロイ時はコメントアウト
    if len(words) == 0:
      current_time = (datetime.datetime.now() + datetime.timedelta(hours=9))
      words = Word(word_id=1, member_id=0, word=u"しりとらず", hiragana=u"しりとらず", image_url="http://siritoraz.appspot.com/favicon.ico", amazon_link="http://siritoraz.appspot.com", created_at=current_time.strftime("%Y/%m/%d %H:%M:%S"))
      words.put()

    template_values = {
      'words': words,
      'token': token,
      'words_cursor': cursor.urlsafe(),
      'more_words': more
    }

    template = JINJA_ENVIRONMENT.get_template('index.html')
    self.response.write(template.render(template_values))
Ejemplo n.º 3
0
Archivo: room.py Proyecto: pagewoo/ASL
	def get(self, room_name):
		rooms = Room.gql('where room_name = :1', room_name).fetch(1000)
		users = []
		for room in rooms:
			user = Users.gql('where user_id = :1', room.user_id).get()
			users.append(user.to_dict())

		self.response.out.write(json.dumps(users))
Ejemplo n.º 4
0
def edit_users():
    keys = sorted(user_pub_keys)
    query = db.User.query(
        db.User.pub_key >= keys[0],
        db.User.pub_key <= keys[-1])
    users = query.order(db.User.pub_key).fetch(keys_only=True)
    if not users:
        for key in keys:
            users.append(db.User.create(key, description=key, use_hash=False).key)
    return users
Ejemplo n.º 5
0
 def get(self):
     q=UsersList.all()
     users = []
     for user in q.run():
         users.append(user)
     template_values=login_status(self.request.uri)
     template_values.update({
         'users' : users})
     template = jinja_environment.get_template('display_users_list.html')
     self.response.out.write(template.render(template_values))
Ejemplo n.º 6
0
 def get(self):
     q=UsersList.all()
     users = []
     for user in q.run():
         users.append(user)
     template_values=login_status(self.request.uri)
     template_values.update({
         'users' : users ,
         'unregister_url' : '/authenticationmanagement/admin/unregisteruser'})
     template = jinja_environment.get_template('unregister_user.html')
     self.response.out.write(template.render(template_values))
Ejemplo n.º 7
0
 def get(self):
     result = {}
     radars = None
     
     count = self.request.get("count")
     if (count):
         count = int(count)
     else:
         count = 100
     
     page = self.request.get("page")
     if (page):
         page = int(page)
     else:
         page = 1
     
     scope = self.request.get("scope")
     if (not scope):
         scope = "all"
     
     searchQuery = self.request.get("q")
     keywords = searchQuery.split(" ")
     keyword = keywords[0]
     
     try:
         if (scope == "number"):
             radars = db.Radar().fetchByNumbers(keywords, page, count)
         elif (scope == "user"):
             users = []
             for userName in keywords:
                 user = google.appengine.api.users.User(userName)
                 if user:
                     users.append(user)
             radars = db.Radar().fetchByUsers(users, page, count);
         else:
             radars = models.Radar.all().search(keyword).order("-number").fetch(count, (page - 1) * count)
     except Exception:
         radars = None
     
     if (radars and len(radars) > 0):
         result = [radar.toDictionary() for radar in radars]
     
     # Return the result
     self.respondWithDictionaryAsJSON({"result": result})
Ejemplo n.º 8
0
def manage_connections(otherUserID = None):
	cur_user = current_user()

	if request.method == 'GET':
		connections = cur_user.get_all_connections()
		users = []
		result = "you have " + str(len(connections)) + " connections"
		for connection in connections:
			result += "<br>" + connection.name
			user = dict()
			user["name"] = connection.name
			user["email"] = connection.email
			#user["username"] = connection.username
			user["id"] = connection.get_id()
			users.append(user)
		return jsonify({"connectedUsers":users})
	elif request.method == 'POST':
		cur_user = current_user()
		otherUser = UserAccount.getuser(int(otherUserID))
		result = cur_user.send_invite(otherUser)
		if(result == 0):
			return jsonify({"Message":"Invitation successfully sent"})
		elif(result == 1):
			return jsonify({"Message":"Connection already existed"})
		elif(result == 2):
			return jsonify({"Message":"Cannot create a connection with yourself"})
	elif request.method == 'DELETE':
		cur_user = current_user()
		otherUser = UserAccount.getuser(int(otherUserID))
		if cur_user.remove_connection(otherUser):
			return jsonify({"Message":"Connection successfully deleted"})
		else:
			return jsonify({"Message":"Connection didn't existed"})
	else:
		#this should never be reached
		return jsonify({"Message":"Error: http request was invalid"})
Ejemplo n.º 9
0
	def render_page(self, user):
		if not user:
			self.redirect("/index")
			return
		if(user.userType == '1'):
			orders = db.GqlQuery("select * from Order ORDER BY placed_time DESC")
			orders = list(orders)
			books = []
			users = []
			for order in orders:
				books.append(db.get(order.book))
				users.append(db.get(order.user))
			self.render("orders.html", orders = orders, books = books, users = users, user = user)
		else:
			if user.userType == '0':
				orders = db.GqlQuery("select * from Order where user='******' ORDER BY placed_time DESC")
				books = []
				users = []
				orders = list(orders)
				for order in orders:
					books.append(db.get(order.book))
				self.render("orders.html", orders = orders, books = books, user = user)
			else:
				self.redirec('/index')	
Ejemplo n.º 10
0
def get_users(group):
    users = []
    for member_id in group.members:
        users.append(UserAlias.get_by_id(member_id))
    return users
Ejemplo n.º 11
0
def addUserToOfflineMsgOnUserList(gtalk):
    users = getOfflineMsgOnUserListFromCache()
    if gtalk not in users:
        users.append(gtalk)
        setConfigValueWithCache('cache_offline_msgon_user_list', users)
    return users
Ejemplo n.º 12
0
def addUserToOnlineUserList(gtalk):
    users = getOnlineUserListFromCache()
    if gtalk not in users:
        users.append(gtalk)
        setConfigValueWithCache('cache_online_user_list', users)
    return users
Ejemplo n.º 13
0
def addUserToOfflineMsgOffUserList(gtalk):
	users = getOfflineMsgOffUserListFromCache()
	if gtalk not in users:
		users.append(gtalk)
		setConfigValueWithCache('cache_offline_msgoff_user_list',users)
	return users
Ejemplo n.º 14
0
def addUserToOnlineUserList(gtalk):
	users = getOnlineUserListFromCache()
	if gtalk not in users:
		users.append(gtalk)
		setConfigValueWithCache('cache_online_user_list',users)
	return users
Ejemplo n.º 15
0
    def post(self):
        doc_id = self.request.get('doc_id', '')
        if doc_id:
            #logging.debug('doc_id: %s' % (doc_id))
            urlinstance = Url.get_by_id(int(doc_id))

            if urlinstance:
                # If not valid url, delete from index
                if urlinstance.valid < 0:
                    doc_index = search.Index(name='url')
                    logging.info(
                        'Delete invalid (%s) url (ID %s) from document index \'url\' (%s)'
                        % (str(urlinstance.valid), doc_id, doc_index))
                    doc_index.delete(doc_id)
                else:
                    url = urlinstance.url
                    title = urlinstance.title
                    #logging.debug('url: %s, title: %s' % (url, title))

                    channels = []
                    channel = None
                    users = []
                    user = None
                    date = datetime.datetime.fromtimestamp(0)

                    comments = []
                    comment = None
                    tags = []
                    tag = None

                    rate = 0

                    channelurlquery = ChannelUrl.query(
                        ChannelUrl.url == urlinstance.key)
                    for channelurlinstance in channelurlquery:
                        channelinstance = channelurlinstance.channel.get()
                        if channelinstance.name not in channels:
                            channels.append(channelinstance.name)
                            #logging.info('Adding channel %s' % (channelinstance.name))

                        postquery = Post.query(
                            Post.channelurl == channelurlinstance.key)
                        for postinstance in postquery:
                            if postinstance.user not in users:
                                users.append(postinstance.user)
                            if date:
                                if date < postinstance.date:
                                    date = postinstance.date
                            else:
                                date = postinstance.date

                        extraquery = Extra.query(
                            Extra.channelurl == channelurlinstance.key)
                        for extrainstance in extraquery:
                            if extrainstance.tag:
                                if extrainstance.tag not in tags:
                                    tags.append(extrainstance.tag)
                                    #logging.info('Adding tag %s' % (extrainstance.tag))
                            if extrainstance.comment:
                                if extrainstance.comment not in comments:
                                    comments.append(extrainstance.comment)
                                    #logging.info('Adding comment %s' % (extrainstance.comment))

                        ratequery = Rate.query(
                            Rate.channelurl == channelurlinstance.key)
                        for rateinstance in ratequery:
                            rate += rateinstance.value
                        #logging.debug('rate %s' % (rate))

                    if not date:
                        date = datetime.datetime.fromtimestamp(0)
                    # lists to strings
                    channel = ' '.join(channels)
                    user = '******'.join(users)
                    tag = ' '.join(tags)
                    if not tag:
                        tag = None
                    comment = ' '.join(comments)
                    if not comment:
                        comment = None

                    logging.debug(
                        'doc; channel=%s, user=%s, url=%s, date=%s, title=%s, comment=%s, tag=%s, rate=%s'
                        %
                        (channel, user, url, date, title, comment, tag, rate))
                    try:
                        doc = search.Document(
                            doc_id=str(doc_id),
                            fields=[
                                search.TextField(name='channel',
                                                 value=channel),
                                search.TextField(name='user', value=user),
                                search.TextField(name='url', value=url),
                                search.DateField(name='date', value=date),
                                search.TextField(name='title', value=title),
                                search.TextField(name='comment',
                                                 value=comment,
                                                 language='fi'),
                                search.TextField(name='tag',
                                                 value=tag,
                                                 language='fi'),
                                search.NumberField(name='rate', value=rate)
                            ],
                            language='en')
                    except Exception, e:
                        logging.error('doc_id: %s, error %s' %
                                      (str(doc_id), e))
                        doc = None

                    try:
                        if doc:
                            search.Index(name='url').put(doc)
                            urlinstance.document_date = datetime.datetime.now()
                            urlinstance.put()
                        else:
                            logging.error('Doc missing.')
                    except search.Error:
                        logging.error('Create Document failed.')
            else:
                logging.debug('No urlinstance for doc_id: %s' % (doc_id))