Commit 255d2160 by Kálmán Viktor

request: add help texts

parent 4db2f63c
......@@ -22,9 +22,12 @@
</span>
{% else %}
<div id="vm-request-resource-form">
<div class="alert alert-info text-justify">
{% trans "Changing resources is only possible on virtual machines with STOPPED state. We suggest to turn off the VM after submitting the request otherwise it will be automatically stopped in the future when the request is accepted." %}
</div>
<div class="form-group">
<label>{% trans "Reason" %}*</label>
<textarea class="form-control" name="reason"></textarea>
<textarea class="form-control" name="reason">{% include "request/initials/resources.html" %}</textarea>
</div>
<input type="submit" class="btn btn-success btn-sm"/>
</div>
......
......@@ -67,7 +67,7 @@ from ..forms import (
VmRemoveInterfaceForm,
)
from request.models import TemplateAccessType
from request.forms import LeaseRequestForm
from request.forms import LeaseRequestForm, TemplateRequestForm
from ..models import Favourite
from manager.scheduler import has_traits
......@@ -680,7 +680,7 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
def get_context_data(self, **kwargs):
context = super(VmRenewView, self).get_context_data(**kwargs)
context['lease_request_form'] = LeaseRequestForm()
context['lease_request_form'] = LeaseRequestForm(request=self.request)
return context
......@@ -1047,14 +1047,13 @@ class VmCreate(LoginRequiredMixin, TemplateView):
'template_o': template,
})
else:
from request.forms import TemplateRequestForm
context.update({
'template': 'dashboard/_vm-create-1.html',
'box_title': _('Create a VM'),
'ajax_title': True,
'templates': templates.all(),
'template_access_types': TemplateAccessType.objects.count(),
'form': TemplateRequestForm(),
'form': TemplateRequestForm(request=request),
})
return self.render_to_response(context)
......
......@@ -19,6 +19,8 @@ from django.forms import (
)
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.template import RequestContext
from django.template.loader import render_to_string
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
......@@ -59,19 +61,33 @@ class TemplateAccessTypeForm(ModelForm):
model = TemplateAccessType
class TemplateRequestForm(Form):
class InitialFromFileMixin(object):
def __init__(self, *args, **kwargs):
request = kwargs.pop("request", None)
super(InitialFromFileMixin, self).__init__(*args, **kwargs)
self.initial['reason'] = render_to_string(
self.initial_template,
RequestContext(request, {}),
)
class TemplateRequestForm(InitialFromFileMixin, Form):
template = ModelChoiceField(TemplateAccessType.objects.all(),
label="Template share")
label=_("Template share"))
level = ChoiceField(TemplateAccessAction.LEVELS, widget=RadioSelect,
initial=TemplateAccessAction.LEVELS.user)
reason = CharField(widget=forms.Textarea)
reason = CharField(widget=forms.Textarea, label=_("Reason"))
initial_template = "request/initials/template.html"
class LeaseRequestForm(Form):
lease = ModelChoiceField(LeaseType.objects.all(),
label=_("Lease"))
class LeaseRequestForm(InitialFromFileMixin, Form):
lease = ModelChoiceField(LeaseType.objects.all(), label=_("Lease"))
reason = CharField(widget=forms.Textarea)
initial_template = "request/initials/lease.html"
class ResourceRequestForm(VmResourcesForm):
reason = CharField(widget=forms.Textarea)
......@@ -6,16 +6,16 @@
{% csrf_token %}
{{ form.template|as_crispy_field }}
<div style="font-weight: bold;">Level*</div>
<div style="font-weight: bold;">{% trans "Level" %}*</div>
{% for radio in form.level %}
<div class="myradio" style="display: inline-block; padding-left: 20px;">
<label>
{{ radio }}
<div class="text-muted" style="padding-left: 16px; font-weight: normal;">
{% if forloop.last %}
For users who want to share the template with others.
{% trans "For users who want to share the template with others." %}
{% else %}
For regular users who want to start a virtual machine.
{% trans "For users who want to start a virtual machine." %}
{% endif %}
</div>
</label>
......
{% spaceless %}
{% if LANGUAGE_CODE == "en" %}
Why do you need this lease?
{% else %} {# place your translations here #}
Why do you need this lease?
{% endif %}
{% endspaceless %}
{% spaceless %}
{% if LANGUAGE_CODE == "en" %}
Why do you need these resources?
{% else %} {# place your translations here #}
Why do you need these resources?
{% endif %}
{% endspaceless %}
{% spaceless %}
{% if LANGUAGE_CODE == "en" %}
Why do you need this template?
{% else %} {# place your translations here #}
Why do you need this template?
{% endif %}
{% endspaceless %}
......@@ -133,6 +133,11 @@ class TemplateRequestView(FormView):
form_class = TemplateRequestForm
template_name = "request/request-template.html"
def get_form_kwargs(self):
kwargs = super(TemplateRequestView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs
def form_valid(self, form):
data = form.cleaned_data
user = self.request.user
......@@ -174,6 +179,11 @@ class LeaseRequestView(FormView):
context['vm'] = self.get_vm()
return context
def get_form_kwargs(self):
kwargs = super(LeaseRequestView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs
def form_valid(self, form):
data = form.cleaned_data
user = self.request.user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment