Jiu zhe yang ba

pull/530/head
ibuler 8 years ago
parent ab2eeb0da3
commit b5abb17568

@ -22,7 +22,8 @@ class AssetPermission(models.Model):
assets = models.ManyToManyField(Asset, related_name='granted_by_permissions', blank=True) assets = models.ManyToManyField(Asset, related_name='granted_by_permissions', blank=True)
asset_groups = models.ManyToManyField(AssetGroup, related_name='granted_by_permissions', blank=True) asset_groups = models.ManyToManyField(AssetGroup, related_name='granted_by_permissions', blank=True)
system_users = models.ManyToManyField(SystemUser, related_name='granted_by_permissions') system_users = models.ManyToManyField(SystemUser, related_name='granted_by_permissions')
private_for = models.CharField(choices=PRIVATE_FOR_CHOICE, max_length=1, default='N', verbose_name=_('Private for')) private_for = models.CharField(choices=PRIVATE_FOR_CHOICE, max_length=1, default='N', blank=True,
verbose_name=_('Private for'))
is_active = models.BooleanField(default=True, verbose_name=_('Active')) is_active = models.BooleanField(default=True, verbose_name=_('Active'))
date_expired = models.DateTimeField(default=date_expired_default, verbose_name=_('Date expired')) date_expired = models.DateTimeField(default=date_expired_default, verbose_name=_('Date expired'))
created_by = models.CharField(max_length=128, blank=True, verbose_name=_('Created by')) created_by = models.CharField(max_length=128, blank=True, verbose_name=_('Created by'))

@ -88,14 +88,11 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
def save(self, commit=True): def save(self, commit=True):
self.instance = super(UserPrivateAssetPermissionForm, self).save(commit=commit) self.instance = super(UserPrivateAssetPermissionForm, self).save(commit=commit)
self.instance.private_for = 'U'
self.instance.users = [self.user] self.instance.users = [self.user]
self.instance.name = '_Private for %s %s' % (self.user.username, )
self.instance.save() self.instance.save()
return self.instance return self.instance
def clean_private_for(self):
return 'U'
class Meta: class Meta:
model = AssetPermission model = AssetPermission
fields = [ fields = [
@ -110,5 +107,3 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
'data-placeholder': _('Select system users')}), 'data-placeholder': _('Select system users')}),
} }

@ -44,7 +44,7 @@
<div class="col-sm-7" style="padding-left: 0;"> <div class="col-sm-7" style="padding-left: 0;">
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-title"> <div class="ibox-title">
<span style="float: left">{% trans 'Asset permission of ' %} <b>{{ user.name }}</b></span> <span style="float: left">{% trans 'Asset permission of ' %} <b>{{ user_object.name }}</b></span>
<div class="ibox-tools"> <div class="ibox-tools">
<a class="collapse-link"> <a class="collapse-link">
<i class="fa fa-chevron-up"></i> <i class="fa fa-chevron-up"></i>
@ -115,31 +115,35 @@
<i class="fa fa-info-circle"></i> {% trans 'Quick create permission for user' %} <i class="fa fa-info-circle"></i> {% trans 'Quick create permission for user' %}
</div> </div>
<div class="panel-body"> <div class="panel-body">
<form> <form method="post" action="{% url 'users:user-asset-permission-create' pk=user_object.id %}">
<table class="table"> <table class="table">
<tbody> <tbody>
{% csrf_token %} {% csrf_token %}
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td colspan="1" style="padding-top: 0"> <td colspan="1" style="padding-top: 0">
{{ form.assets|bootstrap }} {{ form.name|bootstrap }}
</td> </td>
</tr> </tr>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td colspan="1" style="padding-top: 0"> <td colspan="1" style="padding-top: 0">
{{ form.asset_groups|bootstrap }} {{ form.assets|bootstrap }}
</td> </td>
</tr> </tr>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td colspan="1" style="padding-top: 0"> <td colspan="1" style="padding-top: 0">
{{ form.system_users|bootstrap }} {{ form.asset_groups|bootstrap }}
</td> </td>
</tr> </tr>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td> <td colspan="1" style="padding-top: 0">
<button type="button" {{ form.system_users|bootstrap }}
class="btn btn-primary btn-sm">{% trans 'Submit' %}</button> </td>
</td> </tr>
</tr> <tr class="no-borders-tr">
<td>
<button type="submit" class="btn btn-primary btn-sm">{% trans 'Submit' %}</button>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</form> </form>

@ -18,6 +18,8 @@ urlpatterns = [
url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'), url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/(?P<pk>[0-9]+)/asset-permission$', views.UserAssetPermissionView.as_view(), url(r'^user/(?P<pk>[0-9]+)/asset-permission$', views.UserAssetPermissionView.as_view(),
name='user-asset-permission'), name='user-asset-permission'),
url(r'^user/(?P<pk>[0-9]+)/asset-permission/create$', views.UserAssetPermissionCreateView.as_view(),
name='user-asset-permission-create'),
url(r'^user/(?P<pk>[0-9]+)/asset-granted', views.UserDetailView.as_view(), name='user-granted-asset'), url(r'^user/(?P<pk>[0-9]+)/asset-granted', views.UserDetailView.as_view(), name='user-granted-asset'),
url(r'^user/(?P<pk>[0-9]+)/login-history', views.UserDetailView.as_view(), name='user-login-history'), url(r'^user/(?P<pk>[0-9]+)/login-history', views.UserDetailView.as_view(), name='user-login-history'),
url(r'^first-login/$', views.UserFirstLoginView.as_view(), name='user-first-login'), url(r'^first-login/$', views.UserFirstLoginView.as_view(), name='user-first-login'),

@ -18,18 +18,17 @@ from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, FormMixin from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, \
FormMixin, ModelFormMixin, ProcessFormView, BaseCreateView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from formtools.wizard.views import SessionWizardView from formtools.wizard.views import SessionWizardView
from common.utils import get_object_or_none, get_logger from common.utils import get_object_or_none, get_logger
from .models import User, UserGroup from .models import User, UserGroup
from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm, \ from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm, \
UserPrivateAssetPermissionForm UserPrivateAssetPermissionForm
from .utils import AdminUserRequiredMixin, user_add_success_next, send_reset_password_mail from .utils import AdminUserRequiredMixin, user_add_success_next, send_reset_password_mail
from .hands import AssetPermission
logger = get_logger(__name__) logger = get_logger(__name__)
@ -394,4 +393,26 @@ class UserAssetPermissionView(AdminUserRequiredMixin, FormMixin, SingleObjectMix
class UserAssetPermissionCreateView(AdminUserRequiredMixin, CreateView): class UserAssetPermissionCreateView(AdminUserRequiredMixin, CreateView):
pass form_class = UserPrivateAssetPermissionForm
model = AssetPermission
def get(self, request, *args, **kwargs):
user_object = self.get_object(queryset=User.objects.all())
return redirect(reverse('users:user-asset-permission', kwargs={'pk': user_object.id}))
def post(self, request, *args, **kwargs):
self.user_object = self.get_object(queryset=User.objects.all())
return super(UserAssetPermissionCreateView, self).post(request, *args, **kwargs)
def get_form(self, form_class=None):
form = super(UserAssetPermissionCreateView, self).get_form(form_class=form_class)
form.user = self.user_object
return form
def form_invalid(self, form):
print(form.errors)
return redirect(reverse('users:user-asset-permission', kwargs={'pk': self.user_object.id}))
def get_success_url(self):
return reverse('users:user-asset-permission', kwargs={'pk': self.user_object.id})

Loading…
Cancel
Save