Commit a6e314e6 by Kálmán Viktor

Merge branch 'issue-180' into 'master'

Change traits and raw data of VM

Closes #180
parents 5e2da567 794733a1
...@@ -39,12 +39,13 @@ from django.template import Context ...@@ -39,12 +39,13 @@ from django.template import Context
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from sizefield.widgets import FileSizeWidget from sizefield.widgets import FileSizeWidget
from django.core.urlresolvers import reverse_lazy
from django_sshkey.models import UserKey from django_sshkey.models import UserKey
from firewall.models import Vlan, Host from firewall.models import Vlan, Host
from storage.models import Disk from storage.models import Disk
from vm.models import ( from vm.models import (
InstanceTemplate, Lease, InterfaceTemplate, Node, Trait InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance
) )
from .models import Profile, GroupProfile from .models import Profile, GroupProfile
from circle.settings.base import LANGUAGES from circle.settings.base import LANGUAGES
...@@ -1145,3 +1146,38 @@ class UserKeyForm(forms.ModelForm): ...@@ -1145,3 +1146,38 @@ class UserKeyForm(forms.ModelForm):
if self.user: if self.user:
self.instance.user = self.user self.instance.user = self.user
return super(UserKeyForm, self).clean() return super(UserKeyForm, self).clean()
class TraitsForm(forms.ModelForm):
class Meta:
model = Instance
fields = ('req_traits', )
@property
def helper(self):
helper = FormHelper()
helper.form_show_labels = False
helper.form_action = reverse_lazy("dashboard.views.vm-traits",
kwargs={'pk': self.instance.pk})
helper.add_input(Submit("submit", _("Save"),
css_class="btn btn-success", ))
return helper
class RawDataForm(forms.ModelForm):
class Meta:
model = Instance
fields = ('raw_data', )
@property
def helper(self):
helper = FormHelper()
helper.form_show_labels = False
helper.form_action = reverse_lazy("dashboard.views.vm-raw-data",
kwargs={'pk': self.instance.pk})
helper.add_input(Submit("submit", _("Save"),
css_class="btn btn-success",
css_id="submit-password-button"))
return helper
...@@ -68,6 +68,32 @@ ...@@ -68,6 +68,32 @@
</div> </div>
</div> </div>
{% if user.is_superuser %}
<hr/>
<div class="row" id="">
<div class="col-sm-12">
<h3>
{% trans "Required traits" %}
</h3>
{% crispy traits_form %}
</div>
</div>
<hr/>
<div class="row" id="">
<div class="col-sm-12">
<h3>
{% trans "Raw data" %}
</h3>
{% crispy raw_data_form %}
</div>
</div>
{% endif %}
{% block extra_js %} {% block extra_js %}
<style> <style>
......
...@@ -37,6 +37,7 @@ from .views import ( ...@@ -37,6 +37,7 @@ from .views import (
get_vm_screenshot, get_vm_screenshot,
ProfileView, toggle_use_gravatar, UnsubscribeFormView, ProfileView, toggle_use_gravatar, UnsubscribeFormView,
UserKeyDelete, UserKeyDetail, UserKeyCreate, UserKeyDelete, UserKeyDetail, UserKeyCreate,
VmTraitsUpdate, VmRawDataUpdate
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -89,6 +90,10 @@ urlpatterns = patterns( ...@@ -89,6 +90,10 @@ urlpatterns = patterns(
name='dashboard.views.vm-activity'), name='dashboard.views.vm-activity'),
url(r'^vm/(?P<pk>\d+)/screenshot/$', get_vm_screenshot, url(r'^vm/(?P<pk>\d+)/screenshot/$', get_vm_screenshot,
name='dashboard.views.vm-get-screenshot'), name='dashboard.views.vm-get-screenshot'),
url(r'^vm/(?P<pk>\d+)/traits/$', VmTraitsUpdate.as_view(),
name='dashboard.views.vm-traits'),
url(r'^vm/(?P<pk>\d+)/raw_data/$', VmRawDataUpdate.as_view(),
name='dashboard.views.vm-raw-data'),
url(r'^node/list/$', NodeList.as_view(), name='dashboard.views.node-list'), url(r'^node/list/$', NodeList.as_view(), name='dashboard.views.node-list'),
url(r'^node/(?P<pk>\d+)/$', NodeDetailView.as_view(), url(r'^node/(?P<pk>\d+)/$', NodeDetailView.as_view(),
......
...@@ -61,6 +61,7 @@ from .forms import ( ...@@ -61,6 +61,7 @@ from .forms import (
UserCreationForm, GroupProfileUpdateForm, UnsubscribeForm, UserCreationForm, GroupProfileUpdateForm, UnsubscribeForm,
VmSaveForm, UserKeyForm, VmSaveForm, UserKeyForm,
CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm, CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm,
TraitsForm, RawDataForm
) )
from .tables import ( from .tables import (
...@@ -287,6 +288,11 @@ class VmDetailView(CheckedDetailView): ...@@ -287,6 +288,11 @@ class VmDetailView(CheckedDetailView):
# ipv6 infos # ipv6 infos
context['ipv6_host'] = instance.get_connect_host(use_ipv6=True) context['ipv6_host'] = instance.get_connect_host(use_ipv6=True)
context['ipv6_port'] = instance.get_connect_port(use_ipv6=True) context['ipv6_port'] = instance.get_connect_port(use_ipv6=True)
# resources forms
if self.request.user.is_superuser:
context['traits_form'] = TraitsForm(instance=instance)
context['raw_data_form'] = RawDataForm(instance=instance)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -499,6 +505,22 @@ class VmDetailView(CheckedDetailView): ...@@ -499,6 +505,22 @@ class VmDetailView(CheckedDetailView):
return redirect("%s#activity" % self.object.get_absolute_url()) return redirect("%s#activity" % self.object.get_absolute_url())
class VmTraitsUpdate(SuperuserRequiredMixin, UpdateView):
form_class = TraitsForm
model = Instance
def get_success_url(self):
return self.get_object().get_absolute_url() + "#resources"
class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
form_class = RawDataForm
model = Instance
def get_success_url(self):
return self.get_object().get_absolute_url() + "#resources"
class OperationView(DetailView): class OperationView(DetailView):
template_name = 'dashboard/operate.html' template_name = 'dashboard/operate.html'
......
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