Skip to content

Commit

Permalink
TemplateContent
Browse files Browse the repository at this point in the history
  • Loading branch information
biodiv committed Dec 14, 2022
1 parent f817ec0 commit eb1b281
Show file tree
Hide file tree
Showing 201 changed files with 2,686 additions and 7,829 deletions.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
recursive-include localcosmos_server/app_admin/static *
recursive-include localcosmos_server/app_admin/templates *
recursive-include localcosmos_server/datasets/templates *
recursive-include localcosmos_server/online_content/static *
recursive-include localcosmos_server/online_content/templates *
recursive-include localcosmos_server/template__content/static *
recursive-include localcosmos_server/template_content/templates *
recursive-include localcosmos_server/server_control_panel/templates *
recursive-include localcosmos_server/specifications *
recursive-include localcosmos_server/static *
Expand Down
2 changes: 1 addition & 1 deletion docker/localcosmos_private/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'localcosmos_server.app_admin',
'localcosmos_server.server_control_panel',
'localcosmos_server.datasets',
'localcosmos_server.online_content',
'localcosmos_server.template_content',

'django_road',
'anycluster',
Expand Down
2 changes: 1 addition & 1 deletion localcosmos_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'localcosmos_server'
__version__ = '0.10.0'
__version__ = '0.12.0'
2 changes: 1 addition & 1 deletion localcosmos_server/app_admin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
request.is_appadmin = False

# the admin has to use localcosmos_server.urls to not conflict with the commercial installation
# online_content needs the correct urlconf
# template_content needs the correct urlconf
if '/app-admin/' in request.path:

request.is_appadmin = True
Expand Down
2 changes: 1 addition & 1 deletion localcosmos_server/app_admin/templates/app_admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link" href="{% url 'manage_onlinecontent' request.app.uid %}">{% trans 'Online content' %}</a>
<a class="nav-link" href="{% url 'template_content_home' request.app.uid %}">{% trans 'Template content' %}</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{% trans 'Observations' %}</a>
Expand Down
46 changes: 0 additions & 46 deletions localcosmos_server/datasets/migrations/0002_auto_20221111_1535.py

This file was deleted.

10 changes: 6 additions & 4 deletions localcosmos_server/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def import_module(module):
'''
ObservationForm
'''
'''
class ObservationForm(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
Expand All @@ -69,15 +70,16 @@ class ObservationForm(models.Model):
class Meta:
unique_together=('uuid', 'version')

'''
'''
MetaData
'''
'''
class MetaData(models.Model):
observation_form = models.ForeignKey(ObservationForm, on_delete=models.PROTECT)
data = models.JSONField()

'''

'''
Dataset
Expand All @@ -93,9 +95,9 @@ class Dataset(ModelWithTaxon):
# all data except the taxononmic inherited from ModelWithTaxon is stored in the json data column without schema
# for quicker queries, some fields have their own (redundant) db columns below
data = models.JSONField()
observation_form = models.ForeignKey(ObservationForm, on_delete=models.PROTECT)
#observation_form = models.ForeignKey(ObservationForm, on_delete=models.PROTECT)

meta_data = models.ForeignKey(MetaData, null=True, on_delete=models.PROTECT)
#meta_data = models.ForeignKey(MetaData, null=True, on_delete=models.PROTECT)

### redundant fields for quick DB queries
# geographic reference, useful for anycluster and quick GIS queries
Expand Down
87 changes: 86 additions & 1 deletion localcosmos_server/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def clean(self):

'''
ManageContentImageForm
- used by online_content and app_kit
- used by template_content and app_kit
- expects LicencingFormMixin in Form
- add an image to any content of the app, or an app directly
- images have a type, default is 'image', possible types are eg 'background' or 'logo'
Expand Down Expand Up @@ -262,3 +262,88 @@ def clean(self):

return cleaned_data


from content_licencing.mixins import LicencingFormMixin, OptionalLicencingFormMixin
from localcosmos_server.widgets import HiddenJSONInput
class ManageContentImageForm(ManageContentImageFormCommon, LicencingFormMixin):

# cropping
crop_parameters = forms.CharField(widget=forms.HiddenInput)

# features like arrows
features = forms.CharField(widget=HiddenJSONInput, required=False)

