Beispiel #1
0
def app_context(request):
    """
    Adds context data that is shared across the Facebook app.
    """
    if not in_facebook_app(request):
        return {}

    ctx = {
        'FACEBOOK_DOWNLOAD_URL': settings.FACEBOOK_DOWNLOAD_URL,
        'FACEBOOK_APP_ID': settings.FACEBOOK_APP_ID,
        'FACEBOOK_CLICK_GOAL': settings.FACEBOOK_CLICK_GOAL
    }

    # Add account link form.
    if not request.user.is_linked:
        ctx['account_link_form'] = FacebookAccountLinkForm()

    if is_logged_in(request):
        # Add newsletter form to en-US
        if request.locale.startswith('en'):
            ctx['newsletter_form'] = NewsletterSubscriptionForm(
                request.user, auto_id='newsletter_%s')

        # Add notifications
        ctx['app_notifications'] = (AppNotification.objects.filter(
            user=request.user))

    return ctx
def app_context(request):
    """
    Adds context data that is shared across the Facebook app.
    """
    if not in_facebook_app(request):
        return {}

    ctx = {
        "FACEBOOK_DOWNLOAD_URL": settings.FACEBOOK_DOWNLOAD_URL,
        "FACEBOOK_APP_ID": settings.FACEBOOK_APP_ID,
        "FACEBOOK_CLICK_GOAL": settings.FACEBOOK_CLICK_GOAL,
    }

    # Add account link form.
    if not request.user.is_linked:
        ctx["account_link_form"] = FacebookAccountLinkForm()

    if is_logged_in(request):
        # Add newsletter form to en-US
        if request.locale.startswith("en"):
            ctx["newsletter_form"] = NewsletterSubscriptionForm(request.user, auto_id="newsletter_%s")

        # Add notifications
        ctx["app_notifications"] = AppNotification.objects.filter(user=request.user)

    return ctx
Beispiel #3
0
    def process_request(self, request):
        # Exit early if we are not in the Facebook app section of the site to
        # avoid clashing with the Django auth middleware.
        if not in_facebook_app(request):
            return None

        # Default to an anonymous user.
        request.user = AnonymousFacebookUser()
        locale = None
        try:
            user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            request.user = user
            locale = user.locale
        except (FacebookUser.DoesNotExist, KeyError):
            pass

        if locale is None:
            # Since we can't get their locale from their user data, we'll use
            # funfactory's prefixer instead.
            prefixer = Prefixer(request)
            locale = prefixer.get_language()

        activate_locale(request, locale)
Beispiel #4
0
    def process_request(self, request):
        # Exit early if we are not in the Facebook app section of the site to
        # avoid clashing with the Django auth middleware.
        if not in_facebook_app(request):
            return None

        # Default to an anonymous user.
        request.user = AnonymousFacebookUser()
        locale = None
        try:
            user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            request.user = user
            locale = user.locale
        except (FacebookUser.DoesNotExist, KeyError):
            pass

        if locale is None:
            # Since we can't get their locale from their user data, we'll use
            # funfactory's prefixer instead.
            prefixer = Prefixer(request)
            locale = prefixer.get_language()

        activate_locale(request, locale)
Beispiel #5
0
def view_404(request):
    template = '404.html'
    if in_facebook_app(request):
        template = 'facebook/error.html'

    return render(request, template, status=404)
Beispiel #6
0
def view_500(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=500)
    else:
        return server_error(request)
Beispiel #7
0
def handler404(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=404)
    else:
        return page_not_found(request)
Beispiel #8
0
def handler500(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=500)
    else:
        return server_error(request)
Beispiel #9
0
def handler404(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=404)
    else:
        return page_not_found(request)