panel adminów

This commit is contained in:
Jędrzej Klepacki 2021-01-15 19:27:40 +01:00
parent fa8855e6de
commit f6d68449b2
30 changed files with 452 additions and 1 deletions

View File

@ -33,6 +33,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'homepage.apps.HomepageConfig',
'enGB.apps.EngbConfig',
'control.apps.ControlConfig',
'django.contrib.postgres',
'django.contrib.admin',
'django.contrib.auth',

View File

@ -7,5 +7,6 @@ from django.conf.urls.static import static
urlpatterns = [
path('homepage/', include('homepage.urls')),
path('enGB/', include('enGB.urls')),
path('control/', include('control.urls')),
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Notificationuser, Notificationoffer, Usermessage, Vipuser
admin.site.register(Notificationuser)
admin.site.register(Notificationoffer)
admin.site.register(Usermessage)
admin.site.register(Vipuser)

View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ControlConfig(AppConfig):
name = 'control'

View File

@ -0,0 +1,58 @@
# Generated by Django 3.1.4 on 2021-01-15 15:54
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('homepage', '0004_chat'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Usermessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('active', models.BooleanField(default=True)),
('name', models.TextField(default='', max_length=40)),
('email', models.TextField(default='', max_length=40)),
('text', models.TextField(default='', max_length=5000)),
('date', models.DateTimeField(verbose_name='date published')),
],
),
migrations.CreateModel(
name='Vipuser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('active', models.BooleanField(default=True)),
('expires_date', models.DateTimeField(verbose_name='date published')),
('user_iden', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Notificationuser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('active', models.BooleanField(default=True)),
('text', models.TextField(default='', max_length=5000)),
('date', models.DateTimeField(verbose_name='date published')),
('user_iden', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Notificationoffer',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('active', models.BooleanField(default=True)),
('text', models.TextField(default='', max_length=5000)),
('date', models.DateTimeField(verbose_name='date published')),
('user_iden', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.product')),
],
),
]

View File

@ -0,0 +1,28 @@
from django.db import models
from django.contrib.auth.models import User
from homepage.models import Product
import datetime
class Notificationuser(models.Model):
active = models.BooleanField(default=True)
user_iden = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField(max_length=5000, blank=False, default="")
date = models.DateTimeField('date published')
class Notificationoffer(models.Model):
active = models.BooleanField(default=True)
user_iden = models.ForeignKey(Product, on_delete=models.CASCADE)
text = models.TextField(max_length=5000, blank=False, default="")
date = models.DateTimeField('date published')
class Usermessage(models.Model):
active = models.BooleanField(default=True)
name = models.TextField(max_length=40, blank=False, default="")
email = models.TextField(max_length=40, blank=False, default="")
text = models.TextField(max_length=5000, blank=False, default="")
date = models.DateTimeField('date published')
class Vipuser(models.Model):
active = models.BooleanField(default=True)
user_iden = models.ForeignKey(User, on_delete=models.CASCADE)
expires_date = models.DateTimeField('date published')

View File

@ -0,0 +1,23 @@
{% block content %}
<!DOCTYPE html>
<a href="/control">Powrót</a>
<table>
<tr>
<th>Nr Oferty</th>
<th>Opis Zgłoszenia</th>
<th>Data Zgłoszenia</th>
<th>Usuń Oferte</th>
<th>Zamknij Zgłoszenie</th>
</tr>
{% for offer in all_Notificationoffer %}
<tr>
<th><a href="/homepage/offer_details/{{offer.user_iden.id}}">{{offer.id}}</a></th>
<th>{{offer.text}}</th>
<th>{{offer.date}}</th>
<th><a href="DeleteOffer/{{offer.user_iden.id}}">Usuń</a></th>
<th><a href="DeleteOfferNotification/{{offer.id}}">Zamknij<a></th>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,18 @@
{% block content %}
<!DOCTYPE html>
<a href="/control">Powrót</a>
<table>
<tr>
<th>Email</th>
<th>Nadaj VIP</th>
<th>Usuń Konto</th>
</tr>
{% for user in all_User %}
<tr>
<th><a href="/homepage/user_profile/{{user.email}}">{{user.email}}</a></th>
<th><a href="AddVIP/{{user.id}}">Dodaj</a></th>
<th><a href="DeleteUser/{{user.id}}">Usuń</a></th>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% block content %}
<!DOCTYPE html>
<a href="/control">Powrót</a>
<table>
<tr>
<th>Adresat</th>
<th>email</th>
<th>Treść</th>
<th>Zamknij Zgłoszenie</th>
</tr>
{% for mess in all_Usermessage %}
<tr>
<th>{{mess.name}}</a></th>
<th>{{mess.email}}</th>
<th>{{mess.text}}</th>
<th><a href="DeleteUserMessager/{{mess.id}}">Zamknij<a></th>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% block content %}
<!DOCTYPE html>
<a href="/control">Powrót</a>
<table>
<tr>
<th>Email</th>
<th>Opis Zgłoszenia</th>
<th>Data Zgłoszenia</th>
<th>Usuń Użytkownika</th>
<th>Zamknij Zgłoszenie</th>
</tr>
{% for user in all_Notificationuser %}
<tr>
<th><a href="/homepage/user_profile/{{user.user_iden}}">{{user.user_iden}}</a></th>
<th>{{user.text}}</th>
<th>{{user.date}}</th>
<th><a href="DeleteUser/{{user.user_iden.id}}">Usuń</a></th>
<th><a href="DeleteUserNotification/{{user.id}}">Zamknij<a></th>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,20 @@
{% block content %}
<!DOCTYPE html>
<a href="/control">Powrót</a>
<table>
<tr>
<th>Email</th>
<th>Usuń Konto</th>
<th>Zakończ VIP</th>
<th>Przedłuż VIP</th>
</tr>
{% for user in all_Vipuser %}
<tr>
<th><a href="/homepage/user_profile/{{user.email}}">{{user.email}}</a></th>
<th><a href="DeleteUser/{{user.id}}">Usuń</a></th>
<th><a href="DeleteVIP/{{user.id}}">Zakończ</a></th>
<th><a href="ExtendVIP/{{user.id}}">Przedłuż</a></th>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% block content %}
<!DOCTYPE html>
<a href="UserNotification"><button>Zgłoszenia Użytkowników: {{all_Notificationuser}} </button></a><br>
<a href="OfferNotification"><button>Zgłoszenia Ogłoszeń: {{all_Notificationoffer}}</button></a><br>
<a href="UserMessager"><button>Wiadomości od Użytkowników: {{all_Usermessage}}</button></a><br>
<a href="UserList"><button>Lista Użytkowników: {{all_User}}</button></a><br>
<a href="VIPUserList"><button>Lista Użytkowników Premium: {{all_Vipuser}}</button></a><br>
{% endblock %}

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,29 @@
from django.urls import path, include
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.pulpit, name='pulpit'),
path('UserNotification', views.NotificationuserPage, name='NotificationuserPage'),
path('DeleteUserNotification/<int:not_id>', views.Notificationuser_deletenot, name='Notificationuser_deletenot'),
path('DeleteUser/<int:user_id>', views.Notificationuser_deleteuser, name='Notificationuser_deleteuser'),
path('OfferNotification', views.NotificationofferPage, name='NotificationofferPage'),
path('DeleteOfferNotification/<int:not_id>', views.Notificationoffer_deletenot, name='Notificationoffer_deletenot'),
path('DeleteOffer/<int:offer_id>', views.Notificationoffer_deleteoffer, name='Notificationoffer_deleteoffer'),
path('UserMessager', views.UsermessagerPage, name='UsermessagerPage'),
path('DeleteUserMessager/<int:not_id>', views.Usermessager_deletenot, name='Usermessager_deletenot'),
path('VIPUserList', views.VipuserPage, name='VipuserPage'),
path('DeleteVIP/<int:vip_id>', views.Vipuser_delete, name='Vipuser_delete'),
path('ExtendVIP/<int:vip_id>', views.Vipuser_extension, name='Vipuser_extension'),
path('UserList', views.UserPage, name='UserPage'),
path('AddVIP/<int:user_id>', views.AddVIP, name='AddVIP'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -0,0 +1,203 @@
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.urls import reverse
from django.template import loader
from django.contrib.auth import get_user_model
from django.contrib import messages, auth
from django.utils import timezone
from django.views.decorators.clickjacking import xframe_options_exempt
from django.db.models import Q
from homepage.models import Product
from .models import Notificationuser, Notificationoffer, Usermessage, Vipuser
from django.core.mail import send_mail
from django.utils import timezone
from datetime import timedelta
import datetime
def pulpit(request):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
all_Notificationuser = Notificationuser.objects.filter(active = True).count()
all_Notificationoffer = Notificationoffer.objects.filter(active = True).count()
all_Usermessage = Usermessage.objects.filter(active = True).count()
all_User = User.objects.filter(is_active = True).count()
all_Vipuser_list = Vipuser.objects.values_list('user_iden', flat=True).distinct('user_iden').filter(active = True)
all_Vipuser = User.objects.filter(id__in = all_Vipuser_list).count()
template = loader.get_template('control/pulpit.html')
context = {
'all_Notificationuser': all_Notificationuser,
'all_Notificationoffer': all_Notificationoffer,
'all_Usermessage': all_Usermessage,
'all_Vipuser': all_Vipuser,
'all_User': all_User
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def NotificationuserPage(request):
if request.user.is_authenticated and request.user.is_superuser == True:
all_Notificationuser = Notificationuser.objects.filter(active = True)
template = loader.get_template('control/UserNotification.html')
context = {
'all_Notificationuser': all_Notificationuser,
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def Notificationuser_deletenot(request, not_id):
if request.user.is_authenticated and request.user.is_superuser == True:
instance = Notificationuser.objects.get(id=not_id)
instance.active = False
instance.save()
messages.success(request, 'Zgłoszenie Zamknięte')
return redirect(NotificationuserPage)
else:
return redirect(index)
def Notificationuser_deleteuser(request, user_id):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
instance = User.objects.get(id=user_id)
instance.is_active = False
instance.save()
messages.success(request, 'Użytkownik Usunięty')
return redirect(UserPage)
else:
return redirect(index)
def NotificationofferPage(request):
if request.user.is_authenticated and request.user.is_superuser == True:
all_Notificationoffer = Notificationoffer.objects.filter(active = True)
template = loader.get_template('control/OfferNotification.html')
context = {
'all_Notificationoffer': all_Notificationoffer,
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def Notificationoffer_deletenot(request, not_id):
if request.user.is_authenticated and request.user.is_superuser == True:
instance = Notificationoffer.objects.get(id=not_id)
instance.active = False
instance.save()
messages.success(request, 'Zgłoszenie Zamknięte')
return redirect(NotificationofferPage)
else:
return redirect(index)
def Notificationoffer_deleteoffer(request, offer_id):
if request.user.is_authenticated and request.user.is_superuser == True:
instance = Product.objects.get(id=offer_id)
instance.is_active = False
instance.save()
messages.success(request, 'Ogłoszenie Usunięte')
return redirect(NotificationofferPage)
else:
return redirect(index)
def UsermessagerPage(request):
if request.user.is_authenticated and request.user.is_superuser == True:
all_Usermessage = Usermessage.objects.filter(active = True)
template = loader.get_template('control/UserMessager.html')
context = {
'all_Usermessage': all_Usermessage,
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def Usermessager_deletenot(request, not_id):
if request.user.is_authenticated and request.user.is_superuser == True:
instance = Usermessage.objects.get(id=not_id)
instance.active = False
instance.save()
messages.success(request, 'Zgłoszenie Zamknięte')
return redirect(UsermessagerPage)
else:
return redirect(index)
def VipuserPage(request):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
all_Vipuser_list = Vipuser.objects.values_list('user_iden', flat=True).distinct('user_iden').filter(active = True)
all_Vipuser = User.objects.filter(id__in = all_Vipuser_list)
template = loader.get_template('control/VIPUserList.html')
context = {
'all_Vipuser': all_Vipuser,
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def Vipuser_delete(request, vip_id):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
vip = User.objects.get(id = vip_id)
instance = Vipuser.objects.get(user_iden = vip)
instance.active = False
instance.expires_date = timezone.now()
instance.save()
messages.success(request, 'Usunięto status VIP')
return redirect(VipuserPage)
else:
return redirect(index)
def Vipuser_extension(request, vip_id):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
vip = User.objects.get(id = vip_id)
instance = Vipuser.objects.get(user_iden = vip)
d = timedelta(days=31)
instance.expires_date += d
instance.save()
messages.success(request, 'Przedłużono status VIP')
return redirect(VipuserPage)
else:
return redirect(index)
def UserPage(request):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
all_User = User.objects.filter(is_active = True)
template = loader.get_template('control/UserList.html')
context = {
'all_User': all_User,
}
return HttpResponse(template.render(context, request))
else:
return redirect(index)
def AddVIP(request, user_id):
if request.user.is_authenticated and request.user.is_superuser == True:
User = get_user_model()
vip = User.objects.get(id = user_id)
d = timedelta(days=31)
if Vipuser.objects.filter(user_iden = vip, active = True).exists():
messages.error(request, 'Użytkownik już jest VIPem!')
return redirect(UserPage)
elif Vipuser.objects.filter(user_iden = vip, active = False).exists():
instance = Vipuser.objects.get(user_iden = vip)
instance.active = True
instance.expires_date += d
instance.save()
messages.success(request, 'Przywrócono status VIP')
return redirect(UserPage)
else:
new_vip = Vipuser(
active = True,
user_iden = vip,
expires_date = timezone.now() + d
)
new_vip.save()
messages.success(request, 'Nadano status VIP')
return redirect(UserPage)
else:
return redirect(index)

View File

@ -470,7 +470,7 @@ def user_profile(request, user_name):
types = TYPE_T
types_o = TYPE_O
suma = 0
if Ocena.objects.filter(user_iden = user_prof.id).exists():
ocena = 0
suma = 0