Unverified Commit 20669eea authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Greatly simplify file storage

There is no need to make it complex:
- Human-readable is unnecessary and difficult
- Django takes care of uniqueness just fine
- The filesystem does not mind lots of files in 1 dir
parent 9caeee75
# -*- coding: utf-8 -*-
# Generated by Django 1.10b1 on 2016-07-06 20:37
# Generated by Django 1.10b1 on 2016-07-14 20:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import documents.models
import utils.validators
......@@ -20,17 +19,16 @@ class Migration(migrations.Migration):
name='AssociationDocument',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('year', models.IntegerField()),
('file', models.FileField(upload_to=documents.models.associationdocs_path, validators=[utils.validators.validate_file_extension])),
('filetype', models.CharField(choices=[('policy_document', 'Policy document'), ('annual_report', 'Annual report'), ('financial_report', 'Financial report')], max_length=16)),
('file', models.FileField(upload_to='documents/association/', validators=[utils.validators.validate_file_extension])),
('filetype', models.CharField(choices=[('policy-document', 'Policy document'), ('annual-report', 'Annual report'), ('financial-report', 'Financial report')], max_length=16)),
],
),
migrations.CreateModel(
name='GeneralMeeting',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('minutes', models.FileField(upload_to=documents.models.minutes_path, validators=[utils.validators.validate_file_extension])),
('minutes', models.FileField(upload_to='documents/meetings/minutes/', validators=[utils.validators.validate_file_extension])),
('datetime', models.DateTimeField()),
('location', models.CharField(max_length=200)),
],
......@@ -39,7 +37,7 @@ class Migration(migrations.Migration):
name='GeneralMeetingDocument',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to=documents.models.general_meetingdocs_path, validators=[utils.validators.validate_file_extension])),
('file', models.FileField(upload_to='documents/meetings/files/', validators=[utils.validators.validate_file_extension])),
('meeting', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='documents.GeneralMeeting')),
],
),
......@@ -48,7 +46,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('file', models.FileField(upload_to='documents/general/', validators=[utils.validators.validate_file_extension])),
('file', models.FileField(upload_to='documents/generic/', validators=[utils.validators.validate_file_extension])),
('members_only', models.BooleanField(default=False)),
],
),
......
from django.db import models
from django.utils.translation import ugettext_lazy as _
import os
from utils.validators import validate_file_extension
def associationdocs_path(instance, filename):
filename = instance.filetype + instance.year
return 'documents/associationdocs/{0}'.format(filename)
def minutes_path(instance, filename):
_, ext = os.path.splitext(filename)
return 'documents/{}/minutes{}'.format(instance.datetime.date(), ext)
def general_meetingdocs_path(instance, filename):
_, ext = os.path.splitext(filename)
return 'documents/{}/files/'.format(instance.datetime.date(), filename)
class AssociationDocument(models.Model):
name = models.CharField(max_length=200)
year = models.IntegerField()
file = models.FileField(
upload_to=associationdocs_path,
upload_to='documents/association/',
validators=[validate_file_extension],
)
FILETYPES = (
('policy_document', _("Policy document")),
('annual_report', _("Annual report")),
('financial_report', _("Financial report")),
('policy-document', _("Policy document")),
('annual-report', _("Annual report")),
('financial-report', _("Financial report")),
)
filetype = models.CharField(
max_length=16,
......@@ -42,7 +24,7 @@ class AssociationDocument(models.Model):
class GenericDocument(models.Model):
name = models.CharField(max_length=200)
file = models.FileField(
upload_to='documents/general/',
upload_to='documents/generic/',
validators=[validate_file_extension],
)
members_only = models.BooleanField(default=False)
......@@ -53,7 +35,7 @@ class GenericDocument(models.Model):
class GeneralMeeting(models.Model):
minutes = models.FileField(
upload_to=minutes_path,
upload_to='documents/meetings/minutes/',
validators=[validate_file_extension],
)
datetime = models.DateTimeField()
......@@ -63,7 +45,7 @@ class GeneralMeeting(models.Model):
class GeneralMeetingDocument(models.Model):
meeting = models.ForeignKey(GeneralMeeting, on_delete=models.CASCADE)
file = models.FileField(
upload_to=general_meetingdocs_path,
upload_to='documents/meetings/files/',
validators=[validate_file_extension],
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment