Implement organization editing

This commit is contained in:
Kumi 2019-02-03 10:35:52 +00:00
parent 8cab325f9f
commit 3d9cfd40b2
3 changed files with 19 additions and 1 deletions

View file

@ -28,5 +28,6 @@ urlpatterns = [
path('users/<int:user_id>/edit/', views.edituser, name='edituser'),
path('users/<int:user_id>/delete/', views.deleteuser, name='deleteuser'),
path('organizations/<int:orga_id>/delete/', views.deleteorga, name='deleteorga'),
path('organizations/<int:orga_id>/edit/', views.editorganization, name='editorganization'),
path('update', views.update, name='update')
]

View file

@ -518,6 +518,23 @@ def makeorganization(request):
return render(request, "manager/form.html", { "title": "Add Organization", "form": form })
@user_passes_test(is_superuser)
def editorganization(request, orga_id):
orga = get_object_or_404(Organization, id=orga_id)
if request.method == "POST":
form = OrgaForm(request.POST)
if form.is_valid():
data = form.cleaned_data
orga.name = data["name"]
orga.userlimit = data["users"]
orga.save()
return redirect("/organizations/")
else:
form = OrgaForm(initial={ "name": orga.name, "users": orga.userlimit })
return render(request, "manager/form.html", { "title": "Change Organization", "form": form })
@user_passes_test(is_superuser)
def makedevice(request):
CADIR = "/etc/openvpn/ca/"

View file

@ -148,7 +148,7 @@
<tr>
<td><div style="display:inline;">{{ orga.name }}</div></td>
<td>{{ orga.users.all|length }}{% if orga.userlimit %}/{{ orga.userlimit }}{% endif %}</td>
<td><a href="#"><i style="color: darkred;" onclick="askdeleteorga({{ orga.id }});" class="fas fa-trash-alt" title="Delete Organization"></i></a></td>
<td><a href="/organizations/{{ orga.id }}/edit"><i class="fas fa-edit" title="Edit Organization"></i></a> <a href="#"><i style="color: darkred;" onclick="askdeleteorga({{ orga.id }});" class="fas fa-trash-alt" title="Delete Organization"></i></a></td>
</tr>
{% endfor %}