Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
desd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kj2-drupisz
desd
Commits
2c45a9f2
Commit
2c45a9f2
authored
1 year ago
by
Brody Wilton
Browse files
Options
Downloads
Patches
Plain Diff
Restrict ability to run app behind a token count of greater than 0
parent
0f8b2d26
Branches
Branches containing commit
No related tags found
1 merge request
!29
Restrict ability to run app behind a token count of greater than 0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
myproject/myapp/models.py
+2
-2
2 additions, 2 deletions
myproject/myapp/models.py
myproject/myapp/templates/index1.html
+12
-0
12 additions, 0 deletions
myproject/myapp/templates/index1.html
myproject/myapp/views.py
+2
-0
2 additions, 0 deletions
myproject/myapp/views.py
with
16 additions
and
2 deletions
myproject/myapp/models.py
+
2
−
2
View file @
2c45a9f2
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
myproject/myapp/templates/index1.html
+
12
−
0
View file @
2c45a9f2
...
...
@@ -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"
>
...
...
This diff is collapsed.
Click to expand it.
myproject/myapp/views.py
+
2
−
0
View file @
2c45a9f2
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment