Ejemplo n.º 1
0
 def get(self):
     user = users.get_current_user()
     
     user_prefs_query = UserPrefs().all()
     user_prefs_query.filter('google_account =', user)
     
     user_prefs = user_prefs_query.get()
     
     if user is not None and user_prefs is not None:
         color_name_list = ColorName.all().filter('user_prefs =', user_prefs).fetch(100)
         color_list = []
         for color_name in color_name_list:
             color_list.append({'name': color_name.name,
                                'name_yomi': color_name.name_yomi,
                                'red': color_name.red,
                                'green': color_name.green,
                                'blue': color_name.blue,
                                'rank': color_name.rank})
             
         data = json.dumps(color_list, ensure_ascii=False)
         
     else:
         self.response.set_status(401)
         data = json.dumps({'state': 'failed'}, ensure_ascii=False)
         
     self.response.content_type = 'application/json'
     self.response.out.write(data)
Ejemplo n.º 2
0
    def get(self, user_id):
        user_prefs = UserPrefs().all().filter('user_id =', user_id).get()

        if user_prefs is None:
            return self.error(404)

        color_name_list = ColorName.all()\
                            .filter('user_prefs =', user_prefs)\
                            .order('rank')\
                            .fetch(100, 0)

        color_list = []
        #color_list.append({'name': 'test',
        #                   'name_yomi': 'test',
        #                   'hex': '%02x%02x%02x' % (128,
        #                                             128,
        #                                             128)
        #                   })
        for color_name in color_name_list:
            is_crayon_available = CrayonData.all().filter(
                'color_name =', color_name).get()

            show_new_icon = False
            if color_name.created_at > (datetime.datetime.now() -
                                        datetime.timedelta(days=1)):
                show_new_icon = True

            color_list.append({
                'id':
                color_name.key().id(),
                'name':
                color_name.name,
                'name_yomi':
                color_name.name_yomi,
                'is_crayon_available':
                True if is_crayon_available else False,
                'show_new_icon':
                show_new_icon,
                'hex':
                '%02x%02x%02x' %
                (color_name.red, color_name.green, color_name.blue)
            })

        template_values = {
            'nick_name': user_prefs.nick_name,
            'user_id': user_prefs.user_id,
            'color_list': color_list
        }

        path = os.path.join(os.path.dirname(__file__), 'templates/user.html')
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 3
0
 def get(self, user_id):
     user_prefs = UserPrefs().all().filter('user_id =', user_id).get()
     
     if user_prefs is None:
         return self.error(404)
     
     color_name_list = ColorName.all()\
                         .filter('user_prefs =', user_prefs)\
                         .order('rank')\
                         .fetch(100, 0)
     
     color_list = []
     #color_list.append({'name': 'test',
     #                   'name_yomi': 'test',
     #                   'hex': '%02x%02x%02x' % (128,
     #                                             128,
     #                                             128)
     #                   })
     for color_name in color_name_list:
         is_crayon_available = CrayonData.all().filter('color_name =', color_name).get()
         
         show_new_icon = False
         if color_name.created_at > (datetime.datetime.now() - datetime.timedelta(days=1)):
             show_new_icon = True
         
         color_list.append({'id': color_name.key().id(),
                            'name': color_name.name,
                            'name_yomi': color_name.name_yomi,
                            'is_crayon_available': True if is_crayon_available else False,
                            'show_new_icon': show_new_icon,
                            'hex': '%02x%02x%02x' % (color_name.red,
                                                      color_name.green,
                                                      color_name.blue)
                            })
     
     template_values = {
         'nick_name': user_prefs.nick_name,
         'user_id': user_prefs.user_id,
         'color_list': color_list
         
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/user.html')
     self.response.out.write(template.render(path, template_values))
Ejemplo n.º 4
0
 def get(self):
     user = users.get_current_user()
     if user is None:
         login_url = users.create_login_url('/api/v1/login?first=true')
         return self.redirect(login_url)
     
     continue_login = self.request.get('continue')
     first_login = self.request.get('first')
     
     user_id = gen_userid()
     
     user_prefs_query = UserPrefs().all()
     user_prefs_query.filter('google_account =', user)
     
     template_name = 'login.html'
     
     is_previously_saved = False
     user_prefs = user_prefs_query.get()
     if user_prefs is None:
         user_prefs = UserPrefs()
         user_prefs.user_id = user_id
         user_prefs.google_account = user
         user_prefs.put()
         
     else:
         color_name = ColorName.all().filter('user_prefs =', user_prefs).count(10)
         if color_name > 0:
             is_previously_saved = True
             
         if continue_login != 'true' and first_login != 'true':
             template_name = 'confirm_login.html'
     
     template_values = {
         'account': user.email(),
         'user_id': user_prefs.user_id,
         'avatar_available': True if user_prefs.avatar else False,
         'is_previously_saved': is_previously_saved
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/api/%s' % template_name)
     self.response.out.write(template.render(path, template_values))