class MakePublicContainer(forms.SelfHandlingForm): index_object_name = forms.ChoiceField(label="Object used for index.html") css_object_name = forms.ChoiceField( label="Object used as a css file for listing Container") error = forms.CharField(max_length="255", label="file suffix to be used when error occurs", required=False) public_html = forms.BooleanField(label="Published as HTML", required=False) use_css_in_listing = forms.BooleanField( label="Use CSS file for listing Container", required=False) html_listing = forms.BooleanField(label="Enable Container listing", required=False) container_name = forms.CharField(widget=forms.HiddenInput()) def __init__(self, *args, **kwargs): objects = kwargs.pop('objects') headers = kwargs.pop('headers') super(MakePublicContainer, self).__init__(*args, **kwargs) self.fields['index_object_name'].choices = objects self.fields['css_object_name'].choices = objects for name, value in headers: name = name.lower() if name == 'x-container-meta-web-index': self.fields['public_html'].initial = True self.fields['index_object_name'].initial = (value, value) if name == 'x-container-meta-web-listing': self.fields['html_listing'].initial = value == 'true' if name == 'x-container-meta-web-listing-css': self.fields['use_css_in_listing'].initial = True self.fields['css_object_name'].initial = (value, value) if name == 'x-container-meta-web-error': self.fields['error'].value = value def handle(self, request, data): hdrs = {} index_object_name = data['index_object_name'] css_object_name = data['css_object_name'] public_html = data['public_html'] error = data['error'] html_listing = data['html_listing'] use_css_in_listing = data['use_css_in_listing'] container_name = data['container_name'] for name in ['Index', 'Listing', 'Listing-Css', 'Error']: hdrs['X-Container-Meta-Web-' + name] = '' if public_html: hdrs['X-Container-Meta-Web-Index'] = index_object_name if html_listing: hdrs['X-Container-Meta-Web-Listing'] = 'true' if use_css_in_listing: hdrs['X-Container-Meta-Web-Listing-Css'] = css_object_name if error: hdrs['X-Container-Meta-Web-Error'] = error api.swift_set_container_info(request, container_name, hdrs) return shortcuts.redirect("dash_containers", request.user.tenant_id)
class UpdateTenant(forms.SelfHandlingForm): id = forms.CharField( label=_("ID"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) name = forms.CharField( label=_("Name"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) description = forms.CharField(widget=forms.widgets.Textarea(), label=_("Description")) enabled = forms.BooleanField(required=False, label=_("Enabled")) def handle(self, request, data): try: LOG.info('Updating tenant with id "%s"' % data['id']) api.tenant_update(request, data['id'], data['name'], data['description'], data['enabled']) messages.success(request, _('%s was successfully updated.') % data['name']) except api_exceptions.ApiException, e: LOG.exception( 'ApiException while updating tenant\n' 'Id: "%s", Name: "%s", Description: "%s", Enabled "%s"' % (data['id'], data['name'], data['description'], data['enabled'])) messages.error(request, _('Unable to update tenant: %s') % e.message) return redirect('syspanel_tenants')
class CreateTenant(forms.SelfHandlingForm): name = forms.CharField(label="Name") description = forms.CharField(widget=forms.widgets.Textarea(), label="Description") enabled = forms.BooleanField(label="Enabled", required=False, initial=True) def handle(self, request, data): try: LOG.info('Creating tenant with name "%s"' % data['name']) api.tenant_create(request, data['name'], data['description'], data['enabled']) messages.success(request, '%s was successfully created.' % data['name']) except api_exceptions.ApiException, e: LOG.exception('ApiException while creating tenant\n' 'Id: "%s", Description: "%s", Enabled "%s"' % (data['name'], data['description'], data['enabled'])) messages.error(request, 'Unable to create tenant: %s' % (e.message)) return redirect('syspanel_tenants')
class MakePublicContainer(forms.SelfHandlingForm): index_object_name = forms.ChoiceField(label="Object used for index.html") css_object_name = forms.ChoiceField( label="Object used as a css file for listing Container") error = forms.CharField(max_length="255", label="file suffix to be used when error occurs", required=False) public_html = forms.BooleanField(label="Published as HTML", required=False) use_css_in_listing = forms.BooleanField( label="Use CSS file for listing Container", required=False) html_listing = forms.BooleanField(label="Enable Container listing", required=False) container_name = forms.CharField(widget=forms.HiddenInput()) def __init__(self, *args, **kwargs): objects = kwargs.pop('objects') headers = kwargs.pop('headers') super(MakePublicContainer, self).__init__(*args, **kwargs) self.fields['index_object_name'].choices = objects self.fields['css_object_name'].choices = objects for name, value in headers: name = name.lower() if name == 'x-container-meta-web-index': self.fields['public_html'].initial = True self.fields['index_object_name'].initial = (value, value) if name == 'x-container-meta-web-listings': self.fields['html_listing'].initial = value == 'true' if name == 'x-container-meta-web-listings-css': self.fields['use_css_in_listing'].initial = True self.fields['css_object_name'].initial = (value, value) if name == 'x-container-meta-web-error': self.fields['error'].value = value def handle(self, request, data): hdrs = {} index_object_name = data['index_object_name'] css_object_name = data['css_object_name'] public_html = data['public_html'] error = data['error'] try: error = error.encode('ascii') except Exception, e: messages.error( request, 'Container Public contains non-ASCII character %s' % str(e)) return html_listing = data['html_listing'] use_css_in_listing = data['use_css_in_listing'] container_name = data['container_name'] for name in ['Index', 'Listings', 'Listings-Css', 'Error']: hdrs['X-Container-Meta-Web-' + name] = '' if public_html: hdrs['X-Container-Meta-Web-Index'] = index_object_name if html_listing: hdrs['X-Container-Meta-Web-Listings'] = 'true' if use_css_in_listing: hdrs['X-Container-Meta-Web-Listings-Css'] = css_object_name if error: hdrs['X-Container-Meta-Web-Error'] = error try: api.swift_set_container_info(request, container_name, hdrs) except Exception, e: messages.error( request, 'Unable to set container metadata for public : %s' % str(e)) return