Skip to content
Snippets Groups Projects
Commit 2c45a9f2 authored by Brody Wilton's avatar Brody Wilton
Browse files

Restrict ability to run app behind a token count of greater than 0

parent 0f8b2d26
Branches
No related tags found
1 merge request!29Restrict ability to run app behind a token count of greater than 0
......@@ -63,8 +63,8 @@ class UserTokenCount(models.Model):
@receiver(post_save, sender=User)
def create_or_update_user_profile(sender, instance, created, **kwargs):
if created:
UserTokenCount.objects.create(user=instance)
# Profile.objects.create(user=instance)
UserTokenCount.objects.get_or_create(user=instance)
Profile.objects.get_or_create(user=instance)
# instance.profile.save()
class Action(Enum):
......
......@@ -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">
......
......@@ -111,6 +111,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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment