80
app/access/forms/team.py
Normal file
80
app/access/forms/team.py
Normal file
@ -0,0 +1,80 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.db.models import Q
|
||||
from django.forms import inlineformset_factory
|
||||
|
||||
from app import settings
|
||||
|
||||
from .team_users import TeamUsersForm, TeamUsers
|
||||
from access.models import Team
|
||||
|
||||
|
||||
TeamUserFormSet = inlineformset_factory(
|
||||
model=TeamUsers,
|
||||
parent_model= Team,
|
||||
extra = 1,
|
||||
fields=[
|
||||
'user',
|
||||
'manager'
|
||||
]
|
||||
)
|
||||
|
||||
class TeamForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = [
|
||||
'name',
|
||||
'permissions',
|
||||
]
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.fields['created'] = forms.DateTimeField(
|
||||
label="Created",
|
||||
input_formats=settings.DATETIME_FORMAT,
|
||||
initial=kwargs['instance'].created,
|
||||
disabled=True,
|
||||
required=False,
|
||||
)
|
||||
|
||||
self.fields['modified'] = forms.DateTimeField(
|
||||
label="Modified",
|
||||
input_formats=settings.DATETIME_FORMAT,
|
||||
initial=kwargs['instance'].modified,
|
||||
disabled=True,
|
||||
required=False,
|
||||
)
|
||||
|
||||
self.fields['permissions'].widget.attrs = {'style': "height: 200px;"}
|
||||
|
||||
apps = [
|
||||
'access',
|
||||
'config_management',
|
||||
'core',
|
||||
'itam',
|
||||
'settings',
|
||||
]
|
||||
|
||||
exclude_models = [
|
||||
'appsettings',
|
||||
'organization'
|
||||
'settings',
|
||||
'usersettings',
|
||||
]
|
||||
|
||||
exclude_permissions = [
|
||||
'add_organization',
|
||||
'change_organization',
|
||||
'delete_organization',
|
||||
]
|
||||
|
||||
self.fields['permissions'].queryset = Permission.objects.filter(
|
||||
content_type__app_label__in=apps,
|
||||
).exclude(
|
||||
content_type__model__in=exclude_models
|
||||
).exclude(
|
||||
codename__in = exclude_permissions
|
||||
)
|
@ -5,23 +5,9 @@
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div>
|
||||
<input name="organization" id="id_organization" type="hidden" value="{{ organization.id }}">
|
||||
<section class="content-header">
|
||||
<fieldset><label>Name</label><input name="name" required id="id_name" type="text" value="{{ team.team_name }}" /></fieldset>
|
||||
<fieldset><label>Created</label><input name="created" type="text" value="{{ team.created }}" readonly /></fieldset>
|
||||
<fieldset><label>Modified</label><input name="modified" type="text" value="{{ team.modified }}" readonly /></fieldset>
|
||||
<fieldset><label>Permissions</label>
|
||||
<select name="permissions" id="id_permissions" style="height: 200px;" multiple>
|
||||
{% for permission in permissions %}
|
||||
{% if 'administration' not in permission.content_type|lower and 'authorization' not in permission.content_type|lower and 'content types' not in permission.content_type|lower and 'session' not in permission.content_type|lower and 'python social auth' not in permission.content_type|lower and 'add_organization' not in permission.codename|lower and 'delete_organization' not in permission.codename|lower %}
|
||||
<option value="{{ permission.id }}" {% for team_permission in team.permissions.all %}{% if permission.id == team_permission.id %}selected{% endif %}{% endfor %}>{{ permission.content_type }} | {{ permission.name }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</fieldset>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{{ form.as_div }}
|
||||
|
||||
{% include 'icons/issue_link.html.j2' with issue=13 %}<br>
|
||||
<input style="display:unset;" type="submit" value="Submit">
|
||||
</form>
|
||||
|
@ -4,25 +4,27 @@ from django.utils.decorators import method_decorator
|
||||
from django.urls import reverse
|
||||
from django.views import generic
|
||||
|
||||
from access.forms.team import TeamForm
|
||||
# from access.forms.team_users import TeamUsersForm
|
||||
from access.models import Team, TeamUsers, Organization
|
||||
from access.mixin import *
|
||||
|
||||
|
||||
|
||||
class View(OrganizationPermission, generic.UpdateView):
|
||||
|
||||
context_object_name = "team"
|
||||
|
||||
form_class = TeamForm
|
||||
|
||||
model = Team
|
||||
|
||||
permission_required = [
|
||||
'access.view_team',
|
||||
'access.change_team',
|
||||
]
|
||||
template_name = 'access/team.html.j2'
|
||||
|
||||
fields = [
|
||||
"name",
|
||||
'id',
|
||||
'organization',
|
||||
'permissions'
|
||||
]
|
||||
template_name = 'access/team.html.j2'
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -37,7 +39,6 @@ class View(OrganizationPermission, generic.UpdateView):
|
||||
teamusers = TeamUsers.objects.filter(team=self.kwargs['pk'])
|
||||
|
||||
context['teamusers'] = teamusers
|
||||
context['permissions'] = Permission.objects.filter()
|
||||
|
||||
context['model_pk'] = self.kwargs['pk']
|
||||
context['model_name'] = self.model._meta.verbose_name.replace(' ', '')
|
||||
|
Reference in New Issue
Block a user