diff --git a/base/admin.py b/base/admin.py index 34ef61e..200c187 100644 --- a/base/admin.py +++ b/base/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. \ No newline at end of file +# Register your models here. +from .models import VendorsData + +admin.site.register(VendorsData) \ No newline at end of file diff --git a/base/models.py b/base/models.py index 4defafe..30b865f 100644 --- a/base/models.py +++ b/base/models.py @@ -1,23 +1,26 @@ from django.db import models from users.models import User +from django.contrib import admin # Create your models here. class VendorsData(models.Model): + id = models.BigAutoField(primary_key=True) vendorid = models.ForeignKey(User, default=None, on_delete=models.CASCADE) vendorUUID = models.UUIDField() vendor = models.CharField(max_length=8, unique=True) vendorSecretKey = models.UUIDField() vendorCoverAmount = models.IntegerField(default=0) - vendorPaidNotification = models.IntegerField(default=1) - vendorSkipScreen = models.IntegerField(default=0) - vendorPayWindow = models.IntegerField(default=0) + vendorPaidNotification = models.BooleanField(default=True) + vendorSkipScreen = models.BooleanField(default=False) + vendorPayWindow = models.BooleanField(default=True) vendorWebName = models.CharField(max_length=250) - vendorWebAddr = models.CharField(max_length=250) + vendorWebAddr = models.URLField(max_length=250) vendorAddDate = models.DateTimeField(auto_now_add=True) - vendorDeleted = models.IntegerField(default=0) - vendorAddDelete = models.DateTimeField(auto_now=True) - vendorIsActive = models.IntegerField(default=1) + vendorDeleted = models.BooleanField(default=False) + vendorUpdated = models.DateTimeField(auto_now=True) + vendorAddDelete = models.DateTimeField(auto_now_add=True) + vendorIsActive = models.BooleanField(default=True) def __str__(self): return self.vendor diff --git a/base/templates/base/vendor.html b/base/templates/base/vendor.html index f5ad1d9..41b49f9 100644 --- a/base/templates/base/vendor.html +++ b/base/templates/base/vendor.html @@ -1,6 +1,6 @@ {% extends "partials/base.html" %} {% load static %} -{% block title %}Dashboard{% endblock title %} +{% block title %}Vendor Page{% endblock title %} {% block content %} @@ -16,7 +16,6 @@

Vendor Page

- @@ -39,9 +38,9 @@ VendorID - Creation Date Website Name - + Created + Updated Status @@ -50,22 +49,18 @@ - ... - {{vendor.vendor}} - - {{vendor.vendorAddDate}} - - - ... - - {{vendor.vendorWebName}} - + {{vendor.vendorWebName}} + {{vendor.vendorAddDate}} + + + + {{vendor.vendorUpdated|timesince}} ago {% if vendor.vendorIsActive == 0 %} @@ -79,8 +74,8 @@ {% endif %} - Edit - Addresses + Edit + @@ -90,7 +85,14 @@ diff --git a/base/urls.py b/base/urls.py index f83b06d..ba06898 100644 --- a/base/urls.py +++ b/base/urls.py @@ -8,4 +8,6 @@ urlpatterns = [ path('', views.index, name="dashboard"), path('vendor/', views.VendorPage, name="vendor"), + path('vendor/edit//', views.VendorEditPage, name="edit-vendor"), + path('vendor/create', views.VendorCreatePage, name="create-vendor"), ] \ No newline at end of file diff --git a/base/views.py b/base/views.py index 43fefbd..8e8822d 100644 --- a/base/views.py +++ b/base/views.py @@ -1,10 +1,15 @@ from django.shortcuts import render, redirect from django.contrib import messages -from users.models import User -from .models import VendorsData from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required - +from django.core.exceptions import ValidationError +from django.db.models import Q +# +from users.models import User +from .models import VendorsData +from .forms import VendorEditForm +from .functions import vendor_generator +import uuid # Create your views here. @login_required(login_url='login') @@ -41,6 +46,75 @@ def LogoutPage(request): @login_required(login_url='login') def VendorPage(request): - vendors = VendorsData.objects.filter(vendorid_id=request.user.id) + vendors = VendorsData.objects.filter(Q(vendorid_id=request.user.id) & Q(vendorDeleted=False)) context = {'vendors': vendors} - return render(request, 'base/vendor.html', context) \ No newline at end of file + return render(request, 'base/vendor.html', context) + +@login_required(login_url='login') +def VendorEditPage(request, vdr ): + vendor = VendorsData.objects.get(vendorUUID=vdr) + try: + if vendor.vendorid_id is not request.user.id: + messages.error(request, "You are not authorized to edit this vendor") + return redirect('vendor') + except Exception as e: + messages.error(request, "Something wrong happened, try again.") + return redirect('vendor') + + + form = VendorEditForm() + vendor_title = "Edit Vendor" + if request.method == 'POST': + if request.POST.get('submit') == 'Submit': + try: + vendors = VendorsData.objects.get(vendorUUID=vdr) + form = VendorEditForm(request.POST, instance=vendors) + if form.is_valid(): + form.save() + messages.success(request, "Vendor information saved") + return redirect('vendor') + else: + messages.error(request, "Something wrong happened, try again.") + except Exception as e: + messages.error(request, "Something wrong happened, try again.") + vendors = VendorsData.objects.get(vendorUUID=vdr) + context = {'vendors': vendors, 'form': form, 'vendor_title': vendor_title} + return render(request, 'base/vendorEdit.html', context) + +@login_required(login_url='login') +def VendorCreatePage(request): + vendor_title = "Create Vendor" + if request.method == 'POST': + try: + form = VendorEditForm(request.POST) + if form.is_valid(): + # Generate vendor + new_vendor = form.save(commit=False) + try: + vdr = vendor_generator() + vendor_check = VendorsData.objects.get(vendorUUID=vdr) + while vendor_check is vdr: + vdr = vendor_generator() + vendor_check = VendorsData.objects.get(vendorUUID=vdr) + except: + pass + + new_vendor.vendor = vdr + new_vendor.vendorSecretKey = uuid.uuid4() + new_vendor.vendorUUID = uuid.uuid4() + new_vendor.vendorid_id = request.user.id + # Save vendor + try: + new_vendor.save() + messages.success(request, "Vendor created") + return redirect('vendor') + except Exception as e: + print(e) + else: + messages.error(request, "Something wrong happened, try again.") + except Exception as e: + messages.error(request, "Something wrong happened, try again.") + + + context = {'vendor_title': vendor_title} + return render(request, 'base/vendorEdit.html', context) \ No newline at end of file diff --git a/dLitepay/settings.py b/dLitepay/settings.py index 69f47b7..73c75b7 100644 --- a/dLitepay/settings.py +++ b/dLitepay/settings.py @@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-z#_ppfgs06)e4v18t!970-&-&jkxht!tw&ms#u5n_m-fbxulwa # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['10.0.70.5'] # User substitution # https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#auth-custom-user @@ -113,13 +113,13 @@ AUTH_PASSWORD_VALIDATORS = [ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] - +''' PASSWORD_HASHERS = [ 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', ] - +''' # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ diff --git a/templates/partials/base.html b/templates/partials/base.html index 75d3431..c2afdba 100755 --- a/templates/partials/base.html +++ b/templates/partials/base.html @@ -14,6 +14,8 @@ + + {% endblock css %}