Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fdw-forks
django-database-files
Commits
40195f0b
Commit
40195f0b
authored
Nov 14, 2012
by
chris
Browse files
Modified file dump command to update hash upon write and allow targeting
of specific files.
parent
739ed082
Changes
3
Show whitespace changes
Inline
Side-by-side
database_files/__init__.py
View file @
40195f0b
VERSION
=
(
0
,
1
,
1
0
)
VERSION
=
(
0
,
1
,
1
1
)
__version__
=
'.'
.
join
(
map
(
str
,
VERSION
))
\ No newline at end of file
database_files/management/commands/database_files_rehash.py
View file @
40195f0b
...
...
@@ -6,8 +6,9 @@ from django.core.management.base import BaseCommand, CommandError
from
database_files.models
import
File
class
Command
(
BaseCommand
):
args
=
''
help
=
'Regenerates hashes for all files.'
args
=
'<filename 1> <filename 2> ... <filename N>'
help
=
'Regenerates hashes for files. If no filenames given, '
+
\
'rehashes everything.'
option_list
=
BaseCommand
.
option_list
+
(
# make_option('--dryrun',
# action='store_true',
...
...
@@ -22,9 +23,11 @@ class Command(BaseCommand):
settings
.
DEBUG
=
False
try
:
q
=
File
.
objects
.
all
()
if
args
:
q
=
q
.
filter
(
name__in
=
args
)
total
=
q
.
count
()
i
=
1
for
f
in
q
:
for
f
in
q
.
iterator
()
:
print
'%i of %i: %s'
%
(
i
,
total
,
f
.
name
)
f
.
_content_hash
=
None
f
.
save
()
...
...
database_files/models.py
View file @
40195f0b
...
...
@@ -75,7 +75,7 @@ class File(models.Model):
if
verbose
:
print
'Checking %i total files...'
%
(
total
,)
i
=
0
for
(
file_id
,
name
,
content_hash
)
in
q
:
for
(
file_id
,
name
,
content_hash
)
in
q
.
iterator
()
:
i
+=
1
if
verbose
and
not
i
%
100
:
print
'%i of %i'
%
(
i
,
total
)
...
...
@@ -88,6 +88,8 @@ class File(models.Model):
file
.
name
,
file
.
content
,
overwrite
=
True
)
file
.
_content_hash
=
None
file
.
save
()
finally
:
if
debug
:
settings
.
DEBUG
=
tmp_debug
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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