forked from mike/django
vendor
This commit is contained in:
parent
3600ffcce5
commit
08e081bead
|
@ -1,3 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
from .models import VendorsData
|
||||||
|
|
||||||
|
admin.site.register(VendorsData)
|
|
@ -1,23 +1,26 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class VendorsData(models.Model):
|
class VendorsData(models.Model):
|
||||||
|
id = models.BigAutoField(primary_key=True)
|
||||||
vendorid = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
|
vendorid = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
|
||||||
vendorUUID = models.UUIDField()
|
vendorUUID = models.UUIDField()
|
||||||
vendor = models.CharField(max_length=8, unique=True)
|
vendor = models.CharField(max_length=8, unique=True)
|
||||||
vendorSecretKey = models.UUIDField()
|
vendorSecretKey = models.UUIDField()
|
||||||
vendorCoverAmount = models.IntegerField(default=0)
|
vendorCoverAmount = models.IntegerField(default=0)
|
||||||
vendorPaidNotification = models.IntegerField(default=1)
|
vendorPaidNotification = models.BooleanField(default=True)
|
||||||
vendorSkipScreen = models.IntegerField(default=0)
|
vendorSkipScreen = models.BooleanField(default=False)
|
||||||
vendorPayWindow = models.IntegerField(default=0)
|
vendorPayWindow = models.BooleanField(default=True)
|
||||||
vendorWebName = models.CharField(max_length=250)
|
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)
|
vendorAddDate = models.DateTimeField(auto_now_add=True)
|
||||||
vendorDeleted = models.IntegerField(default=0)
|
vendorDeleted = models.BooleanField(default=False)
|
||||||
vendorAddDelete = models.DateTimeField(auto_now=True)
|
vendorUpdated = models.DateTimeField(auto_now=True)
|
||||||
vendorIsActive = models.IntegerField(default=1)
|
vendorAddDelete = models.DateTimeField(auto_now_add=True)
|
||||||
|
vendorIsActive = models.BooleanField(default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.vendor
|
return self.vendor
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "partials/base.html" %}
|
{% extends "partials/base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% block title %}Dashboard{% endblock title %}
|
{% block title %}Vendor Page{% endblock title %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<!-- ============================================================== -->
|
<!-- ============================================================== -->
|
||||||
<!-- Start right Content here -->
|
<!-- Start right Content here -->
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
<h1 class="h2 mb-0 ls-tight"> Vendor Page </h1>
|
<h1 class="h2 mb-0 ls-tight"> Vendor Page </h1>
|
||||||
<hr class="navbar-divider my-1 opacity-20">
|
<hr class="navbar-divider my-1 opacity-20">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
<hr class="navbar-divider my-1 opacity-20">
|
<hr class="navbar-divider my-1 opacity-20">
|
||||||
|
@ -39,9 +38,9 @@
|
||||||
<thead class="thead-light">
|
<thead class="thead-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">VendorID</th>
|
<th scope="col">VendorID</th>
|
||||||
<th scope="col">Creation Date</th>
|
|
||||||
<th scope="col">Website Name</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 scope="col">Status</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -50,22 +49,18 @@
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<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.vendor}}
|
{{vendor.vendor}}
|
||||||
</a>
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{vendor.vendorAddDate}}
|
{{vendor.vendorWebName}}
|
||||||
</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>
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
|
{{vendor.vendorAddDate}}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{vendor.vendorUpdated|timesince}} ago
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if vendor.vendorIsActive == 0 %}
|
{% if vendor.vendorIsActive == 0 %}
|
||||||
|
@ -79,8 +74,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<a href="{{vendor.vendorUUID}}" class="btn btn-sm btn-neutral">Edit</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>
|
<!-- <a href="addresses/{{vendor.vendorUUID}}" class="btn btn-sm btn-neutral">Addresses</a> -->
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
@ -90,7 +85,14 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer border-0 py-5">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,4 +8,6 @@ urlpatterns = [
|
||||||
|
|
||||||
path('', views.index, name="dashboard"),
|
path('', views.index, name="dashboard"),
|
||||||
path('vendor/', views.VendorPage, name="vendor"),
|
path('vendor/', views.VendorPage, name="vendor"),
|
||||||
|
path('vendor/edit/<str:vdr>/', views.VendorEditPage, name="edit-vendor"),
|
||||||
|
path('vendor/create', views.VendorCreatePage, name="create-vendor"),
|
||||||
]
|
]
|
|
@ -1,10 +1,15 @@
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.contrib import messages
|
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 import authenticate, login, logout
|
||||||
from django.contrib.auth.decorators import login_required
|
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.
|
# Create your views here.
|
||||||
@login_required(login_url='login')
|
@login_required(login_url='login')
|
||||||
|
@ -41,6 +46,75 @@ def LogoutPage(request):
|
||||||
|
|
||||||
@login_required(login_url='login')
|
@login_required(login_url='login')
|
||||||
def VendorPage(request):
|
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}
|
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)
|
|
@ -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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = ['10.0.70.5']
|
||||||
|
|
||||||
# User substitution
|
# User substitution
|
||||||
# https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#auth-custom-user
|
# 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',
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
'''
|
||||||
PASSWORD_HASHERS = [
|
PASSWORD_HASHERS = [
|
||||||
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
|
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
|
||||||
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
||||||
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
|
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
|
||||||
]
|
]
|
||||||
|
'''
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||||
|
|
|
@ -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" />
|
<link href="https://unpkg.com/@webpixels/css@1.1.5/dist/index.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||||
<!-- Icons 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 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 %}
|
{% endblock css %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue