Skip to content

Commit

Permalink
Merge pull request #13 from kkkkkkkkatya/manage
Browse files Browse the repository at this point in the history
add manager feature
  • Loading branch information
kkkkkkkkatya authored May 14, 2024
2 parents 50a3b2a + f4eddf0 commit e3c01b6
Show file tree
Hide file tree
Showing 37 changed files with 342 additions and 3 deletions.
Binary file modified OnlineBookClub/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified OnlineBookClub/__pycache__/urls.cpython-311.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion OnlineBookClub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
'group',
'user',
'session',
'books'
'books',
'manager',
]
### NEEEEW

Expand Down
1 change: 1 addition & 0 deletions OnlineBookClub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
path('user/', include('user.urls', namespace='user')),
path('session/', include('session.urls', namespace='session')),
path('books/', include('books.urls', namespace='books')),
path('manager/', include('manager.urls', namespace='manager')),


]
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified forum/__pycache__/admin.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions forum/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin
from .models import *

# Register your models here.
admin.site.register(Forum)
admin.site.register(Discussion)
Binary file modified group/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified group/__pycache__/views.cpython-311.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions group/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from django.contrib import admin
from .models import *

# Register your models here.
admin.site.register(Group)
admin.site.register(Interest)
admin.site.register(Comment)
admin.site.register(RelGroupUser)
15 changes: 14 additions & 1 deletion group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .forms import *
from main.keeper_service import keeper_service
from django.utils import timezone
from manager.views import group_show


# Create your views here.
Expand Down Expand Up @@ -78,6 +79,7 @@ def group_create(request):
def group_delete(request, id):
print(f"=== group, action: group_delete === ")
print(f"id: ", id)
user = request.user

try:
obj = None
Expand All @@ -88,6 +90,9 @@ def group_delete(request, id):
keeper_service.push("error", str(e))
print(f"Error: {e}")

if user.is_staff:
return redirect('manager:group_list', id=group.id)

return redirect('group:list')


Expand All @@ -98,6 +103,7 @@ def edit(request, id):
print(f"method: ", request.method)
error = ''
cur_action = "edit"
user = request.user

group = get_object_or_404(Group, id=id)

Expand All @@ -107,6 +113,8 @@ def edit(request, id):
form = CreateGroup(request.POST, request.FILES, instance=group)
if form.is_valid():
form.save()
if user.is_staff:
return redirect('manager:group_show', id=group.id)
return redirect('group:show', id=group.id) # Redirect to forum detail view
else:
error = 'Помилки при заповненні форми'
Expand Down Expand Up @@ -203,6 +211,7 @@ def comment_create(request):
def comment_delete(request, id):
print(f"=== forum, action: discussion_delete === ")
print(f"id: ", id)
user = request.user

try:
obj = None
Expand All @@ -214,7 +223,11 @@ def comment_delete(request, id):
keeper_service.push("error", str(e))
print(f"Error: {e}")

return redirect('group:show',id=group_id)
if user.is_staff:
return redirect('manager:group_show', id=group_id)
else:

return redirect('group:show',id=group_id)



Binary file modified main/__pycache__/urls.cpython-311.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions main/templates/main/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@

<div class=" d-flex" style="color: gray">

{% if user.is_staff %}
<span class="nav-item m-1" >
<a class="nav-link active" aria-current="page" href="{% url 'manager:home' %}">Admin page</a>
</span>
{% endif %}

{% if user.is_authenticated %}
<span class="nav-item m-1" >
<a class="nav-link active" aria-current="page" style="margin-right: 10px;"
Expand All @@ -80,6 +86,7 @@
</span>

{% endif %}

</div>


Expand Down
Empty file added manager/__init__.py
Empty file.
Binary file added manager/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added manager/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file added manager/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added manager/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added manager/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added manager/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions manager/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


# Register your models here.
6 changes: 6 additions & 0 deletions manager/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AdminConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'manager'
Empty file added manager/migrations/__init__.py
Empty file.
Binary file not shown.
8 changes: 8 additions & 0 deletions manager/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models
from django.contrib.auth.models import User



class Manager(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
is_admin = models.BooleanField(default=False, blank=True, null=True)
50 changes: 50 additions & 0 deletions manager/templates/manager/group_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'main/layout.html' %}


{% block content %}
<div class="row mb-3 ">
<div class="col-10">
<h1>Reading groups</h1>
</div>
{% if user.is_authenticated %}
<div class="col-2">
<a href="{% url 'group:group_create'%}" class="btn btn-outline-success">Create new group</a>
</div>
{% endif %}

</div>
{% if error %}
<span class="alert alert-danger mt-2"> {{error}}</span>
{% endif %}

<div class="container col-10">
<div class="row justify-content-center">
{% for el in instance_list %}
<a href="{% url 'manager:group_show' id=el.id %}" class="btn btn-outline-dark mt-3 mb-3">
<style>
.forum-item {
text-align: left;
}
.topic {
font-size: 30px; /* Adjust font size as needed */
font-weight: bold; /* Add bold font weight */
}
.details {
display: flex;
justify-content: space-between;
}
.name {
margin-right: 10px; /* Add right margin to separate from date */
}
</style>
<div class="forum-item">
<p class="topic">{{ el.topic }}</p>
<div class="details">
<p class="name">#{{ el.interest }}</p>
</div>
</div>
</a>
{% endfor %}
</div>
</div>
{% endblock %}
91 changes: 91 additions & 0 deletions manager/templates/manager/group_show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{% extends 'main/layout.html' %}

