diff --git a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc index 3f237a5..4d73774 100644 Binary files a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc and b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc differ diff --git a/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc index dedee57..66a155b 100644 Binary files a/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc and b/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/SocialHelper/settings.py b/SocialHelper/SocialHelper/settings.py index 5cb9ba6..fca1973 100644 --- a/SocialHelper/SocialHelper/settings.py +++ b/SocialHelper/SocialHelper/settings.py @@ -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', diff --git a/SocialHelper/SocialHelper/urls.py b/SocialHelper/SocialHelper/urls.py index 6daf9c2..0c1721f 100644 --- a/SocialHelper/SocialHelper/urls.py +++ b/SocialHelper/SocialHelper/urls.py @@ -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) diff --git a/SocialHelper/control/__init__.py b/SocialHelper/control/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SocialHelper/control/__pycache__/__init__.cpython-37.pyc b/SocialHelper/control/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..6607e85 Binary files /dev/null and b/SocialHelper/control/__pycache__/__init__.cpython-37.pyc differ diff --git a/SocialHelper/control/__pycache__/admin.cpython-37.pyc b/SocialHelper/control/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..5197a4a Binary files /dev/null and b/SocialHelper/control/__pycache__/admin.cpython-37.pyc differ diff --git a/SocialHelper/control/__pycache__/apps.cpython-37.pyc b/SocialHelper/control/__pycache__/apps.cpython-37.pyc new file mode 100644 index 0000000..4130692 Binary files /dev/null and b/SocialHelper/control/__pycache__/apps.cpython-37.pyc differ diff --git a/SocialHelper/control/__pycache__/models.cpython-37.pyc b/SocialHelper/control/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..ebc5387 Binary files /dev/null and b/SocialHelper/control/__pycache__/models.cpython-37.pyc differ diff --git a/SocialHelper/control/__pycache__/urls.cpython-37.pyc b/SocialHelper/control/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..6016956 Binary files /dev/null and b/SocialHelper/control/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/control/__pycache__/views.cpython-37.pyc b/SocialHelper/control/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..5999900 Binary files /dev/null and b/SocialHelper/control/__pycache__/views.cpython-37.pyc differ diff --git a/SocialHelper/control/admin.py b/SocialHelper/control/admin.py new file mode 100644 index 0000000..767181c --- /dev/null +++ b/SocialHelper/control/admin.py @@ -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) diff --git a/SocialHelper/control/apps.py b/SocialHelper/control/apps.py new file mode 100644 index 0000000..a5f7085 --- /dev/null +++ b/SocialHelper/control/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ControlConfig(AppConfig): + name = 'control' diff --git a/SocialHelper/control/migrations/0001_initial.py b/SocialHelper/control/migrations/0001_initial.py new file mode 100644 index 0000000..cfc819d --- /dev/null +++ b/SocialHelper/control/migrations/0001_initial.py @@ -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')), + ], + ), + ] diff --git a/SocialHelper/control/migrations/__init__.py b/SocialHelper/control/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SocialHelper/control/migrations/__pycache__/0001_initial.cpython-37.pyc b/SocialHelper/control/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..f9a5c53 Binary files /dev/null and b/SocialHelper/control/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/SocialHelper/control/migrations/__pycache__/__init__.cpython-37.pyc b/SocialHelper/control/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..406921a Binary files /dev/null and b/SocialHelper/control/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/SocialHelper/control/models.py b/SocialHelper/control/models.py new file mode 100644 index 0000000..4cae6d3 --- /dev/null +++ b/SocialHelper/control/models.py @@ -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') diff --git a/SocialHelper/control/templates/control/OfferNotification.html b/SocialHelper/control/templates/control/OfferNotification.html new file mode 100644 index 0000000..61a9283 --- /dev/null +++ b/SocialHelper/control/templates/control/OfferNotification.html @@ -0,0 +1,23 @@ + +{% block content %} + +Powrót + + + + + + + + +{% for offer in all_Notificationoffer %} + + + + + + + +{% endfor %} +
Nr OfertyOpis ZgłoszeniaData ZgłoszeniaUsuń OferteZamknij Zgłoszenie
{{offer.id}}{{offer.text}}{{offer.date}}UsuńZamknij
+{% endblock %} diff --git a/SocialHelper/control/templates/control/UserList.html b/SocialHelper/control/templates/control/UserList.html new file mode 100644 index 0000000..7f81fa2 --- /dev/null +++ b/SocialHelper/control/templates/control/UserList.html @@ -0,0 +1,18 @@ +{% block content %} + +Powrót + + + + + + +{% for user in all_User %} + + + + + +{% endfor %} +
EmailNadaj VIPUsuń Konto
{{user.email}}DodajUsuń
+{% endblock %} diff --git a/SocialHelper/control/templates/control/UserMessager.html b/SocialHelper/control/templates/control/UserMessager.html new file mode 100644 index 0000000..f4bc3d5 --- /dev/null +++ b/SocialHelper/control/templates/control/UserMessager.html @@ -0,0 +1,21 @@ + +{% block content %} + +Powrót + + + + + + + +{% for mess in all_Usermessage %} + + + + + + +{% endfor %} +
AdresatemailTreśćZamknij Zgłoszenie
{{mess.name}}{{mess.email}}{{mess.text}}Zamknij
+{% endblock %} diff --git a/SocialHelper/control/templates/control/UserNotification.html b/SocialHelper/control/templates/control/UserNotification.html new file mode 100644 index 0000000..d4b3f6b --- /dev/null +++ b/SocialHelper/control/templates/control/UserNotification.html @@ -0,0 +1,23 @@ + +{% block content %} + +Powrót + + + + + + + + +{% for user in all_Notificationuser %} + + + + + + + +{% endfor %} +
EmailOpis ZgłoszeniaData ZgłoszeniaUsuń UżytkownikaZamknij Zgłoszenie
{{user.user_iden}}{{user.text}}{{user.date}}UsuńZamknij
+{% endblock %} diff --git a/SocialHelper/control/templates/control/VIPUserList.html b/SocialHelper/control/templates/control/VIPUserList.html new file mode 100644 index 0000000..e251a3b --- /dev/null +++ b/SocialHelper/control/templates/control/VIPUserList.html @@ -0,0 +1,20 @@ +{% block content %} + +Powrót + + + + + + + +{% for user in all_Vipuser %} + + + + + + +{% endfor %} +
EmailUsuń KontoZakończ VIPPrzedłuż VIP
{{user.email}}UsuńZakończPrzedłuż
+{% endblock %} diff --git a/SocialHelper/control/templates/control/pulpit.html b/SocialHelper/control/templates/control/pulpit.html new file mode 100644 index 0000000..1681187 --- /dev/null +++ b/SocialHelper/control/templates/control/pulpit.html @@ -0,0 +1,11 @@ + +{% block content %} + + +
+
+
+
+
+ +{% endblock %} diff --git a/SocialHelper/control/tests.py b/SocialHelper/control/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/SocialHelper/control/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/SocialHelper/control/urls.py b/SocialHelper/control/urls.py new file mode 100644 index 0000000..de9d510 --- /dev/null +++ b/SocialHelper/control/urls.py @@ -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/', views.Notificationuser_deletenot, name='Notificationuser_deletenot'), + path('DeleteUser/', views.Notificationuser_deleteuser, name='Notificationuser_deleteuser'), + + path('OfferNotification', views.NotificationofferPage, name='NotificationofferPage'), + path('DeleteOfferNotification/', views.Notificationoffer_deletenot, name='Notificationoffer_deletenot'), + path('DeleteOffer/', views.Notificationoffer_deleteoffer, name='Notificationoffer_deleteoffer'), + + path('UserMessager', views.UsermessagerPage, name='UsermessagerPage'), + path('DeleteUserMessager/', views.Usermessager_deletenot, name='Usermessager_deletenot'), + + path('VIPUserList', views.VipuserPage, name='VipuserPage'), + path('DeleteVIP/', views.Vipuser_delete, name='Vipuser_delete'), + path('ExtendVIP/', views.Vipuser_extension, name='Vipuser_extension'), + + path('UserList', views.UserPage, name='UserPage'), + path('AddVIP/', views.AddVIP, name='AddVIP'), + + +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/SocialHelper/control/views.py b/SocialHelper/control/views.py new file mode 100644 index 0000000..2ca4cc8 --- /dev/null +++ b/SocialHelper/control/views.py @@ -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) diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index 9d4d0b1..ff398b9 100644 Binary files a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index 14daca5..4d3c09d 100644 Binary files a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc differ diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index 6fac099..d35fd52 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -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