Esempio n. 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
Esempio n. 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()
        if SESSION_KEY in request.session:
            try:
                user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            except FacebookUser.DoesNotExist:
                return None
            request.user = user

            # Activate locale now that we know who the user is.
            activate_locale(request, user.locale)
Esempio n. 4
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()

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

    return ctx
Esempio n. 5
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)
Esempio n. 6
0
 def process_request(self, request):
     request._fb_debug = (getattr(settings, 'FACEBOOK_DEBUG', False) and
                          in_facebook_app(request))
Esempio n. 7
0
def view_500(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=500)
    else:
        return server_error(request)
Esempio n. 8
0
def view_404(request):
    template = '404.html'
    if in_facebook_app(request):
        template = 'facebook/error.html'

    return render(request, template, status=404)
Esempio n. 9
0
def view_500(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=500)
    else:
        return server_error(request)
Esempio n. 10
0
def view_404(request):
    template = '404.html'
    if in_facebook_app(request):
        template = 'facebook/error.html'

    return render(request, template, status=404)
Esempio n. 11
0
def view_404(request):
    if in_facebook_app(request):
        return render(request, 'facebook/error.html', status=404)
    else:
        return page_not_found(request)