{% block content %}
{% if error %}
<span class="alert alert-danger row mt-2">Error! {{error}}</span>
{% endif %}

<style>
.details {
display: flex;

}

.date {
font-style: italic; /* Add italic style to date */
}
</style>

<div class="card ">
<div class="card-header bg-dark text-white ">
<p for="creator">Creater: {{ group.creator }}</p>

{% if user.is_authenticated and user != group.creator%}

<form method="post">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{group.id}}">
<input type="hidden" name="user_id" value="{{user.id}}">
<div class="row mt-4 mb-4">

</div>
</form>

{% endif %}

</div>
<div class="card-body position-relative">
<div>
<h2 class="card-title" style="margin-left: 20px;" for="topic"> {{group.topic}} </h2>
<h6 class="date" style="margin-left: 20px;" for="interest">#{{ group.interest }}</h6>
<h5 class="card-text" style="margin-left: 20px;" for="description"> {{group.description}} </h5>
</div>
<div class="row">
<div class="col-2 text-right mt-4">
{% if user.is_staff %}
<a href="{% url 'group:edit' id=group.id %}" class="btn btn-outline-success"><i
class="fa-regular fa-pen-to-square"></i></a>
<a href="{% url 'group:group_delete' id=group.id %}" class="btn btn-outline-danger"><i
class="fa-solid fa-trash-can"></i></a>
{% endif %}
</div>
</div>
</div>
</div>



<h3>Comments</h3>
{% for el in comments_list %}
<div class="container col-11">

<div class="card justify-content-center mt-3 mb-3">
<div class="card-header bg-dark bg-gradient text-white details">
<div class="col-9">
<p for="name"> {{ el.user_id }}
{% if el.parent_comment != None%}
answer {{el.parent_comment.user_id}}: {{el.parent_comment}}
{% endif%}
</p>
</div>
<div class="col-3">
<p class="date" for="date_created">{{ el.date_created }}</p>
</div>
</div>
<div class="card-body position-relative">
<div>
<h6 class="card-text" style="margin-left: 20px;" for="discuss"> {{el.comment}} </h6>
{% if user.is_staff %}
<a href="{% url 'group:comment_delete' id=el.id %}" class="btn btn-outline-danger mt-4"
style="margin-left: 20px;"> <i class="fa-solid fa-trash-can"></i></a>
{% endif %}

</div>
</div>
</div>

</div>
{%endfor%}


{% endblock %}
32 changes: 32 additions & 0 deletions manager/templates/manager/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'main/layout.html' %}


{% block content %}
<div class="row mb-3 ">
<div class="col-10">
<h1>Admin dashboard</h1>
</div>
</div>

{% if error %}
<span class="alert alert-danger mt-2"> {{error}}</span>
{% endif %}

<div class="container col-10">
<div class="row justify-content-center">
<a href="{% url 'manager:group_list' %}" class="btn btn-outline-dark mt-3 mb-3">
Reading groups
</a>
</div>
<div class="row justify-content-center">
<a href="{% url 'forum:list' %}" class="btn btn-outline-dark mt-3 mb-3">
Discussion forums
</a>
</div>
<div class="row justify-content-center">
<a href="{% url 'manager:users_list' %}" class="btn btn-outline-dark mt-3 mb-3">
Users
</a>
</div>
</div>
{% endblock %}
45 changes: 45 additions & 0 deletions manager/templates/manager/users_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'main/layout.html' %}


{% block content %}
<div class="row mb-3 ">
<div class="col-10">
<h1>Users</h1>
</div>

</div>
{% if error %}
<span class="alert alert-danger mt-2"> {{error}}</span>
{% endif %}

<div class="container col-10">
<div class="row justify-content-center">
{% for el in instance_list %}
<a href="{% url 'user:show' id=el.id %}" class="btn btn-outline-dark mt-3 mb-3">
<style>
.forum-item {
text-align: left;
}
.topic {
font-size: 30px; /* Adjust font size as needed */
font-weight: bold; /* Add bold font weight */
}
.details {
display: flex;
justify-content: space-between;
}
.name {
margin-right: 10px; /* Add right margin to separate from date */
}
</style>
<div class="forum-item">
<p class="topic">{{ el.username }}</p>
<div class="details">
<p class="name">{{ el.email }}</p>
</div>
</div>
</a>
{% endfor %}
</div>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions manager/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
17 changes: 17 additions & 0 deletions manager/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.urls import path
from . import views
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

app_name = "manager"

urlpatterns = [
path('', views.index, name='home'),
path('users_list', views.users_list, name='users_list'),
path('group_list', views.group_list, name='group_list'),
path('group_show/<int:id>', views.group_show, name='group_show'),

]


urlpatterns += staticfiles_urlpatterns()
Loading

0 comments on commit e3c01b6

Please sign in to comment.