This commit is contained in:
Bob 2023-05-05 23:15:03 +03:00
parent 3600ffcce5
commit 08e081bead
7 changed files with 119 additions and 33 deletions

View File

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
# Register your models here.
from .models import VendorsData
admin.site.register(VendorsData)

View File

@ -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

View File

@ -1,6 +1,6 @@
{% extends "partials/base.html" %}
{% load static %}
{% block title %}Dashboard{% endblock title %}
{% block title %}Vendor Page{% endblock title %}
{% block content %}
<!-- ============================================================== -->
<!-- Start right Content here -->
@ -16,7 +16,6 @@
<!-- Title -->
<h1 class="h2 mb-0 ls-tight"> Vendor Page </h1>
<hr class="navbar-divider my-1 opacity-20">
</div>
<!-- Actions -->
<hr class="navbar-divider my-1 opacity-20">
@ -39,9 +38,9 @@
<thead class="thead-light">
<tr>
<th scope="col">VendorID</th>
<th scope="col">Creation Date</th>
<th scope="col">Website Name</th>
<th scope="col"></th>
<th scope="col">Created</th>
<th scope="col">Updated</th>
<th scope="col">Status</th>
<th></th>
</tr>
@ -50,22 +49,18 @@
<tr>
<td>
<img alt="..." src="https://preview.webpixels.io/web/img/other/logos/logo-1.png" class="avatar avatar-xs rounded-circle me-2">
<a class="text-heading font-semibold" href="#">
{{vendor.vendor}}
</a>
</td>
<td>
{{vendor.vendorAddDate}}
</td>
<td>
<img alt="..." src="https://preview.webpixels.io/web/img/other/logos/logo-1.png" class="avatar avatar-xs rounded-circle me-2">
<a class="text-heading font-semibold" href="#">
{{vendor.vendorWebName}}
</a>
{{vendor.vendorWebName}}
</td>
<td>
{{vendor.vendorAddDate}}
</td>
<td>
{{vendor.vendorUpdated|timesince}} ago
</td>
<td>
{% if vendor.vendorIsActive == 0 %}
@ -79,8 +74,8 @@
{% endif %}
</td>
<td class="text-end">
<a href="{{vendor.vendorUUID}}" class="btn btn-sm btn-neutral">Edit</a>
<a href="addresses/{{vendor.vendorUUID}}" class="btn btn-sm btn-neutral">Addresses</a>
<a href="{% url 'edit-vendor' vendor.vendorUUID %}" class="btn btn-sm btn-neutral">Edit</a>
<!-- <a href="addresses/{{vendor.vendorUUID}}" class="btn btn-sm btn-neutral">Addresses</a> -->
</td>
</tr>
@ -90,7 +85,14 @@
</table>
</div>
<div class="card-footer border-0 py-5">
<span class="text-muted text-sm">#</span>
<div class="text-center"> <a href="{% url 'create-vendor' %}" class="btn btn-sm btn-primary">Create</a> </div>
{% if messages %}
<ul class="messages text-center">
{% for message in messages %}
<p{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</p>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>

View File

@ -8,4 +8,6 @@ urlpatterns = [
path('', views.index, name="dashboard"),
path('vendor/', views.VendorPage, name="vendor"),
path('vendor/edit/<str:vdr>/', views.VendorEditPage, name="edit-vendor"),
path('vendor/create', views.VendorCreatePage, name="create-vendor"),
]

View File

@ -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)
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)

View File

@ -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/

View File

@ -14,6 +14,8 @@
<link href="https://unpkg.com/@webpixels/css@1.1.5/dist/index.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
<!-- Icons Css -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.4.0/font/bootstrap-icons.min.css" rel="stylesheet" type="text/css" />
<!-- -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
{% endblock css %}
</head>