# image_type
image_type = forms.CharField(widget=forms.HiddenInput, required=False)

# md5
md5 = forms.CharField(widget=forms.HiddenInput, required=False)

requires_translation = forms.BooleanField(required=False)


def clean_source_image(self):

source_image = self.cleaned_data.get('source_image')
if not source_image and not self.current_image:
raise forms.ValidationError('An image file is required.')

return source_image


class ManageContentImageWithTextForm(FormLocalizationMixin, ManageContentImageForm):

input_language = forms.CharField(widget=forms.HiddenInput)

text = forms.CharField(max_length=355, required=False, widget=forms.Textarea,
help_text=_('Text that will be shown together with this image.'))

localizeable_fields = ['text']
layoutable_simple_fields = ['text']


class ManageLocalizedContentImageForm(ManageContentImageForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
del self.fields['requires_translation']


'''
A form with an optional ContentImage. If the user uploads an image, creator_name and licence have to be present
'''
class OptionalContentImageForm(ManageContentImageFormCommon, OptionalLicencingFormMixin):

# cropping
crop_parameters = forms.CharField(widget=forms.HiddenInput, required=False)

# features like arrows
features = forms.CharField(widget=HiddenJSONInput, required=False)

# image_type
image_type = forms.CharField(widget=forms.HiddenInput, required=False)

# md5
md5 = forms.CharField(widget=forms.HiddenInput, required=False)

# if suggested images are provided, the user may click on the suggested image
referred_content_image_id = forms.IntegerField(widget=forms.HiddenInput, required=False)

def fields_required(self, fields):
"""Used for conditionally marking fields as required."""
for field in fields:
if not self.cleaned_data.get(field, None):
msg = forms.ValidationError(_('This field is required.'))
self.add_error(field, msg)


# if an image is present, at least crop_parameters, licence and creator_name have to be present
def clean(self):
cleaned_data = super().clean()
file_ = cleaned_data.get('source_image', None)

if file_ is not None:
self.fields_required(['creator_name', 'licence'])


return cleaned_data
10 changes: 9 additions & 1 deletion localcosmos_server/global_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
extra_context={'base_template': 'base.html'},
template_name='localcosmos_server/registration/password_reset_complete.html'),
name='password_reset_complete'),

# server content images
path('manage-server-content-image/<int:content_type_id>/<int:object_id>/',
views.ManageServerContentImage.as_view(), name='manage_server_content_image'),
path('manage-server-content-image/<int:content_type_id>/<int:object_id>/<str:image_type>/',
views.ManageServerContentImage.as_view(), name='manage_server_content_image'),
path('manage-server-content-image/<int:content_image_id>/',
views.ManageServerContentImage.as_view(), name='manage_server_content_image'),
path('delete-server-content-image/<int:pk>/',
views.DeleteServerContentImage.as_view(), name='delete_server_content_image'),
# SETUP GUI
path('', include('localcosmos_server.setup_urls')),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 3.1.14 on 2022-12-12 14:39

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import localcosmos_server.models


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('localcosmos_server', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='ServerImageStore',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('taxon_latname', models.CharField(max_length=255, null=True)),
('taxon_author', models.CharField(max_length=255, null=True)),
('taxon_source', models.CharField(max_length=255, null=True)),
('taxon_include_descendants', models.BooleanField(default=False)),
('taxon_nuid', models.CharField(max_length=255, null=True)),
('name_uuid', models.UUIDField(null=True)),
('md5', models.CharField(max_length=255)),
('source_image', models.ImageField(upload_to=localcosmos_server.models.get_image_store_path)),
('uploaded_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ServerContentImage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('crop_parameters', models.TextField(null=True)),
('features', models.JSONField(null=True)),
('object_id', models.IntegerField()),
('image_type', models.CharField(default='image', max_length=100)),
('position', models.IntegerField(default=0)),
('is_primary', models.BooleanField(default=False)),
('text', models.CharField(max_length=355, null=True)),
('requires_translation', models.BooleanField(default=False)),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('image_store', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='localcosmos_server.serverimagestore')),
],
options={
'abstract': False,
},
),
]

0 comments on commit eb1b281

Please sign in to comment.