Closed msettles closed 8 years ago
Added a field to Share for when it was last updated. The timestamp is updated whenever: -A new file is uploaded -A folder is created -A file/folder is renamed -A file/folder is deleted
The list of shares is now sorted by last modified, then created. The update will now set last modified times for existing shares. They will be updated as soon as one of the above actions is performed. In order to have a timestamp for existing shares, a script would need to crawl every share and find the latest modified date.
Here is some code that can be run from the django shell to update the timestamp:
from datetime import datetime
import os
from bioshareX.models import Share
for share in Share.objects.all():
path = share.get_path()
files = []
for root, dirnames, filenames in os.walk(path):
files += [os.path.join(root, file) for file in filenames]
files += [os.path.join(root, dir) for dir in dirnames]
try:
newest = max(files, key=os.path.getmtime)
share.updated = datetime.fromtimestamp(os.path.getmtime(newest))
share.save()
except:
continue
Sort order should be on last modified, rather than created, old(er) (but active) shares would float to the top