Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #####################
- # models.py
- #####################
- from django.db import models
- from users.models import Employee
- class Domain (models.Model):
- '''A class to handle the domain for services'''
- name = models.CharField(max_length=64)
- is_active = models.BooleanField()
- owner = models.ForeignKey(Employee)
- description = models.TextField(null=True)
- class Meta:
- ordering = ['name']
- def __unicode__(self):
- return self.name
- def get_absolute_url(self):
- return '/services/domains/' + str(self.id)
- def get_service_families(self):
- return self.servicefamily_set.all()
- #####################
- # forms.py
- #####################
- from services.models import Domain
- from django import forms
- from guardian.shortcuts import assign, remove_perm, get_users_with_perms
- class DomainForm(forms.ModelForm):
- class Meta:
- model = Domain
- def save(self, commit=True):
- domain = super(forms.ModelForm, self).save(commit=commit)
- # Remove existing rights on this domain
- users_with_perms = get_users_with_perms(domain)
- for user in users_with_perms:
- remove_perms('update_domain',user,domain)
- # Assign the right to update this domain to the domain owner
- assign('domains.update_domain', domain.owner.user, domain)
- return domain
- #####################
- # forms.py
- #####################
- from django.conf.urls.defaults import *
- from django.views.generic import UpdateView
- from services.models import Domain
- from services.forms import DomainForm
- urlpatterns = patterns('',
- ##################################
- # Domains
- # .... (removed unnecessary lines)
- (r'^domains/(?P<pk>\d+)/update/$', UpdateView.as_view( model=DomainForm, success_url='/services/domains/%(id)s' ), ),
- # ...
- )
Advertisement
Add Comment
Please, Sign In to add comment