Commit 36231e8f by Kálmán Viktor

request: fix trivial mistakes

parent 255d2160
...@@ -1052,7 +1052,7 @@ class VmCreate(LoginRequiredMixin, TemplateView): ...@@ -1052,7 +1052,7 @@ class VmCreate(LoginRequiredMixin, TemplateView):
'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.exists(),
'form': TemplateRequestForm(request=request), 'form': TemplateRequestForm(request=request),
}) })
return self.render_to_response(context) return self.render_to_response(context)
......
...@@ -32,9 +32,6 @@ from dashboard.forms import VmResourcesForm ...@@ -32,9 +32,6 @@ from dashboard.forms import VmResourcesForm
class LeaseTypeForm(ModelForm): class LeaseTypeForm(ModelForm):
def __init__(self, *args, **kwargs):
super(LeaseTypeForm, self).__init__(*args, **kwargs)
@property @property
def helper(self): def helper(self):
helper = FormHelper() helper = FormHelper()
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('request', '0002_auto_20150317_1211'),
]
operations = [
migrations.AlterField(
model_name='request',
name='reason',
field=models.TextField(verbose_name='Reason'),
preserve_default=True,
),
]
...@@ -66,7 +66,7 @@ class Request(TimeStampedModel): ...@@ -66,7 +66,7 @@ class Request(TimeStampedModel):
('template', _("template access")), ('template', _("template access")),
) )
type = CharField(choices=TYPES, max_length=10) type = CharField(choices=TYPES, max_length=10)
reason = TextField(help_text="szia") reason = TextField(verbose_name=_("Reason"))
content_type = ForeignKey(ContentType) content_type = ForeignKey(ContentType)
object_id = IntegerField() object_id = IntegerField()
......
...@@ -160,31 +160,37 @@ class TemplateRequestView(FormView): ...@@ -160,31 +160,37 @@ class TemplateRequestView(FormView):
return redirect("/") return redirect("/")
class LeaseRequestView(FormView): class VmRequestMixin(object):
form_class = LeaseRequestForm
template_name = "request/request-lease.html"
def get_vm(self): def get_vm(self):
return get_object_or_404(Instance, pk=self.kwargs['vm_pk']) return get_object_or_404(Instance, pk=self.kwargs['vm_pk'])
def dispatch(self, *args, **kwargs): def dispatch(self, *args, **kwargs):
vm = self.get_vm() vm = self.get_vm()
user = self.request.user user = self.request.user
if not vm.has_level(user, 'operator'): if not vm.has_level(user, self.user_level):
raise PermissionDenied() raise PermissionDenied()
return super(LeaseRequestView, self).dispatch(*args, **kwargs) return super(VmRequestMixin, self).dispatch(*args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(LeaseRequestView, self).get_context_data(**kwargs) context = super(VmRequestMixin, self).get_context_data(**kwargs)
context['vm'] = self.get_vm() context['vm'] = self.get_vm()
return context return context
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super(LeaseRequestView, self).get_form_kwargs() kwargs = super(VmRequestMixin, self).get_form_kwargs()
kwargs['request'] = self.request kwargs['request'] = self.request
return kwargs return kwargs
def form_valid(self, form): def form_valid(self, form):
raise NotImplementedError
class LeaseRequestView(VmRequestMixin, FormView):
form_class = LeaseRequestForm
template_name = "request/request-lease.html"
user_level = "operator"
def form_valid(self, form):
data = form.cleaned_data data = form.cleaned_data
user = self.request.user user = self.request.user
vm = self.get_vm() vm = self.get_vm()
...@@ -206,29 +212,14 @@ class LeaseRequestView(FormView): ...@@ -206,29 +212,14 @@ class LeaseRequestView(FormView):
return redirect(vm.get_absolute_url()) return redirect(vm.get_absolute_url())
class ResourceRequestView(FormView): class ResourceRequestView(VmRequestMixin, FormView):
form_class = ResourceRequestForm form_class = ResourceRequestForm
template_name = "request/request-resource.html" template_name = "request/request-resource.html"
user_level = "user"
def get_vm(self):
return get_object_or_404(Instance, pk=self.kwargs['vm_pk'])
def dispatch(self, *args, **kwargs):
vm = self.get_vm()
user = self.request.user
if not vm.has_level(user, "user"):
raise PermissionDenied()
return super(ResourceRequestView, self).dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super(ResourceRequestView, self).get_context_data(**kwargs)
context['vm'] = self.get_vm()
return context
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super(ResourceRequestView, self).get_form_kwargs() kwargs = super(ResourceRequestView, self).get_form_kwargs()
kwargs['can_edit'] = True kwargs['can_edit'] = True
kwargs['instance'] = self.get_vm()
return kwargs return kwargs
def get_initial(self): def get_initial(self):
......
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