Exemplo n.º 1
0
 def get(self):
     
     map_id = self.request.get('id')
     
     data = memcache.get('tag_index_%s' % map_id)
     if data is None:
         user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
         if user_maps is None:
             logging.error('map_id not found.')
             return self.error(404)
         
         user_activity_tag_index_list = UserActivityTagIndex.all().filter('user_maps =', user_maps.key()).fetch(100)
         if len(user_activity_tag_index_list) <= 0:
             logging.error('Tag index not found.')
             return self.error(404)
         
         data = []
         for user_activity_tag_index in user_activity_tag_index_list:
             data.append({'id': user_activity_tag_index.key().id(), 'tag': user_activity_tag_index.tag, 'count': user_activity_tag_index.count})
         
         memcache.add('tag_index_%s' % map_id, data, 3600)
         logging.info('Add memcache.')
         
     else:
         logging.info('Load memcache.')
     
     json = simplejson.dumps(data, ensure_ascii=False)
     self.response.content_type = 'application/json'
     self.response.out.write(json)
Exemplo n.º 2
0
 def post(self, map_id):
     
     user = users.get_current_user()
     if user is None:
         return self.redirect(users.create_login_url(self.request.uri))
     
     user_prefs = UserPrefs.all().filter('google_account =', user).get()
     if user_prefs is None:
         return self.redirect('/map/%s' % map_id)
     
     user_maps = UserMaps.all().filter('map_id =', map_id).filter('visible =', True).filter('user_prefs =', user_prefs.key()).get()
     if user_maps is None:
         return self.redirect('/map/%s' % map_id)
     
     mode = self.request.get('mode')
     
     if mode == 'set_home':
         lat = self.request.get('lat')
         lng = self.request.get('lng')
         
         user_maps.home_geo = db.GeoPt(lat, lon=lng)
         user_maps.put()
     elif mode == 'set_marker':
         name = self.request.get('name')
         tags = self.request.get('tags')
         icon = self.request.get('icon')
         
         marker_icon = None
         if icon != '':
             marker_icon = MarkerIcon.get_by_id(int(icon))
         
         tags = tags.replace(u'、', ',').replace(' ', ',').replace(u' ', ',')
         
         lat = self.request.get('lat')
         lng = self.request.get('lng')
         
         user_activity = UserActivity()
         user_activity.name = name
         user_activity.tags = tags
         user_activity.geo = db.GeoPt(lat, lon=lng)
         user_activity.user_prefs = user_prefs.key()
         user_activity.user_maps = user_maps.key()
         
         if marker_icon is not None:
             user_activity.icon = marker_icon.key()
         
         user_activity.put()
         
         try:
             taskqueue.add(url='/task/build_tag_index', params={'map_id': map_id})
         except:
             logging.error('Taskqueue add failed.')
             
     elif mode == 'delete':
         user_maps.visible = False
         user_maps.put()
         return self.redirect('/user/home')
         
     return self.redirect('/map/%s' % map_id)
