Browse Source

add file icons

master
TheOrangeOne 5 years ago
parent
commit
2a9abc8a54
Signed by: theorangeone GPG Key ID: 57AFB45680EDD477
  1. 6
      build
  2. 2
      package.json
  3. 8
      project/files/models.py

6
build

@ -26,4 +26,10 @@ env/bin/pip install -r requirements.txt
npm install
npm run build
echo "Getting icons..."
git clone git@github.com:teambox/Free-file-icons static/build/img/temp || echo "already exists"
cp static/build/img/temp/512px/* static/build/img/icons/
rm -rf static/build/img/temp
env/bin/python manage.py collectstatic --noinput

2
package.json

@ -6,7 +6,7 @@
"scripts": {
"test": "npm run lint",
"lint": "eslint 'static/src/js/'",
"create-build-dirs": "mkdir -p static/build/js static/build/css static/build/fonts static/build/img",
"create-build-dirs": "mkdir -p static/build/js static/build/css static/build/fonts static/build/img/icons",
"build-scss": "bash scripts/build-scss.sh",
"build-js": "bash scripts/build-js.sh",
"build-fonts": "cp -R node_modules/bootstrap-sass/assets/fonts/bootstrap/* static/build/fonts/ && cp -R node_modules/font-awesome/fonts static/build",

8
project/files/models.py

@ -4,6 +4,8 @@ from admin_resumable.fields import ModelAdminResumableFileField
from shortuuidfield import ShortUUIDField
from datetime import timedelta
from django.core.urlresolvers import reverse
import os.path
from django.conf import settings
class SharedFile(models.Model):
@ -23,6 +25,12 @@ class SharedFile(models.Model):
def get_absolute_url(self):
return reverse('files:file', args=(self.short_id,))
def get_type_image(self):
extension = self.get_original_filename().split('.')[-1]
icon_file = os.path.join(settings.STATICFILES_DIRS[0], 'img', 'icons', "{0}.png".format(extension))
filename = extension if os.path.exists(icon_file) else "_page"
return os.path.join(settings.STATIC_URL, 'img', 'icons', "{0}.png".format(filename))
class FileToken(models.Model):
valid_time = timedelta(minutes=5)

Loading…
Cancel
Save