Exemplo n.º 1
0
    def get(self):
        google_login_template = jinja_env.get_template(
            "/templates/google_login.html")
        new_user_template = jinja_env.get_template("/templates/new_user.html")

        user = users.get_current_user()

        if user:
            print("ACCOUNT EXISTS:")
            print(user.email())
            print(user.nickname())

            existing_user = User.query().filter(
                User.email == user.email()).get()
            nickname = user.nickname()
            if existing_user:
                self.redirect('/addcourses')

            if not existing_user:
                fields = {
                    "nickname": nickname,
                    "logout_url": logout_url,
                }
                self.response.write(new_user_template.render(fields))
            # else:
            #     self.redirect('/layout.html')
        else:
            self.response.write(
                google_login_template.render({"login_url": login_url}))
Exemplo n.º 2
0
def populate_feed(current_user, current_board):
    chat_fields = {
        "sign_out":
        logout_url,
        "username":
        current_user.username,
        "user_name":
        current_user.name,
        "post_count":
        len(Post.query().filter(Post.author == current_user.key).fetch()),
        "user_count":
        len(User.query().fetch()),
        "posts":
        format_posts(Post.query().filter(
            Post.board == current_board).order(-Post.time).fetch(limit=30)),
        "users":
        User.query().order(User.username).fetch(),
        "board":
        current_board,
    }
    return chat_fields
Exemplo n.º 3
0
def task_users():

    logging.info("Performing user maintainance...")

    users = list(User.query().fetch())

    for user in users:
        # Delete all users whose last move is older than USER_TIMEOUT
        expired = (datetime.now() - user.last_activity_date) > timedelta(
            days=app.config['USER_TIMEOUT'])
        if expired:
            # Delete user
            logging.info("Deleting user %s. Last activity: %s", user.username,
                         str(user.last_activity_date))
            user.key.delete()
Exemplo n.º 4
0
    def get(self):
        template = jinja_environment.get_template('calendar.html')
        logout = {'logout':users.create_logout_url('/')}
        #self.response.out.write(template.render(logout))
        #user = User.query().filter().keys
        #print user
#pulls list out of Datastore


        userCal = User.query().filter(User.user == users.get_current_user().email())
        if userCal.get() == None:
            self.redirect('/intro')
        else:

            attractions= userCal.get().attractions
            resturantsBreakfast= userCal.get().resturantsBreakfast
            resturantsGeneral= userCal.get().resturantsGeneral
            userDay= userCal.get().dateNum
            city= userCal.get().city
            state= userCal.get().state

            variables = {
            'ad1p1': attractions[0:3],
            'ad1p2': attractions[3:6],
            'ad2p1': attractions[6:9],
            'ad2p2': attractions[9:12],
            'ad3p1': attractions[12:15],
            'ad3p2': attractions[15:18],
            'rd1b1': resturantsBreakfast[0:1],
            'rd2b2': resturantsBreakfast[1:2],
            'rd2b3': resturantsBreakfast[2:3],
            'rd1g1': resturantsGeneral[0:1],
            'rd1g2': resturantsGeneral[1:2],
            'rd2g3': resturantsGeneral[2:3],
            'rd2g4': resturantsGeneral[3:4],
            'rd3g5': resturantsGeneral[4:5],
            'rd3g6': resturantsGeneral[5:6],
            'search_city': city,
            'search_state': state
            }
            self.response.write(template.render(variables))
Exemplo n.º 5
0
    def arg_body(self):

        user = self.user
        adversary_username = self.text

        if self.text == "/cancel":
            user.send_message("Game cancelled!",
                              reply_markup=telegram.ReplyKeyboardRemove(True))
        else:
            if adversary_username == user.username and not user.admin:
                user.send_message(
                    constants.ERROR_SAME_USER,
                    reply_markup=telegram.ReplyKeyboardRemove(True))
                return

            query = User.query(User.username == adversary_username)
            query_list = list(query.fetch())

            if len(query_list) != 1:
                # Adversary not found
                invite_button = [[
                    telegram.InlineKeyboardButton(
                        "Invite a friend",
                        switch_inline_query=constants.STRING_SHARED)
                ]]
                reply_markup = telegram.InlineKeyboardMarkup(invite_button)
                user.send_message(
                    adversary_username + " is not a Chess Duel Bot user.",
                    reply_markup=telegram.ReplyKeyboardRemove(True))
                user.send_message(constants.STRING_INVITE,
                                  reply_markup=reply_markup)
                return

            adversary = query_list[0]
            if adversary.status == UserStatus.IDLE:

                try:
                    timeout = int(user.pending_arg)
                except ValueError:
                    # TODO: Print error
                    return

                match = Match(white_id=adversary.key.id(),
                              black_id=user.key.id(),
                              timeout=timeout)
                match.put()

                # Adversary found
                user.setup_match(match, adversary, False)
                user.send_message(
                    constants.STRING_REQUEST_SENT,
                    reply_markup=telegram.ReplyKeyboardRemove(True))

                adversary.setup_match(match, user, True)
                accept_button = [[
                    telegram.InlineKeyboardButton("Accept",
                                                  callback_data='/accept'),
                    telegram.InlineKeyboardButton("Refuse",
                                                  callback_data='/refuse')
                ]]
                reply_markup = telegram.InlineKeyboardMarkup(accept_button)
                adversary.send_message(
                    constants.STRING_REQUEST_RECEIVED.format(
                        user.username,
                        humanfriendly.format_timespan(match.timeout)),
                    reply_markup=reply_markup)
            else:

                # Adversary busy
                user.send_message(
                    "Adversary is busy",
                    reply_markup=telegram.ReplyKeyboardRemove(True))
Exemplo n.º 6
0
def notify_admins(message):

    admins = list(User.query(User.admin == True).fetch())

    for admin in admins:
        admin.send_message(message)
Exemplo n.º 7
0
def format_posts(posts):
    return [(User.query().filter(User.key == post.author).get().username,
             post.content, post.time) for post in posts]