Commit 255d2160 by Kálmán Viktor

request: add help texts

parent 4db2f63c
...@@ -22,9 +22,12 @@ ...@@ -22,9 +22,12 @@
</span> </span>
{% else %} {% else %}
<div id="vm-request-resource-form"> <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"> <div class="form-group">
<label>{% trans "Reason" %}*</label> <label>{% trans "Reason" %}*</label>
<textarea class="form-control" name="reason"></textarea> <textarea class="form-control" name="reason">{% include "request/initials/resources.html" %}</textarea>
</div> </div>
<input type="submit" class="btn btn-success btn-sm"/> <input type="submit" class="btn btn-success btn-sm"/>
</div> </div>
......
...@@ -67,7 +67,7 @@ from ..forms import ( ...@@ -67,7 +67,7 @@ from ..forms import (
VmRemoveInterfaceForm, VmRemoveInterfaceForm,
) )
from request.models import TemplateAccessType from request.models import TemplateAccessType
from request.forms import LeaseRequestForm from request.forms import LeaseRequestForm, TemplateRequestForm
from ..models import Favourite from ..models import Favourite
from manager.scheduler import has_traits from manager.scheduler import has_traits
...@@ -680,7 +680,7 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView): ...@@ -680,7 +680,7 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(VmRenewView, self).get_context_data(**kwargs) context = super(VmRenewView, self).get_context_data(**kwargs)
context['lease_request_form'] = LeaseRequestForm() context['lease_request_form'] = LeaseRequestForm(request=self.request)
return context return context
...@@ -1047,14 +1047,13 @@ class VmCreate(LoginRequiredMixin, TemplateView): ...@@ -1047,14 +1047,13 @@ class VmCreate(LoginRequiredMixin, TemplateView):
'template_o': template, 'template_o': template,
}) })
else: else:
from request.forms import TemplateRequestForm
context.update({ context.update({
'template': 'dashboard/_vm-create-1.html', 'template': 'dashboard/_vm-create-1.html',
'box_title': _('Create a VM'), 'box_title': _('Create a VM'),
'ajax_title': True, 'ajax_title': True,
'templates': templates.all(), 'templates': templates.all(),
'template_access_types': TemplateAccessType.objects.count(), 'template_access_types': TemplateAccessType.objects.count(),
'form': TemplateRequestForm(), 'form': TemplateRequestForm(request=request),
}) })
return self.render_to_response(context) return self.render_to_response(context)
......
...@@ -19,6 +19,8 @@ from django.forms import ( ...@@ -19,6 +19,8 @@ from django.forms import (
) )
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ 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.helper import FormHelper
from crispy_forms.layout import Submit from crispy_forms.layout import Submit
...@@ -59,19 +61,33 @@ class TemplateAccessTypeForm(ModelForm): ...@@ -59,19 +61,33 @@ class TemplateAccessTypeForm(ModelForm):
model = TemplateAccessType 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(), template = ModelChoiceField(TemplateAccessType.objects.all(),
label="Template share") label=_("Template share"))
level = ChoiceField(TemplateAccessAction.LEVELS, widget=RadioSelect, level = ChoiceField(TemplateAccessAction.LEVELS, widget=RadioSelect,
initial=TemplateAccessAction.LEVELS.user) 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): class LeaseRequestForm(InitialFromFileMixin, Form):
lease = ModelChoiceField(LeaseType.objects.all(), lease = ModelChoiceField(LeaseType.objects.all(), label=_("Lease"))
label=_("Lease"))
reason = CharField(widget=forms.Textarea) reason = CharField(widget=forms.Textarea)
initial_template = "request/initials/lease.html"
class ResourceRequestForm(VmResourcesForm): class ResourceRequestForm(VmResourcesForm):
reason = CharField(widget=forms.Textarea) reason = CharField(widget=forms.Textarea)
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
{% csrf_token %} {% csrf_token %}
{{ form.template|as_crispy_field }} {{ 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 %} {% for radio in form.level %}
<div class="myradio" style="display: inline-block; padding-left: 20px;"> <div class="myradio" style="display: inline-block; padding-left: 20px;">
<label> <label>
{{ radio }} {{ radio }}
<div class="text-muted" style="padding-left: 16px; font-weight: normal;"> <div class="text-muted" style="padding-left: 16px; font-weight: normal;">
{% if forloop.last %} {% 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 %} {% else %}
For regular users who want to start a virtual machine. {% trans "For users who want to start a virtual machine." %}
{% endif %} {% endif %}
</div> </div>
</label> </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): ...@@ -133,6 +133,11 @@ class TemplateRequestView(FormView):
form_class = TemplateRequestForm form_class = TemplateRequestForm
template_name = "request/request-template.html" 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): def form_valid(self, form):
data = form.cleaned_data data = form.cleaned_data
user = self.request.user user = self.request.user
...@@ -174,6 +179,11 @@ class LeaseRequestView(FormView): ...@@ -174,6 +179,11 @@ class LeaseRequestView(FormView):
context['vm'] = self.get_vm() context['vm'] = self.get_vm()
return context 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): def form_valid(self, form):
data = form.cleaned_data data = form.cleaned_data
user = self.request.user 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