Exemplo n.º 1
0
def _domainmanageresponder(request, page_num=None, adict={}):

	''' 
		This method provides a mechanism for and admin user to manage domains.
		The decorator ensures that the user is an admin before proceeding. The
		page lists a paginated view of current domains.  add allows the admin
		to add more domains
	'''

	# Create model instance
	model = AdminModel()
	# default mode
	mode ='add'
	# Get all the domains in the 
	# system that are not admins
	domains = list(model.getalldomains())
	# Set page based on passed in number or session
	page = page_num or request.session.get('d_page',1)
	# Set the page number in the session
	request.session['d_page'] = page
	# Get collection and current page
	dcollection, domains_page = paginatorwrapper(domains, page, per_page=items_per_page, orphans=1)

	# The template vars
	info_dict = {'domains':domains_page,
				 'collection': dcollection,
				 'page':'dmanage',
				 'mode':mode,
				 'thistemplate':thistemplate}
	# update the template vars
	info_dict.update(adict)

	return render_to_response('admin/domainmanage.html',
							  info_dict,
							  context_instance=RequestContext(request))
Exemplo n.º 2
0
class GroupAdd(forms.Form):

	def __init__(self, groupname=None, kargs=None):
		super(GroupAdd,self).__init__(kargs)
		self.extras = {}
		self.model = AdminModel()
		# Get all available domains
		domains = self.model.getalldomains()
		if domains:
			self.fields['domain'].choices = [domain.domainname for domain in domains]
		aliases = self.model.getallaliases()
		if aliases:
			self.fields['alias'].others = [alias.aliasname for alias in aliases] 
			self.fields['alias'].exclude = groupname 

	alias = UniqueField(label="aliases", required=True, max_length=64,
						others=[], exclude=None, b_spaces=False)
	
	domain = MultipleOptionField(label="Domain", required=True, choices=[],
								 b_spaces=False)

	notes = forms.CharField(label="notes", required=False)

	def clean_alias(self):
		cleaned_data = super(GroupAdd, self).clean()
		try:
			alias = cleaned_data['alias']
		except KeyError:
			pass
		else:
			if not _validlocalpart (alias):
				raise forms.ValidationError('Please enter a valid group.' )

			return alias
Exemplo n.º 3
0
def _usermanageresponder(request, page_num=None, adict={}):
	''' 
		This method provides a mechanism for and admin user to mange people.
		The decorator ensures that the user is an admin before proceeding. The
		page lists a paginated view of current users.  add allows the admin to
		add more users
	'''
	
	# Create model instance
	model = AdminModel()
	# default mode
	mode ='add'
	# Get all the users in the 
	# system that are not admins
	users = list(model.getallusers())
	# Set page based on passed in number or session
	page = page_num or request.session.get('u_page',1)
	# Set the page number in the session
	request.session['u_page'] = page
	# Defaults
	ucollection, users_page = paginatorwrapper(users, page, per_page=items_per_page, orphans=1)
	# Get all available domains
	domains = list(model.getalldomains())
	# Generate a password
	generated_pass = _gen_pass()

	# The template vars
	info_dict = {'users':users_page,
				 'collection': ucollection,
				 'domains':domains,
				 'page':'umanage',
				 'gen_pass':generated_pass,
				 'mode':mode,
				 'types':types,
				 'thistemplate':thistemplate}

	# update the template vars
	info_dict.update(adict)

	return render_to_response('admin/usermanage.html', info_dict,
							   context_instance=RequestContext(request))
Exemplo n.º 4
0
class DomainEdit(forms.Form):

	def __init__(self, domain_name, kargs=None):
		super(DomainEdit,self).__init__(kargs)
		self.model = AdminModel()
		self.fields['domain'].others = [domain.domainname for domain in self.model.getalldomains()]
		self.fields['domain'].exclude = domain_name

	domain = UniqueField(label="Domain", required=True, max_length=128,
						 others=[], b_spaces=False)
	
	def clean_domain (self):
		cleaned_data = super(DomainEdit, self).clean()
		try:
			domain = cleaned_data['domain']
		except KeyError:
			pass
		else:
			if not _validdomain (domain):
				raise forms.ValidationError('Please enter a valid domain.' )

			return domain
Exemplo n.º 5
0
class UserAdd(forms.Form):

	def __init__(self, kargs=None):
		super(UserAdd,self).__init__(kargs)
		self.model = AdminModel()
		self.extras = {}
		self.fields['domain'].choices = [domain.domainname for domain in self.model.getalldomains()]
		self.fields['typer'].choices = [typer for typer in types]




	fullname = forms.CharField(label="fullname", 
								 max_length=32,
								 min_length=3,
								 required=True)

	userid = forms.CharField(label="userid", 
								 max_length=64,
								 min_length=1,
								 required=True)

	password = forms.CharField(label="password", 
								 max_length=64,
								 required=True)
	
	role = forms.CharField(label="role", 
								 max_length=64,
								 required=False)
	
	domain = MultipleOptionField(label="Domain", required=True, choices=[],
								 b_spaces = False)

	typer = MultipleOptionField(label="type", required=True, choices=[])

	notes = forms.CharField(label="notes", required=False)

	def clean_userid (self):
		cleaned_data = super(UserAdd, self).clean()
		try:
			userid = cleaned_data['userid']
		except KeyError:
			pass
		else:
			if _hasspaces (userid):
				raise forms.ValidationError('This field cannot contain spaces.' )

			if not _validlocalpart (userid):
				raise forms.ValidationError('Please enter a valid userid.' )

			return userid


	def clean(self):
		cleaned_data = super(UserAdd, self).clean()

		try:
			value = cleaned_data['userid']
		except KeyError:
			pass
		else:
			if _validascii(value):
				self.checkusername(cleaned_data)

			# If any errors were picked up raise a validation error so that
			# the form does not validate.
			if self.extras:
				# This error message is generic as the only purpose is to
				# raise *an* error.
				raise forms.ValidationError('General Form Errors have occured.')

		return cleaned_data

	def _createError(self,key,error_message):

		errorList = ErrorList()
		errorList.append(error_message)
		self.extras[key] = errorList

	def checkusername(self, cleaned_data):
	
		try:
			userid = cleaned_data['userid']
			domain = cleaned_data['domain']
		except KeyError:
			# we dont worry about 
			# key error as it implies and error
			# has already been caught elsewhere
			pass 
		else:
			user = self.model.getuser(userid, domain)
			if user and user.userid:
				self._createError('userid','This user already exists.')