Skip to content
Snippets Groups Projects
Commit 05061cdb authored by h4-rahman's avatar h4-rahman
Browse files

Merge branch 'main' into 'hamid'

# Conflicts:
#   myproject/myapp/urls.py
parents fa436a6a f7362085
Branches
No related tags found
1 merge request!31Added logging for file upload and running algorithm.
......@@ -3,6 +3,8 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
from enum import Enum
from django.dispatch import receiver
from django.db.models.signals import post_save
# class UserTypes(User):
# USER_TYPE_CHOICES = (
......@@ -47,6 +49,24 @@ class Profile(models.Model):
return f'{self.user.username} Profile'
# Model to hold the user token count
class UserTokenCount(models.Model):
# User
user = models.OneToOneField(User, on_delete=models.CASCADE)
# Token count
token_count = models.IntegerField(default=0)
def __str__(self):
return f'{self.user.username}\'s token count: {self.token_count}'
# Automatically create a UserTokenCount entry for each user on user creation
@receiver(post_save, sender=User)
def create_or_update_user_profile(sender, instance, created, **kwargs):
if created:
UserTokenCount.objects.get_or_create(user=instance)
Profile.objects.get_or_create(user=instance)
# instance.profile.save()
class Action(Enum):
UPLOAD_FILE = "The user has successfully uploaded a file."
LOGIN = "The user has logged in to their account."
......
import paypalrestsdk
from django.conf import settings
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.urls import reverse
from django.shortcuts import redirect, render
from django.urls import reverse
from .models import UserTokenCount
# Create a payment that can be made via the PayPal API
# Create a payment that can be made via the PayPal API
def create_payment(request):
# Configure PayPal SDK
paypalrestsdk.configure({
"mode": settings.PAYPAL_MODE,
"client_id": settings.PAYPAL_CLIENT_ID,
"client_secret": settings.PAYPAL_CLIENT_SECRET
})
# Create payment object
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal",
},
"redirect_urls": {
"return_url": request.build_absolute_uri(reverse('execute_payment')),
"cancel_url": request.build_absolute_uri(reverse('payment_cancelled')),
},
"transactions" : [{
"item_list" : {
"items" : [{
"name": "Test item",
"sku": "test item",
"price": "9.99",
"currency": "GBP",
"quantity": 1,
}]
},
"amount" : {
"total": "9.99",
"currency": "GBP"
},
"description": "Test payment description"
}]
})
# Successfully communicated with API
if payment.create():
print("Payment created successfully!")
# get url for payment approval
for link in payment.links:
if link.rel == "approval_url":
# turn link into text
approval_url = str(link.href)
# send on merry way
return redirect(approval_url)
else:
print(payment.error)
# Execute a successful payment
def execute_payment(request):
# Get payment id and payer id
payment_id = request.GET.get('paymentId')
payer_id = request.GET.get('PayerID')
#If neither ID, error, restart
if not payment_id or not payer_id:
print("no payment")
#TODO: Change this to a more appropriate path, maybe a generic error page that takes a string:Error to display in a template
return redirect('handler404')
# configure API
paypalrestsdk.configure({
"mode": settings.PAYPAL_MODE,
"client_id": settings.PAYPAL_CLIENT_ID,
"client_secret": settings.PAYPAL_CLIENT_SECRET
})
# Check we've got a successful payment
payment = paypalrestsdk.Payment.find(payment_id)
# If it we do an the payer IDs match
if payment.execute({"payer_id": payer_id}):
print("Payment executed successfully!")
# Allocate some tokens
user = request.user
tokens_purchased = 1
# increment user_tokens
# commit changes
# TODO: Change something here such that the token amount added depends on a detail of the transaction,
# i.e. £9.99 payment for one token or £24.99 for
#
add_tokens(user, tokens_purchased)
return redirect('success')
else:
#TODO: Change this to a more appropriate error message
print("exiting at the end of execute_payment()")
return redirect('handler404')
def add_tokens(user, tokens):
token_count_instance, created = UserTokenCount.objects.get_or_create(user=user)
token_count_instance.token_count += tokens
token_count_instance.save()
def payment_cancelled(request):
return render(request, 'payment_cancelled.html')
def payment_success(request):
return render(request,'payment_success.html')
......@@ -19,6 +19,7 @@
</div>
</div>
{% if token_count > 0 %}
<div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2">
<form enctype="multipart/form-data" method="post" id="uploadForm">
{% csrf_token %}
......@@ -30,6 +31,17 @@
</button>
</form>
</div>
{% else %}
<div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2">
<div class="font-light text-gray-500 sm:text-lg dark:text-gray-400">
<h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Tokens required</h2>
<p class="mb-4">You require more tokens to use this service</p>
<button class="text-white bg-gray-800 hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700">
<a href="{% url 'pricing' %}">Buy Tokens</a>
</button>
</div>
</div>
{% endif %}
<div id="player" class="py-8 px-4 mx-auto max-w-screen-xl lg:py-8 hidden">
......
{% extends "_base.html" %}{% block content %}
<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid">
<div class="font-light text-gray-500 sm:text-lg dark:text-gray-400">
<h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Payment Cancelled</h2>
<p class="mb-4">Your payment has been cancelled.</p>
</div>
</div>
<button class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center text-center"><a href="{% url 'pricing' %}">Return</a></button>
{% endblock content%}
{% extends "_base.html" %}{% block content %}
<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid">
<div class="font-light text-gray-500 sm:text-lg dark:text-gray-400">
<h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Success!</h2>
<p class="mb-4">Your payment was successful and you have been credited with 1 token.</p>
</div>
</div>
<button class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center text-center"><a href="{% url 'users' %}">Return</a></button>
{% endblock content%}
{% extends "_base.html" %}{% block content %}
<div class="grid content-start">
<div class="my-5">
<h1>Purchase Tokens</h1>
<p>We operate through a token model. To use our service, you must purchase tokens that can be redeemed for model runs.</p>
<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid">
<div class="font-light text-gray-500 sm:text-lg dark:text-gray-400">
<h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">An Intelligent System for Instrument Detection</h2>
<p class="mb-4">*placeholder input* We present to you a intelligent system for instrument detection. Using audio processing techinques and a convolutionsal
neural network we are able to classify instruments used in a song. other exciting words that might catch peoples attention and make them use our product.
To use our service upload an mp3 file below.
*placeholder input*
</p>
</div>
</div>
<div class="grid grid-cols-2 content-start">
<div class="w-full mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700">
<h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Trial plan</h5>
<div class="w-full h-80 mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700">
<h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Single Purchase</h5>
<div class="flex items-baseline text-gray-900 dark:text-white">
<span class="text-5xl font-extrabold tracking-tight">Free</span>
<span class="text-5xl font-extrabold tracking-tight">£9.99</span>
</div>
<ul role="list" class="space-y-5 my-7">
<li class="flex items-center">
<svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">1 team member</span>
</li>
<li class="flex">
<svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">0GB Cloud storage</span>
</li>
<li class="flex decoration-gray-500">
<svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 ms-3">1 File upload</span>
<span class="ms-1 text-sm font-normal text-gray-500 dark:text-gray-400">/month</span>
</li>
<li class="flex line-through decoration-gray-500">
<svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">Integration help</span>
<span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">1 token</span>
</li>
<li class="flex line-through decoration-gray-500">
<li class="flex decoration-gray-500">
<svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 ms-3">API Access</span>
</li>
<li class="flex line-through decoration-gray-500">
<li class="flex decoration-gray-500">
<svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 ms-3">Complete documentation</span>
</li>
<li class="flex line-through decoration-gray-500">
<svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
</svg>
<span class="text-base font-normal leading-tight text-gray-500 ms-3">24×7 phone & email support</span>
<span class="text-base font-normal leading-tight text-gray-500 ms-3">Email support</span>
</li>
</ul>
<button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center w-full text-center">Choose plan</button>
<button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center w-full text-center"><a href="{% url 'create_payment' %}">Purchase via PayPal</a></button>
</div>
<div class="w-full mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700">
<h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Standard plan</h5>
<h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Bulk Purchase</h5>
<div class="flex items-baseline text-gray-900 dark:text-white">
<span class="text-3xl font-semibold">£</span>
<span class="text-5xl font-extrabold tracking-tight">49</span>
......
......@@ -3,156 +3,31 @@
class="grid grid-cols-1 px-4 pt-6 xl:grid-cols-3 xl:gap-4 dark:bg-grey-300"
>
<div class="mb-4 col-span-full xl:mb-2">
<h1 class="text-xl font-semibold text-gray-800 sm:text-2xl dark:text-white">
<h1 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">
User settings
</h1>
<h3 class="mb-4 text-xl font-semibold dark:text-white">
User type: {{ user_profile.user_type }}
</h3>
</div>
<!-- Right Content -->
<div class="col-span-full xl:col-auto">
<div class="p-4 mb-4 bg-white border boder-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<h3 class="mb-4 text-xl font-semibold dark:text-white">Tokens:</h3>
<p class="mb-4 text-xl font-semibold dark:text-white">{{ token_count }}</p>
</div>
<div class="p-4 mb-4 bg-white border boder-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<h3 class="mb-4 text-xl font-semibold dark:text-white">Change your password</h3>
<a href="{% url 'password_change' %}" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Change Password</a>
</div>
<!-- <div
class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"
>
<h3 class="mb-4 text-xl font-semibold dark:text-white">
Password information
</h3>
<form action="#">
<div class="grid grid-cols-6 gap-6">
<div class="col-span-6 sm:col-span-3">
<label
for="current-password"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Current password</label
>
<input
type="text"
name="current-password"
id="current-password"
class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="••••••••"
required
/>
</div>
<div class="col-span-6 sm:col-span-3">
<label
for="password"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>New password</label
>
<input
data-popover-target="popover-password"
data-popover-placement="bottom"
type="password"
id="password"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="••••••••"
required
/>
<div
data-popover
id="popover-password"
role="tooltip"
class="absolute z-10 invisible inline-block text-sm font-light text-gray-500 transition-opacity duration-300 bg-white border border-gray-200 rounded-lg shadow-sm opacity-0 w-72 dark:bg-gray-800 dark:border-gray-600 dark:text-gray-400"
>
<div class="p-3 space-y-2">
<h3 class="font-semibold text-gray-900 dark:text-white">
Must have at least 6 characters
</h3>
<div class="grid grid-cols-4 gap-2">
<div class="h-1 bg-orange-300 dark:bg-orange-400"></div>
<div class="h-1 bg-orange-300 dark:bg-orange-400"></div>
<div class="h-1 bg-gray-200 dark:bg-gray-600"></div>
<div class="h-1 bg-gray-200 dark:bg-gray-600"></div>
</div>
<p>It’s better to have:</p>
<ul>
<li class="flex items-center mb-1">
<svg
class="w-4 h-4 mr-2 text-green-400 dark:text-green-500"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clip-rule="evenodd"
></path>
</svg>
Upper & lower case letters
</li>
<li class="flex items-center mb-1">
<svg
class="w-4 h-4 mr-2 text-gray-300 dark:text-gray-400"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"
></path>
</svg>
A symbol (#$&)
</li>
<li class="flex items-center">
<svg
class="w-4 h-4 mr-2 text-gray-300 dark:text-gray-400"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"
></path>
</svg>
A longer password (min. 12 chars.)
</li>
</ul>
</div>
<div data-popper-arrow></div>
</div>
</div>
<div class="col-span-6 sm:col-span-3">
<label
for="confirm-password"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>Confirm password</label
>
<input
type="text"
name="confirm-password"
id="confirm-password"
class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="••••••••"
required
/>
</div>
<div class="col-span-6 sm:col-full">
<button
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
type="submit"
>
Save all
</button>
</div>
</div>
</form>
{% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %}
</div> -->
{% if 1 %}
{% if user_profile.user_type == 3 %}
<div
class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"
>
<h3 class="mb-4 text-xl font-semibold dark:text-white">
Generate Financial Statement
</h3>
......@@ -200,7 +75,8 @@
</form>
{% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %}
</div>
{% endif %} {% if 1 %}
{% endif %}
{% if 1 %}
<div
class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"
......@@ -261,7 +137,7 @@
class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="example@gmail.com"
required
>example@gmail.com</span
>{{ user.email }}</span
>
</div>
<div class="col-span-6 sm:col-span-3">
......@@ -277,7 +153,7 @@
class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="Green"
required
>LoginExample</span
>{{ user.username }}</span
>
</div>
</div>
......@@ -324,7 +200,7 @@
</div>
{% if 1 %} {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER
{%endcomment %}
{% if user_profile.user_type == 2 %}
<div
class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"
>
......@@ -369,6 +245,7 @@
</tbody>
</table>
</div>
{% endif %}
{% endif %} {% comment %} Admin page functionality end {% endcomment %}
</div>
</div>
......
from django.urls import path
from .views import InstrumentDetectionView, index, log_fileupload, users, maintenance, handler404, handler500, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table
from .views import InstrumentDetectionView, index, users, maintenance, handler404, handler500, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table
from .payments import create_payment, execute_payment, payment_cancelled, payment_success
from django.contrib.auth import views as auth_views
# Authentication
......@@ -10,7 +10,7 @@ from django.contrib.auth.views import LoginView, LogoutView
urlpatterns = [
path('', index, name='index'),
path('user/', users, name='users'),
path('404/', handler404),
path('404/', handler404, name='handler404'),
path('500/', handler500),
path('maintenance/', maintenance),
# path('register/', register, name='register'),
......@@ -26,11 +26,20 @@ urlpatterns = [
path('instrument_detection/', InstrumentDetectionView.as_view(), name='instrument_detection'),
path('password_change/', auth_views.PasswordChangeView.as_view(template_name='password_change_form.html'), name='password_change'),
path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'), name='password_change_done'),
# path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout')
path('log_fileupload', log_fileupload, name='log_fileupload'),
# path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'),
path('payment/create/', create_payment, name='create_payment'),
path('payment/execute/', execute_payment, name='execute_payment'),
path('payment/cancel/', payment_cancelled, name='payment_cancelled'),
path('payment_success/', payment_success, name='success'),
# Authentication
path('login/', CustomLoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
path('register/', RegisterView.as_view(), name='register'),
path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'),
# Payment
path('payment/create/', create_payment, name='create_payment'),
path('payment/execute/', execute_payment, name='execute_payment'),
path('payment/cancel/', payment_cancelled, name='payment_cancelled'),
path('payment_success/', payment_success, name='success')
]
......@@ -12,7 +12,7 @@ import json
from datetime import datetime
from .forms import InstrumentDetectionForm
from .models import Log, Action, User
from .models import Log, Action, User, UserTokenCount
from django.http import JsonResponse
from django.db import connection
......@@ -128,6 +128,8 @@ def index(request):
# Handle authenticated users
if request.user.is_authenticated:
token_count = UserTokenCount.objects.get(user=request.user).token_count
context['token_count'] = token_count
if request.method == 'POST':
form = InstrumentDetectionForm(request.POST, request.FILES)
if form.is_valid() and 'audio_file' in request.FILES:
......@@ -171,10 +173,16 @@ def users(request):
data_user = user_table(request)
admin_dict = json.loads(data_admin.content)
user_dict = json.loads(data_user.content)
token_count = UserTokenCount.objects.get(user=request.user).token_count
user_profile = request.user.profile
user = request.user
# Pass the data as a context variable to the template
# !!! ADMIN DATA ONLY DISPLAYED AND GET IF USER IS ADMIN !!!
context['admin_data'] = admin_dict['data']
context['user_data'] = user_dict['data']
context['token_count'] = token_count
context['user_profile'] = user_profile
context['user'] = user
return render(request, 'user_page.html', context)
......
......@@ -173,4 +173,10 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
IMAGE_URL = 'static/src/images/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
#PayPal API settings
PAYPAL_MODE = 'sandbox'
PAYPAL_CLIENT_ID = 'AYpHxonrFMrgnqmjii46SeNsQidn2PjJtEoIgVK0Nrda1iQFUbX28zyuMvUiJk67o_cHII3c8vCMWY-y'
PAYPAL_CLIENT_SECRET = 'EPXXK3Z7xDr4Gy_kt4OkPLbJRXd9tP62q1Dpbmj5QiwaFh7twcSUalHDRBbFRwxdX_rmHk_F6YStXa95'
......@@ -37,4 +37,5 @@ urllib3==2.2.1
reportlab==4.1.0
chardet==5.2.0
charset-normalizer==3.3.2
pillow==10.2.0
\ No newline at end of file
pillow==10.2.0
paypalrestsdk==1.13.3
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment