Add support of Sites
Postponed to Authentic2 in SaaS
Updated by Anonymous about 9 years ago
- we need a middleware which put a site reference into each request (request.site), a cache must be constructed linking domain names to site ids.
- each model should gain a field like this
site = ForeignKey('sites.Site')or like that
sites = ManyToManyField('sites.Site')
- each model visible in the admin should use a ModelAdmin which inherit from a new base class, SiteModelAdmin whose queryset() method should look like this:
def queryset(self, queryset): try: site_field = self.model._meta.get_field('site') or self.model._meta.get('sites') if site_field.name == 'site': q = Q(site=request.site)|Q(site__isnull=True) return queryset.filter(q) else: q = Q(sites=request.site)|Q(site__isnull=True) return queryset.filter(q) except FieldDoesNotExist: return querysetthe goal is to only show object linked to this site
- we should integrate one of the many applications which allow to put django settings in the db
- the settings app must be extended to restrict settings by site
- some caching must be added in order to not touch the db for each access to the settings
- the AdminSite.has_permission() method should be overloaded to only permit staff users linked to the site using a new table to link users to Site objects.
This should maybe be implemented as a different admin site from the main one which should keep access to all object for superusers.
I'm still looking how to force newly created object to be associated to the current site without doing it manually everywhere.