From 4fc0bcdf27fef7f036fb2d8db2643f42a6eba3d6 Mon Sep 17 00:00:00 2001 From: Clint Ecker Date: Tue, 8 Jul 2008 14:55:26 +0000 Subject: [PATCH] Adding the LICENSE, USAGE and making the model optional --- LICENSE | 27 +++++++++++++++++++++++++++ USAGE | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ models.py | 11 ++++++----- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 LICENSE create mode 100644 USAGE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d16322c --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2008, Clint Ecker +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the nor the names of its contributors may +be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/USAGE b/USAGE new file mode 100644 index 0000000..4047438 --- /dev/null +++ b/USAGE @@ -0,0 +1,51 @@ +I manage a lot of Django projects that present slightly-different forms to +users depending on the site/domain they're visiting. There's also a bunch of +custom submission code that differs from form to form, but that's neither here +nor there. + +I need different Google Analytics codes depending on the sites and after +sticking these tags into every single template, I thought it would be cool to +be able to manage these Google analytics accounts from the Django admin page. +I also added a mode of operation that excludes the admin interface altogether +(you can just use the template tag) + +==Two modes of operation== + +Administering and associating codes with Django sites +--------------------------------------------------------- +1. Add the `google_analytics` application to your `INSTALLED_APPS` + section of your `settings.py`. This mode requires that you be using + the Django sites framework too, so make sure you have that set up as + well. + +2. Add `GOOGLE_ANALYTICS_MODEL = True` to your `settings.py` + +3. Run a `./manage.py syncdb` to add the database tables + +4. Go to your project's admin page (usually `/admin/`) and click into a site + objects + +5. You'll now see a new field under the normal site information called + "Analytics Code". In this box you put your unique analytics code for + your project's domain. It looks like `UA-xxxxxx-x` and save the site. + +6. In your base template (usually a `base.html`) insert this tag at the very + top: `{% load analytics %}` + +7. In the same template, insert the following code right before the closing + body tag: `{% analytics %}` + + + +===Just using the template tag=== + +1. Add the `google_analytics` application to your `INSTALLED_APPS` section of + your `settings.py`. + +2. In your base template, usually a `base.html`, insert this tag at the very + top: `{% load analytics %}` + +3. In the same template, insert the following code right before the closing + body tag: `{% analytics "UA-xxxxxx-x" %}` the `UA-xxxxxx-x` is a + unique Google Analytics code for you domain when you sign up for a new + account. diff --git a/models.py b/models.py index f120687..3cdfb8f 100644 --- a/models.py +++ b/models.py @@ -1,9 +1,10 @@ from django.db import models from django.contrib.sites.models import Site -class Analytics(models.Model): - site = models.ForeignKey(Site, edit_inline=models.TABULAR, max_num_in_admin=1, min_num_in_admin=1) - analytics_code = models.CharField(blank=True, max_length=100, core=True) +if getattr(settings, 'GOOGLE_ANALYTICS_MODEL', False): + class Analytics(models.Model): + site = models.ForeignKey(Site, edit_inline=models.TABULAR, max_num_in_admin=1, min_num_in_admin=1) + analytics_code = models.CharField(blank=True, max_length=100, core=True) - def __unicode__(self): - return u"%s" % (self.analytics_code) + def __unicode__(self): + return u"%s" % (self.analytics_code) -- 2.39.5