def get_basic_context(request, is_mobile = False): """ get the context with various standard stuff preinitialized """ ctx = {} ctx['REMOTE_ADDR'] = request.META['REMOTE_ADDR'] ctx['remote_owner_token'] = get_owner_token(request) ctx['DEV_MODE'] = True next_after_accept = request.REQUEST.get('next_after_accept', None) if next_after_accept and re.match(r"/thread/[0-9]+", next_after_accept): ctx['next_after_accept'] = next_after_accept ctx['in_thread_view'] = request.REQUEST.get('in_thread_view', None)=="1" ctx['requestpath'] = request.path loc = get_current_loc(request) ctx['loc'] = loc ctx['is_mobile'] = is_mobile ctx['radius_options'] = c.RADIUS_MENU ctx['more_available'] = False if loc: ctx['loc_fixed'] = "%0.5f,%0.5f" % (loc.latitude, loc.longitude) ctx['MAX_POST_LEN'] = MAX_POST_LEN ctx['SHOW_REPLY_COUNT'] = SHOW_REPLY_COUNT ctx['rounding_val'] = get_current_rounding(request) ctx['radius'] = get_current_radius(request) ctx['nice_radius'] = c.RADII_TEXT[c.RADII.index(ctx['radius'])] ctx['round_options'] = c.ROUND_OPTIONS ctx['THUMB_WIDTH'] = THUMB_WIDTH ctx['THUMB_HEIGHT'] = THUMB_HEIGHT ctx['SLIDE_WIDTH '] = SLIDE_WIDTH ctx['SLIDE_HEIGHT'] = SLIDE_HEIGHT ctx['sitename'] = settings.SITENAME ctx['tagline'] = 'Foursquare meets 4chan' ctx.update(csrf(request)) return ctx
def add_latest_to_context(request, ctx): """ add the data needed to render the main page or mobile main page to the context """ ctx['posts'] = get_latest(ctx['loc'], radius=get_current_radius(request)) ctx['threadmap'] = build_thread_map(ctx['posts'], truncate=SHOW_REPLY_COUNT) # fencepost error here: if we have exactly 50 posts, # this will say there are more, even though there aren't. ctx['more_available'] = len(ctx['posts']) >= DEFAULT_POST_COUNT
def mobile_prefs(request): ''' get the prefs page. note that all the smarts are in js ''' if request.POST.get("set", None) == "1": resp = HttpResponse(content="Preferences set! Redirecting...", status=303) resp["Location"] = "/m/" #resp.set_cookie('round', get_current_rounding(request), # max_age = c.OWNER_TOKEN_EXPIRES, # expires = c.OWNER_TOKEN_EXPIRES) resp.set_cookie('radius', get_current_radius(request), max_age = c.OWNER_TOKEN_EXPIRES, expires = c.OWNER_TOKEN_EXPIRES) return resp ctx = get_basic_context(request, True) return render_to_response('mobile/prefs.html', ctx)
def get_latest_ajax(request): """ get the latest via ajax """ ctx = get_basic_context(request) if str(request.REQUEST.get("is_mobile", "0")) == "1": ctx['is_mobile'] = True # force it to be true skip = [default_int(item, None) for item in \ request.REQUEST.get("skip", "").split(",")] postids = [default_int(item, None) for item in \ request.REQUEST.get("postids", "").split(",")] use_only_these = not not request.REQUEST.get("only_these_postids", False) skip = [item for item in skip if item] # fixme: check loc cookie! # FIXME: radius!! ctx['posts'] = get_latest(ctx['loc'], radius=get_current_radius(request), skiplist = skip, includelist=postids, only_these_postids = use_only_these) if request.REQUEST.get('return_empty_if_none', False) and not ctx['posts']: return HttpResponse(status=204, content="") truncate_to = 0 if request.REQUEST.get('show_all_replies', False) \ else SHOW_REPLY_COUNT ctx['threadmap'] = build_thread_map(ctx['posts'], truncate=truncate_to) if request.REQUEST.get('json', False): # note that remote_owner_token is *ignored* in the multipost view remote_owner_token = get_owner_token(request) return HttpResponse(\ wrap_json_posts(ctx['loc'], serialize_posts_to_list(\ ctx['posts'], ctx['threadmap'], remote_owner_token))) else: return render_to_response('posts_div_contents.html', ctx)