Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Netguru
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Piotr Maślanka
Netguru
Commits
ee62b7b5
Commit
ee62b7b5
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
a quick model fix
parent
b893a532
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
shares/migrations/0001_initial.py
+2
-2
2 additions, 2 deletions
shares/migrations/0001_initial.py
shares/models.py
+1
-1
1 addition, 1 deletion
shares/models.py
shares/templates/share/view.html
+3
-0
3 additions, 0 deletions
shares/templates/share/view.html
shares/views.py
+3
-2
3 additions, 2 deletions
shares/views.py
with
9 additions
and
5 deletions
shares/migrations/0001_initial.py
+
2
−
2
View file @
ee62b7b5
# Generated by Django 3.2.6 on 2021-08-26 14:
26
# Generated by Django 3.2.6 on 2021-08-26 14:
41
import
datetime
import
datetime
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -23,7 +23,7 @@ class Migration(migrations.Migration):
...
@@ -23,7 +23,7 @@ class Migration(migrations.Migration):
(
'
created_on
'
,
models
.
DateTimeField
(
db_index
=
True
,
default
=
datetime
.
datetime
.
now
,
verbose_name
=
'
Created on
'
)),
(
'
created_on
'
,
models
.
DateTimeField
(
db_index
=
True
,
default
=
datetime
.
datetime
.
now
,
verbose_name
=
'
Created on
'
)),
(
'
pwd_hash
'
,
models
.
CharField
(
max_length
=
64
,
verbose_name
=
'
Hashed password salt
'
)),
(
'
pwd_hash
'
,
models
.
CharField
(
max_length
=
64
,
verbose_name
=
'
Hashed password salt
'
)),
(
'
resource
'
,
models
.
TextField
(
verbose_name
=
'
Resource
'
)),
(
'
resource
'
,
models
.
TextField
(
verbose_name
=
'
Resource
'
)),
(
'
used
'
,
models
.
Boolean
Field
(
default
=
False
,
verbose_name
=
'
Has been used?
'
)),
(
'
times_
used
'
,
models
.
Integer
Field
(
default
=
0
,
verbose_name
=
'
Visit count
'
)),
(
'
creator
'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
settings
.
AUTH_USER_MODEL
,
verbose_name
=
'
Creator
'
)),
(
'
creator
'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
settings
.
AUTH_USER_MODEL
,
verbose_name
=
'
Creator
'
)),
],
],
),
),
...
...
This diff is collapsed.
Click to expand it.
shares/models.py
+
1
−
1
View file @
ee62b7b5
...
@@ -30,7 +30,7 @@ class Share(models.Model):
...
@@ -30,7 +30,7 @@ class Share(models.Model):
pwd_hash
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
'
Hashed password salt
'
)
pwd_hash
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
'
Hashed password salt
'
)
# this is either an URL or a f'{UUID}.real_file_name' in /data
# this is either an URL or a f'{UUID}.real_file_name' in /data
resource
=
models
.
TextField
(
verbose_name
=
'
Resource
'
)
resource
=
models
.
TextField
(
verbose_name
=
'
Resource
'
)
used
=
models
.
Boolean
Field
(
verbose_name
=
'
Has been used?
'
,
default
=
False
)
times_
used
=
models
.
Integer
Field
(
verbose_name
=
'
Visit count
'
,
default
=
0
)
@property
@property
def
file_name
(
self
)
->
str
:
def
file_name
(
self
)
->
str
:
...
...
This diff is collapsed.
Click to expand it.
shares/templates/share/view.html
+
3
−
0
View file @
ee62b7b5
...
@@ -4,6 +4,9 @@
...
@@ -4,6 +4,9 @@
{% block head %}
{% block head %}
{% endblock %}
{% endblock %}
{% block body %}
{% block body %}
{% if invalid_password %}
<em>
The password that you provided was invalid!
</em>
{% endif %}
<form
class=
"form-group text-left"
role=
"form"
action=
"/shares/{{ share_id }}"
method=
"POST"
>
<form
class=
"form-group text-left"
role=
"form"
action=
"/shares/{{ share_id }}"
method=
"POST"
>
{% csrf_token %}
{% csrf_token %}
{{ form.as_p }}
{{ form.as_p }}
...
...
This diff is collapsed.
Click to expand it.
shares/views.py
+
3
−
2
View file @
ee62b7b5
...
@@ -123,7 +123,8 @@ def view_share(request, share_id: str):
...
@@ -123,7 +123,8 @@ def view_share(request, share_id: str):
try
:
try
:
if
share
.
share_type
==
SHARE_URL
:
if
share
.
share_type
==
SHARE_URL
:
links_visited
.
runtime
(
+
1
)
links_visited
.
runtime
(
+
1
)
return
redirect
(
share
.
resource
)
return
render
(
request
,
'
share/view.html
'
,
{
'
form
'
:
form
,
'
share_id
'
:
share_id
,
'
invalid_password
'
:
True
})
else
:
else
:
if
not
os
.
path
.
exists
(
share
.
path
):
if
not
os
.
path
.
exists
(
share
.
path
):
raise
Http404
()
raise
Http404
()
...
@@ -145,7 +146,7 @@ def view_share(request, share_id: str):
...
@@ -145,7 +146,7 @@ def view_share(request, share_id: str):
'
Content-Disposition
'
:
cd
'
Content-Disposition
'
:
cd
})
})
finally
:
finally
:
share
.
used
=
True
share
.
times_
used
+
=
1
share
.
save
()
share
.
save
()
else
:
else
:
form
=
PasswordForm
()
form
=
PasswordForm
()
...
...
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