Example #1
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
Example #2
0
def _groupmanageresponder(request, page_num=None, adict={}):
	''' 
		This method provides a mechanism for and admin user to mange groups.
		The decorator ensures that the user is an admin before proceeding. The
		page lists a paginated view of current groups.  add allows the admin to
		add more groups
	'''

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

	# The template vars
	info_dict = {'aliases':aliases_page,
				 'collection': acollection,
				 'domains': domains,
				 'page':'gmanage',
				 'mode':mode,
				 'is_domain':True,
				 'thistemplate':thistemplate}

	# update the template vars
	info_dict.update(adict)

	return render_to_response('admin/groupmanage.html', info_dict,
							  context_instance=RequestContext(request))