Exemplo n.º 3
0
 def get(self, map_id):
     user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
     if user_maps is None:
         return self.error(404)
     
     user = users.get_current_user()
     
     if user_maps.user_prefs.google_account != user:
         return self.redirect('/map/%s' % map_id)
     
     template_values = {
         'map_title': user_maps.map_title,
         'map_id': map_id
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/map/map_edit_title.html')
     self.response.out.write(template.render(path, template_values))
Exemplo n.º 4
0
 def post(self, map_id):
     mode = self.request.get('mode')
     
     user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
     if user_maps is None:
         return self.error(404)
     
     user = users.get_current_user()
     
     if user_maps.user_prefs.google_account != user:
         return self.redirect('/map/%s' % map_id)
     
     if mode == 'modify':
         map_title = self.request.get('map_title')
         user_maps.map_title = map_title
         user_maps.put()
         
     self.redirect('/map/%s' % map_id)
Exemplo n.º 5
0
    def post(self):
        map_id = self.request.get("map_id")

        user_maps = UserMaps.all().filter("visible =", True).filter("map_id =", map_id).get()
        if user_maps is None:
            logging.error("map_id not found.")
            return

        user_activity_list = UserActivity.all().filter("user_maps =", user_maps.key()).fetch(100)
        if len(user_activity_list) > 0:
            index = {}
            for user_activity in user_activity_list:
                if user_activity.tags is not None:
                    for tag in user_activity.tags.split(","):
                        if len(tag) > 0:
                            # logging.info('Tag: %s' % tag)
                            if tag in index:
                                activity_id_list = index[tag]
                                activity_id_list.append(str(user_activity.key().id()))
                            else:
                                activity_id_list = []
                                activity_id_list.append(str(user_activity.key().id()))
                                index[tag] = activity_id_list

            user_activity_tag_index_list = UserActivityTagIndex.all().filter("user_maps =", user_maps.key()).fetch(500)
            if len(user_activity_tag_index_list) > 0:
                logging.info("Clear Index: %d" % len(user_activity_tag_index_list))
                for user_activity_tag_index in user_activity_tag_index_list:
                    memcache.delete("tag_id_list_%f" % user_activity_tag_index.key().id())
                    user_activity_tag_index.delete()

                memcache.delete("tag_index_%s" % map_id)

            for tag, activity_id_list in index.items():
                user_activity_tag_index_list = UserActivityTagIndex()
                user_activity_tag_index_list.user_maps = user_maps.key()
                user_activity_tag_index_list.tag = tag
                user_activity_tag_index_list.user_activity_id_list = ",".join(activity_id_list)
                user_activity_tag_index_list.count = len(activity_id_list)
                user_activity_tag_index_list.put()

            logging.info("Add Index: %d" % len(index))
Exemplo n.º 6
0
    def get(self):
        
        user = users.get_current_user()
        user_prefs = UserPrefs.all().filter('google_account =', user).get()
        if user_prefs is None:
            return self.error(404)
        
        user_maps = UserMaps.all().filter('visible =', True).filter('user_prefs =', user_prefs.key()).fetch(100)

        nickname = user.nickname()
        logout_url = users.create_logout_url('/')

        template_values = {
            'map_list': user_maps,
            'nickname': nickname,
            'logout_url': logout_url
        }
        
        path = os.path.join(os.path.dirname(__file__), 'templates/user/home.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 7
0
 def post(self, map_id):
     user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
     if user_maps is None:
         return self.error(404)
     
     marker_id = self.request.get('marker_id')
     user = users.get_current_user()
     
     user_activity = UserActivity.get_by_id(int(marker_id))
     if user_activity is None:
         return self.error(404)
     
     if user_activity.user_prefs.google_account != user:
         return self.redirect('/map/%s' % map_id)
     
     name = self.request.get('name')
     tags = self.request.get('tags')
     icon = self.request.get('icon')
     
     marker_icon = None
     if icon != '':
         marker_icon = MarkerIcon.get_by_id(int(icon))
     
     tags = tags.replace(u'、', ',').replace(' ', ',').replace(u' ', ',')
     
     lat = self.request.get('lat')
     lng = self.request.get('lng')
     
     user_activity.name = name
     user_activity.tags = tags
     user_activity.geo = db.GeoPt(lat, lon=lng)
     
     if marker_icon is not None:
         user_activity.icon = marker_icon.key()
     
     user_activity.put()
     
     memcache.delete('marker_data_%s' % marker_id)
     
     self.redirect('/map/%s' % map_id)
Exemplo n.º 8
0
 def post(self):
     
     map_id = self.request.get('map_id')
     map_title = self.request.get('map_title')
     
     if map_title == '':
         map_title = map_id
     
     user = users.get_current_user()
     
     user_prefs = UserPrefs.all().filter('google_account =', user).get()
     if user_prefs is None:
         user_prefs = UserPrefs()
         user_prefs.google_account = user
         user_prefs.put()
     
     user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
     if user_maps is None and map_id != '':
         user_maps = UserMaps()
         user_maps.map_id = map_id
         user_maps.map_title = map_title
         user_maps.user_prefs = user_prefs
         user_maps.visible = True
         user_maps.put()
         
         self.redirect('/map/%s' % map_id)
         
     else:
         template_values = {
             'map_id': map_id,
             'map_title': map_title,
             'message': 'そのマップIDは使用できませんできした。'
         }
     
         path = os.path.join(os.path.dirname(__file__), 'templates/user/create.html')
         self.response.out.write(template.render(path, template_values))
Exemplo n.º 9
0
 def get(self, map_id):
     
     user_maps = UserMaps.all().filter('map_id =', map_id).filter('visible =', True).get()
     if user_maps is None:
         return self.error(404)
     
     map_title = user_maps.map_title
     
     lat = ''
     lng = ''
     if user_maps.home_geo is not None:
         lat = user_maps.home_geo.lat
         lng = user_maps.home_geo.lon
     
     user_activity_list = UserActivity.all().filter('user_maps =', user_maps.key()).order('-created_at').fetch(200)
     activity_list = []
     activity_id_list = []
     available_icon_list = []
     for user_activity in user_activity_list:
         
         icon_id = ''
         if user_activity.icon is not None:
             icon_id = user_activity.icon.key().id()
             available_icon_list.append({'id': icon_id, 'name': user_activity.icon.name})
         
         created_at = user_activity.created_at + datetime.timedelta(hours=9)
             
         activity_list.append({'id': user_activity.key().id(), 'name': user_activity.name, 'tags': user_activity.tags, 'icon': icon_id, 'lat': user_activity.geo.lat, 'lng': user_activity.geo.lon, 'created_at': created_at.strftime('%Y-%m-%d %H:%M:%S (JST)')})
         
         activity_id_list.append(str(user_activity.key().id()))
     
     user = users.get_current_user()
     if user:
         url = users.create_logout_url('/map/%s' % map_id)
     else:
         url = users.create_login_url('/map/%s' % map_id)
     
     icon_list = None
     map_owner = False
     if user is not None:
         user_prefs = UserPrefs.all().filter('google_account =', user).get()
         if user_prefs is not None:
             user_maps = UserMaps.all().filter('map_id =', map_id).filter('user_prefs =', user_prefs.key()).get()
             if user_maps is not None:
                 map_owner = True
                 marker_icon_list = MarkerIcon.all().filter('user_prefs =', user_prefs.key()).filter('visible =', True).fetch(100)
                 icon_list = []
                 for marker_icon in marker_icon_list:
                     icon_list.append({'id': marker_icon.key().id(), 'name': marker_icon.name})
     
     mode = self.request.get('mode')
     
     template_values = {
         'map_title': map_title,
         'map_id': map_id,
         'lat': lat,
         'lng': lng,
         'activity_list': activity_list,
         'activity_id_list': ','.join(activity_id_list),
         'icon_list': icon_list,
         'available_icon_list': available_icon_list,
         'map_owner': map_owner,
         'login': user and True or False,
         'url': url,
         'mode': mode
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/map/map.html')
     self.response.out.write(template.render(path, template_values))
Exemplo n.º 10
0
 def get(self, map_id):
     
     user_maps = UserMaps.all().filter('visible =', True).filter('map_id =', map_id).get()
     if user_maps is None:
         return self.error(404)
     
     lat = ''
     lng = ''
     if user_maps.home_geo is not None:
         lat = user_maps.home_geo.lat
         lng = user_maps.home_geo.lon
     
     marker_id = self.request.get('marker_id')
     user = users.get_current_user()
     
     user_activity = UserActivity.get_by_id(int(marker_id))
     if user_activity is None:
         return self.error(404)
     
     if user_activity.user_prefs.google_account != user:
         return self.redirect('/map/%s' % map_id)
     
     icon_id = ''
     if user_activity.icon is not None:
         icon_id = user_activity.icon.key().id()
     
     activity_list = []
     activity_list.append({'id': user_activity.key().id(), 'name': user_activity.name, 'tags': user_activity.tags, 'icon': icon_id, 'lat': user_activity.geo.lat, 'lng': user_activity.geo.lon})
     
     if user:
         url = users.create_logout_url('/map/%s' % map_id)
     else:
         url = users.create_login_url('/map/%s' % map_id)
     
     icon_list = None
     map_owner = False
     if user is not None:
         user_prefs = UserPrefs.all().filter('google_account =', user).get()
         if user_prefs is not None:
             user_maps = UserMaps.all().filter('map_id =', map_id).filter('user_prefs =', user_prefs.key()).get()
             if user_maps is not None:
                 map_owner = True
                 marker_icon_list = MarkerIcon.all().filter('user_prefs =', user_prefs.key()).filter('visible =', True).fetch(100)
                 icon_list = []
                 for marker_icon in marker_icon_list:
                     icon_list.append({'id': marker_icon.key().id(), 'name': marker_icon.name})
     
     template_values = {
         'map_title': user_maps.map_title,
         'map_id': map_id,
         'lat': lat,
         'lng': lng,
         'activity_list': activity_list,
         'icon_list': icon_list,
         'map_owner': map_owner,
         'login': user and True or False,
         'url': url
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/map/map_edit.html')
     self.response.out.write(template.render(path, template_values))