def handle_profile(request, schema, **kwargs): url_format = "/{screen_name}" prev_url = None next_url = None # TODO: enforce stricter validity checking on offset and limit schema.offset = schema.offset or 0 schema.limit = schema.limit or 25 screen_name = schema.screen_name ajax = schema.ajax mobile = schema.mobile del schema.ajax del schema.mobile friends = [] followers = [] if ajax and schema.user_id is not None: user = None user_id = schema.user_id else: if TRAVIS: user = travis_test.user else: user = kwargs.get('user', stampedAPIProxy.getAccountByScreenName(schema.screen_name)) user_id = user['user_id'] # simple sanity check validation of user_id if utils.tryGetObjectId(user_id) is None: raise StampedInputError("invalid user_id") #utils.log(pprint.pformat(schema.dataExport())) schema_data = schema.dataExport() del schema_data['screen_name'] schema_data['user_id'] = user_id if TRAVIS: stamps = travis_test.stamps else: stamps = stampedAPIProxy.getUserStamps(schema_data) if user is None: user = { 'user_id' : user_id } if len(stamps) > 0: user2 = stamps[0]['user'] user2_id = user2['user_id'] if user2_id is None or user2_id != user_id: raise StampedInputError("mismatched user_id") else: user.update(user2) else: user = stampedAPIProxy.getAccount(user_id) if user['user_id'] is None or user['user_id'] != user_id: raise StampedInputError("mismatched user_id") """ if not (ajax | mobile): friends = stampedAPIProxy.getFriends (user_id, limit=3) followers = stampedAPIProxy.getFollowers(user_id, limit=3) friends = shuffle_split_users(friends) followers = shuffle_split_users(followers) """ # modify schema for purposes of next / prev gallery nav links schema.ajax = True schema.user_id = user['user_id'] if schema.offset > 0: prev_url = format_url(url_format, schema, { 'offset' : max(0, schema.offset - schema.limit), }) if len(stamps) >= schema.limit: next_url = format_url(url_format, schema, { 'offset' : schema.offset + len(stamps), }) #utils.log("PREV: %s" % prev_url) #utils.log("NEXT: %s" % next_url) title = "Stamped - %s" % user['screen_name'] sdetail = kwargs.get('sdetail', None) stamp = kwargs.get('stamp', None) entity = kwargs.get('entity', None) url = request.build_absolute_uri(request.get_full_path()) body_classes = get_body_classes('profile', schema) if sdetail is not None: body_classes += " sdetail_popup"; #if not mobile: # body_classes += " wide-body"; page = 'profile' if sdetail is not None: page = 'sdetail' if entity is not None: title = "%s - %s" % (title, stamp['entity']['title']) template = 'profile.html' return stamped_render(request, template, { 'user' : user, 'stamps' : stamps, 'page' : page, 'friends' : friends, 'followers' : followers, 'prev_url' : prev_url, 'next_url' : next_url, 'body_classes' : body_classes, 'sdetail' : sdetail, 'stamp' : stamp, 'entity' : entity, 'title' : title, 'URL' : url, 'mobile' : mobile, }, preload=[ 'page', 'user', 'sdetail', 'mobile' ])
def handle_map(request, schema, **kwargs): screen_name = schema.screen_name stamp_id = schema.stamp_id ajax = schema.ajax lite = schema.lite mobile = schema.mobile schema.offset = schema.offset or 0 schema.limit = 25 if lite else 1000 # TODO: customize this uri = request.get_full_path() url = request.build_absolute_uri(uri) if mobile: redirect_uri = "/%s?category=place" % screen_name redirect_url = request.build_absolute_uri(redirect_uri) logs.info("redirecting mobile map from '%s' to: '%s'" % (uri, redirect_uri)) return HttpResponseRedirect(redirect_url) del schema.stamp_id del schema.ajax del schema.lite del schema.mobile user = stampedAPIProxy.getUser(dict(screen_name=schema.screen_name)) user_id = user['user_id'] # simple sanity check validation of user_id if utils.tryGetObjectId(user_id) is None: raise StampedInputError("invalid user_id") s = schema.dataExport() del s['screen_name'] s['user_id'] = user_id s['category'] = 'place' stamps = stampedAPIProxy.getUserStamps(s) stamps = filter(lambda s: s['entity'].get('coordinates', None) is not None, stamps) if len(stamps) <= 0: redirect_uri = "/%s?category=place" % screen_name redirect_url = request.build_absolute_uri(redirect_uri) logs.info("redirecting empty map from '%s' to: '%s'" % (uri, redirect_uri)) return HttpResponseRedirect(redirect_url) for stamp in stamps: subcategory = stamp['entity']['subcategory'] if '_' in subcategory: stamp['entity']['subcategory'] = subcategory.replace('_', ' ') body_classes = get_body_classes('map collapsed-header', schema) title = "Stamped - %s map" % user['screen_name'] return stamped_render(request, 'map.html', { 'user' : user, 'stamps' : stamps, 'lite' : lite, 'page' : 'map', 'stamp_id' : stamp_id, 'body_classes' : body_classes, 'title' : title, 'URL' : url, 'mobile' : mobile, }, preload=[ 'page', 'user', 'stamps', 'stamp_id', 'lite' ])