Commit 12f405e8 by Oláh István Gergely

dashboard: create group form, view

parent de9e099a
from datetime import timedelta from datetime import timedelta
from django.contrib.auth.models import User
from django.contrib.auth.forms import ( from django.contrib.auth.forms import (
AuthenticationForm, PasswordResetForm, SetPasswordForm, AuthenticationForm, PasswordResetForm, SetPasswordForm,
) )
from django.contrib.auth.models import User, Group
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import ( from crispy_forms.layout import (
...@@ -279,6 +279,55 @@ class VmCustomizeForm(forms.Form): ...@@ -279,6 +279,55 @@ class VmCustomizeForm(forms.Form):
) )
class GroupCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(GroupCreateForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_show_labels = False
self.helper.layout = Layout(
Div(
Div(
AnyTag(
'h4',
HTML(_("Name")),
),
css_class="col-sm-10",
),
css_class="row",
),
Div(
Div(
Field('name', id="group-create-name"),
css_class="col-sm-10",
),
css_class="row",
),
Div( # buttons
Div(
AnyTag( # tip: don't try to use Button class
"button",
AnyTag(
"i",
css_class="icon-play"
),
HTML(" Create"),
css_id="vm-create-submit",
css_class="btn btn-success",
),
css_class="col-sm-5",
),
css_class="row",
),
)
class Meta:
model = Group
fields = ['name', ]
class HostForm(forms.ModelForm): class HostForm(forms.ModelForm):
def setowner(self, user): def setowner(self, user):
......
...@@ -7,7 +7,7 @@ from django.contrib.auth.signals import user_logged_in ...@@ -7,7 +7,7 @@ from django.contrib.auth.signals import user_logged_in
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import ( from django.db.models import (
Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField, Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField,
DateTimeField, DateTimeField, permalink,
) )
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _, override from django.utils.translation import ugettext_lazy as _, override
...@@ -93,6 +93,11 @@ class GroupProfile(AclBase): ...@@ -93,6 +93,11 @@ class GroupProfile(AclBase):
except cls.DoesNotExist: except cls.DoesNotExist:
return Group.objects.get(name=name) return Group.objects.get(name=name)
@permalink
def get_absolute_url(self):
return ('dashboard.views.group-detail', None,
{'pk': self.group.pk})
def get_or_create_profile(self): def get_or_create_profile(self):
obj, created = GroupProfile.objects.get_or_create(group_id=self.pk) obj, created = GroupProfile.objects.get_or_create(group_id=self.pk)
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
<div class="panel panel-default" id="group-detail-panel"> <div class="panel panel-default" id="group-detail-panel">
<div class="tab-content panel-body"> <div class="tab-content panel-body">
<h3>{% trans "User list"|capfirst %}</h3> <h3>{% trans "User list"|capfirst %}</h3>
<form action="" method="post">{% csrf_token %}
<table class="table table-striped table-with-form-fields"> <table class="table table-striped table-with-form-fields">
<tbody> <tbody>
<thead><tr><th></th><th>{% trans "Who" %}</th><th></th><th></th></tr></thead> <thead><tr><th></th><th>{% trans "Who" %}</th><th></th><th></th></tr></thead>
...@@ -43,10 +44,15 @@ ...@@ -43,10 +44,15 @@
{% endfor %} {% endfor %}
<tr><td><i class="icon-plus"></i></td> <tr><td><i class="icon-plus"></i></td>
<td><input type="text" class="form-control" name="perm-new-name" <td><input type="text" class="form-control" name="perm-new-name"
placeholder="{% trans "Name of group or user" %}"></td> placeholder="{% trans "Name of user" %}"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div class="form-actions">
<button type="submit" class="btn btn-success">{% trans "Save" %}</button>
</div>
</form>
<h3>{% trans "Permissions"|capfirst %}</h3> <h3>{% trans "Permissions"|capfirst %}</h3>
<form action="{{acl.url}}" method="post">{% csrf_token %} <form action="{{acl.url}}" method="post">{% csrf_token %}
...@@ -84,7 +90,7 @@ ...@@ -84,7 +90,7 @@
</table> </table>
<textarea class="form-control"></textarea> <textarea class="form-control"></textarea>
<div class="form-actions panel-body"> <div class="form-actions">
<button type="submit" class="btn btn-success">{% trans "Save" %}</button> <button type="submit" class="btn btn-success">{% trans "Save" %}</button>
</div> </div>
</form> </form>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<i class="icon-chevron-sign-right"></i> <strong>{{ more_groups }}</strong> more <i class="icon-chevron-sign-right"></i> <strong>{{ more_groups }}</strong> more
</a> </a>
{% endif %} {% endif %}
<a class="btn btn-success btn-xs group-create" href="#"><i class="icon-upload-alt"></i> upload </a> <a class="btn btn-success btn-xs group-create" href="{% url "dashboard.views.group-create" %}"><i class="icon-upload-alt"></i> upload </a>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -10,8 +10,9 @@ from .views import ( ...@@ -10,8 +10,9 @@ from .views import (
TransferOwnershipConfirmView, TransferOwnershipView, vm_activity, VmCreate, TransferOwnershipConfirmView, TransferOwnershipView, vm_activity, VmCreate,
VmDelete, VmDetailView, VmDetailVncTokenView, VmGraphView, VmList, VmDelete, VmDetailView, VmDetailVncTokenView, VmGraphView, VmList,
VmMassDelete, VmMigrateView, VmRenewView, GroupRemoveAclUserView, VmMassDelete, VmMigrateView, VmRenewView, GroupRemoveAclUserView,
GroupRemoveAclGroupView, GroupRemoveUserView GroupRemoveAclGroupView, GroupRemoveUserView, GroupCreate,
) )
from vm.models import Instance from vm.models import Instance
...@@ -111,4 +112,6 @@ urlpatterns = patterns( ...@@ -111,4 +112,6 @@ urlpatterns = patterns(
url(r'^group/(?P<group_pk>\d+)/remove/user/(?P<user_pk>\d+)/$', url(r'^group/(?P<group_pk>\d+)/remove/user/(?P<user_pk>\d+)/$',
GroupRemoveUserView.as_view(), GroupRemoveUserView.as_view(),
name="dashboard.views.remove-user"), name="dashboard.views.remove-user"),
url(r'^group/create/$', GroupCreate.as_view(),
name='dashboard.views.group-create'),
) )
...@@ -35,10 +35,13 @@ from braces.views import ( ...@@ -35,10 +35,13 @@ from braces.views import (
from .forms import ( from .forms import (
CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm, CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm,
NodeForm, TemplateForm, TraitForm, VmCustomizeForm, NodeForm, TraitForm, VmCustomizeForm, TemplateForm, GroupCreateForm,
)
from .tables import (
NodeListTable, NodeVmListTable, TemplateListTable, LeaseListTable,
GroupListTable,
) )
from .tables import (NodeListTable, NodeVmListTable,
TemplateListTable, LeaseListTable, GroupListTable,)
from vm.models import ( from vm.models import (
Instance, instance_activity, InstanceActivity, InstanceTemplate, Interface, Instance, instance_activity, InstanceActivity, InstanceTemplate, Interface,
InterfaceTemplate, Lease, Node, NodeActivity, Trait, InterfaceTemplate, Lease, Node, NodeActivity, Trait,
...@@ -1278,6 +1281,52 @@ class NodeCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView): ...@@ -1278,6 +1281,52 @@ class NodeCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
return redirect(path) return redirect(path)
class GroupCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
form_class = GroupCreateForm
form = None
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/modal-wrapper.html']
else:
return ['dashboard/nojs-wrapper.html']
def get(self, request, form=None, *args, **kwargs):
if form is None:
form = self.form_class()
context = self.get_context_data(**kwargs)
context.update({
'template': 'dashboard/group-create.html',
'box_title': 'Create a Group',
'form': form,
})
return self.render_to_response(context)
def get_context_data(self, **kwargs):
context = super(GroupCreate, self).get_context_data(**kwargs)
# TODO acl
context.update({
})
return context
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if not form.is_valid():
return self.get(request, form, *args, **kwargs)
form.cleaned_data
savedform = form.save()
messages.success(request, _('Group successfully created!'))
if request.is_ajax():
return HttpResponse(json.dumps({'redirect':
savedform.profile.get_absolute_url()}),
content_type="application/json")
else:
return redirect(savedform.profile.get_absolute_url())
class VmDelete(LoginRequiredMixin, DeleteView): class VmDelete(LoginRequiredMixin, DeleteView):
model = Instance model = Instance
template_name = "dashboard/confirm/base-delete.html" template_name = "dashboard/confirm/base-delete.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