Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
Respect My Net
Commits
6611ec9d
Commit
6611ec9d
authored
Jun 12, 2011
by
stef
Browse files
[enh] files are stored with a hashed name
parent
e5391246
Changes
2
Hide whitespace changes
Inline
Side-by-side
bt/models.py
View file @
6611ec9d
...
...
@@ -71,6 +71,7 @@ class Comment(models.Model):
class
Attachment
(
models
.
Model
):
storage
=
models
.
FileField
(
upload_to
=
'static'
)
name
=
models
.
CharField
(
max_length
=
512
)
comment
=
models
.
ForeignKey
(
Comment
)
class
ViolationModerator
(
CommentModerator
):
...
...
bt/views.py
View file @
6611ec9d
...
...
@@ -9,7 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist
from
models
import
Violation
,
Attachment
,
Comment
from
tempfile
import
mkstemp
from
datetime
import
datetime
import
hashlib
,
os
,
re
,
json
import
hashlib
,
os
,
re
,
json
,
hashlib
from
urlparse
import
urljoin
from
BeautifulSoup
import
BeautifulSoup
,
Comment
as
BComment
...
...
@@ -65,8 +65,12 @@ def add(request):
)
c
.
save
()
for
f
in
request
.
FILES
.
getlist
(
'attachments[]'
):
a
=
Attachment
(
comment
=
c
)
a
.
storage
.
save
(
f
.
name
,
f
)
a
=
Attachment
(
comment
=
c
,
name
=
f
.
name
)
m
=
hashlib
.
sha256
()
for
chunk
in
f
.
chunks
():
m
.
update
(
chunk
)
sname
=
m
.
hexdigest
()
a
.
storage
.
save
(
sname
,
f
)
a
.
save
()
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
else
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment