jijo-paulose / django-profile

Automatically exported from code.google.com/p/django-profile
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Context processor for variables related to Site #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
userprofile/context_processors.py
------------
from django.contrib.sites.models import Site

def site(request):
    """Adds site-related context variables to the context.
    """
    current_site = Site.objects.get_current()

    return {
        'SITE_NAME': current_site.name,
        'SITE_DOMAIN': current_site.domain,
        'SITE_URL': "http://www.%s" % (current_site.domain),
    }
------------

Setup on settings file:

* To add 'django.contrib.sites' on INSTALLED_APPS.
* To add:
TEMPLATE_CONTEXT_PROCESSORS += ('userprofile.context_processors.site',)
* Change the data -Site name and site domain- from Site (via Admin or using
fixtures)

And now it's possible use {{ SITE_NAME }}, {{ SITE_DOMAIN }} and {{
SITE_URL }} on the templates.

Original issue reported on code.google.com by jonas....@googlemail.com on 24 Jun 2008 at 10:31

GoogleCodeExporter commented 9 years ago
And to add: 

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS

on settings file.

Original comment by jonas....@googlemail.com on 24 Jun 2008 at 10:43

GoogleCodeExporter commented 9 years ago
This let to add to the emails sent anything as:

-
{% blocktrans %}The {{ SITE_NAME }} team{% endblocktrans %} - {{ SITE_URL }}

Original comment by jonas....@googlemail.com on 24 Jun 2008 at 5:36

GoogleCodeExporter commented 9 years ago
Mmmmm... the idea is good, but I don't think a context processor is needed to
accomplish that.

I have commit a solution to this on trunk. Look at it to see how it's solved.

Original comment by david.ru...@gmail.com on 25 Jun 2008 at 8:20

GoogleCodeExporter commented 9 years ago
I saw the solution on models.py file [1], but does it works on whatever 
template? The
advantage of to use a context processor is that.

By example, django-contact-form is another pluggable application that could use 
these
variables too: {{ SITE_NAME }}, {{ SITE_DOMAIN }}, {{
SITE_URL }}

[1] 
http://code.google.com/p/django-profile/source/browse/trunk/userprofile/models.p
y

Original comment by jonas....@googlemail.com on 29 Jun 2008 at 12:36

GoogleCodeExporter commented 9 years ago
I'm going to add this to the repository. Let me think about it some time.

Original comment by david.ru...@gmail.com on 1 Jul 2008 at 8:05

GoogleCodeExporter commented 9 years ago
I have been thinking about this, and I decided that a pluggable application 
wouldn't
have to depend on a context processor variables. It need to be independent of 
that,
because the main project could have conflicting dependencies with the 
applications
included, in this case django-profile.

Thanks for the report, in any case.

Original comment by david.ru...@gmail.com on 7 Aug 2008 at 2:02