don't store source images in database
This commit is contained in:
parent
9e4257e36e
commit
8662d5a062
3 changed files with 33 additions and 1 deletions
30
src/c3nav/mapdata/migrations/0016_remove_source_image.py
Normal file
30
src/c3nav/mapdata/migrations/0016_remove_source_image.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-08 12:52
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def move_sources(apps, schema_editor):
|
||||||
|
Source = apps.get_model('mapdata', 'Source')
|
||||||
|
for source in Source.objects.all():
|
||||||
|
with open(os.path.join(settings.SOURCES_ROOT, source.name), 'wb') as f:
|
||||||
|
f.write(source.image)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0015_auto_20170706_1334'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(move_sources),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='source',
|
||||||
|
name='image',
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,7 +9,6 @@ class Source(BoundsMixin, models.Model):
|
||||||
A map source, images of levels that can be useful as backgrounds for the map editor
|
A map source, images of levels that can be useful as backgrounds for the map editor
|
||||||
"""
|
"""
|
||||||
name = models.SlugField(_('Name'), unique=True, max_length=50)
|
name = models.SlugField(_('Name'), unique=True, max_length=50)
|
||||||
image = models.BinaryField(_('image data')) # todo migrate to better storage
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Source')
|
verbose_name = _('Source')
|
||||||
|
|
|
@ -18,6 +18,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
DATA_DIR = config.get('c3nav', 'datadir', fallback=os.environ.get('DATA_DIR', 'data'))
|
DATA_DIR = config.get('c3nav', 'datadir', fallback=os.environ.get('DATA_DIR', 'data'))
|
||||||
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
||||||
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
|
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
|
||||||
|
SOURCES_ROOT = os.path.join(DATA_DIR, 'sources')
|
||||||
MAP_ROOT = os.path.join(DATA_DIR, 'map')
|
MAP_ROOT = os.path.join(DATA_DIR, 'map')
|
||||||
RENDER_ROOT = os.path.join(DATA_DIR, 'render')
|
RENDER_ROOT = os.path.join(DATA_DIR, 'render')
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@ if not os.path.exists(LOG_DIR):
|
||||||
os.mkdir(LOG_DIR)
|
os.mkdir(LOG_DIR)
|
||||||
if not os.path.exists(MEDIA_ROOT):
|
if not os.path.exists(MEDIA_ROOT):
|
||||||
os.mkdir(MEDIA_ROOT)
|
os.mkdir(MEDIA_ROOT)
|
||||||
|
if not os.path.exists(SOURCES_ROOT):
|
||||||
|
os.mkdir(SOURCES_ROOT)
|
||||||
if not os.path.exists(MAP_ROOT):
|
if not os.path.exists(MAP_ROOT):
|
||||||
os.mkdir(MAP_ROOT)
|
os.mkdir(MAP_ROOT)
|
||||||
if not os.path.exists(RENDER_ROOT):
|
if not os.path.exists(RENDER_ROOT):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue