app/django/contrib/sites/managers.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 08 Feb 2009 23:55:44 +0000
changeset 1255 9fe8c6c54933
parent 54 03e267d67478
permissions -rw-r--r--
Redone the listing in group_app.py. There is now a list_self that only shows the group application of the current user in the given a scope. The redirects point to edit or applicant when necessary. Review_overview will show all the group applications that can be reviewed in the given scope, the redirect points to review for all statusses. And list will just show all the group applications and redirect you to edit. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed

from django.conf import settings
from django.db import models
from django.db.models.fields import FieldDoesNotExist

class CurrentSiteManager(models.Manager):
    "Use this to limit objects to those associated with the current site."
    def __init__(self, field_name='site'):
        super(CurrentSiteManager, self).__init__()
        self.__field_name = field_name
        self.__is_validated = False

    def get_query_set(self):
        if not self.__is_validated:
            try:
                self.model._meta.get_field(self.__field_name)
            except FieldDoesNotExist:
                raise ValueError, "%s couldn't find a field named %s in %s." % \
                    (self.__class__.__name__, self.__field_name, self.model._meta.object_name)
            self.__is_validated = True
        return super(CurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})