@ -9,7 +9,7 @@ from crispy_forms.bootstrap import Tab, TabHolder, PrependedText, FormActions
|
||||
from dal import autocomplete
|
||||
from leaflet.forms.widgets import LeafletWidget
|
||||
|
||||
from apps.files.models import File
|
||||
from apps.files.models import File, ImageFile
|
||||
|
||||
from .models import CaseStudy, SpatialRefSys
|
||||
from .widgets import CommaSeparatedTextInput
|
||||
@ -71,9 +71,6 @@ class ShortCaseStudyForm(BaseCaseStudyForm):
|
||||
'project_status',
|
||||
'synopsis',
|
||||
'full_description',
|
||||
'image',
|
||||
'image_caption',
|
||||
'image_credit',
|
||||
'video',
|
||||
'media_coverage_mainstream',
|
||||
'media_coverage_independent',
|
||||
@ -88,6 +85,19 @@ class BootstrapClearableFileInput(forms.ClearableFileInput):
|
||||
class LongCaseStudyForm(BaseCaseStudyForm):
|
||||
"""Long version of the CaseStudy form."""
|
||||
|
||||
images = forms.FileField(
|
||||
widget=BootstrapClearableFileInput(attrs={
|
||||
'url': reverse_lazy('files:upload'),
|
||||
'field': 'images_files',
|
||||
}), required=False
|
||||
)
|
||||
|
||||
images_files = forms.ModelMultipleChoiceField(
|
||||
queryset=ImageFile.objects.all(),
|
||||
widget=CommaSeparatedTextInput(),
|
||||
required=True
|
||||
)
|
||||
|
||||
official_project_documents = forms.FileField(
|
||||
widget=BootstrapClearableFileInput(attrs={
|
||||
'url': reverse_lazy('files:upload'),
|
||||
@ -201,9 +211,8 @@ class LongCaseStudyForm(BaseCaseStudyForm):
|
||||
'project_status',
|
||||
'synopsis',
|
||||
'full_description',
|
||||
'image',
|
||||
'image_caption',
|
||||
'image_credit',
|
||||
'images',
|
||||
'images_files',
|
||||
'video',
|
||||
'video_caption',
|
||||
'video_credit',
|
||||
|
21
apps/map/migrations/0065_casestudy_images.py
Normal file
21
apps/map/migrations/0065_casestudy_images.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2018-05-26 15:47
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('files', '0003_auto_20180526_1547'),
|
||||
('map', '0064_auto_20180526_1536'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='casestudy',
|
||||
name='images',
|
||||
field=models.ManyToManyField(blank=True, related_name='image_for', to='files.ImageFile', verbose_name='Images'),
|
||||
),
|
||||
]
|
36
apps/map/migrations/0066_copy_images_to_imagefiles.py
Normal file
36
apps/map/migrations/0066_copy_images_to_imagefiles.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2018-05-26 15:48
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def copy_images(apps, schema_editor):
|
||||
CaseStudy = apps.get_model('map', 'CaseStudy')
|
||||
ImageFile = apps.get_model('files', 'ImageFile')
|
||||
User = apps.get_model('auth', 'User')
|
||||
|
||||
for case_study in CaseStudy.objects.all():
|
||||
author = case_study.author
|
||||
if author is None:
|
||||
author = User.objects.get(username='root')
|
||||
|
||||
imagefile = ImageFile(
|
||||
file=case_study.image,
|
||||
caption=case_study.image_caption,
|
||||
credit=case_study.image_credit,
|
||||
user=author
|
||||
)
|
||||
imagefile.save()
|
||||
case_study.images.add(imagefile)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('map', '0065_casestudy_images'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(copy_images, migrations.RunPython.noop),
|
||||
]
|
27
apps/map/migrations/0067_remove_old_images.py
Normal file
27
apps/map/migrations/0067_remove_old_images.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2018-05-29 05:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('map', '0066_copy_images_to_imagefiles'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image_caption',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image_credit',
|
||||
),
|
||||
]
|
@ -442,25 +442,12 @@ class CaseStudy(models.Model):
|
||||
blank=True
|
||||
)
|
||||
|
||||
# 1.15.1
|
||||
image = models.ImageField(
|
||||
verbose_name=_("Image")
|
||||
)
|
||||
|
||||
# 1.15.2
|
||||
image_caption = models.CharField(
|
||||
verbose_name=_("Image caption"),
|
||||
max_length=240,
|
||||
default=None,
|
||||
null=True,
|
||||
)
|
||||
|
||||
# 1.15.3
|
||||
image_credit = models.CharField(
|
||||
verbose_name=_("Image credit(s)"),
|
||||
max_length=240,
|
||||
default=None,
|
||||
null=True,
|
||||
# 1.15.1, 1.15.2, 1.15.3
|
||||
images = models.ManyToManyField(
|
||||
'files.ImageFile',
|
||||
related_name='image_for',
|
||||
verbose_name=_("Images"),
|
||||
blank=True
|
||||
)
|
||||
|
||||
# 1.16.1
|
||||
|
@ -63,6 +63,7 @@ class BaseForm(LoginRequiredMixin, CreateView):
|
||||
form.cleaned_data.pop('official_project_documents', None)
|
||||
form.cleaned_data.pop('other_documents', None)
|
||||
form.cleaned_data.pop('shapefiles', None)
|
||||
form.cleaned_data.pop('images', None)
|
||||
|
||||
self.object = form.save()
|
||||
|
||||
|
Reference in New Issue
Block a user