Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a default fallback image as Group header logo image on save (ref: CLIENT_G3WSUITE_LOGO) #509

Merged
merged 6 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions g3w-admin/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@


from django.apps import AppConfig
from django.conf import settings
import os
import shutil

class CoreConfig(AppConfig):
name = 'core'
verbose_name = 'G3W-Admin main app'

# For default Group logo image
# -----------------------------------------------------------------
f = settings.CLIENT_G3WSUITE_LOGO
frm = f"{os.path.dirname(__file__)}/static/img/{f}"
dst = f"{settings.MEDIA_ROOT}logo_img/"

if not os.path.exists(f"{dst}{f}"):
# Before check if directory `logo_img` exists
if not os.path.exists(dst):
os.mkdir(dst)
shutil.copy(frm, dst)
4 changes: 2 additions & 2 deletions g3w-admin/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class GroupForm(TranslationModelForm, FileFormMixin, G3WFormMixin, G3WRequestFormMixin, G3WACLForm, ModelForm):
"""Group form."""
header_logo_img = UploadedFileField()
header_logo_img = UploadedFileField(required=True)
propagate = True

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(self, *args, **kwargs):
Div(
Div(
'header_logo_img',
HTML("""<img {% if not form.header_logo_img.value %}style="display:none;"{% endif %} class="img-responsive img-thumbnail" src="{{ MEDIA_URL }}{{ form.header_logo_img.value }}">""", ),
HTML("""{% load staticfiles %}<img class="img-responsive img-thumbnail" src={% if not form.header_logo_img.value %}"{% static 'img/'|add:SETTINGS.CLIENT_G3WSUITE_LOGO %}"{% else %}"{{ MEDIA_URL }}{{ form.header_logo_img.value }}"{% endif %}>"""),
'use_logo_client',
'form_id',
'upload_url',
Expand Down
20 changes: 20 additions & 0 deletions g3w-admin/core/migrations/0081_auto_20230329_0739.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.28 on 2023-03-29 07:39

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



class Migration(migrations.Migration):

dependencies = [
('core', '0080_statuslog'),
]

operations = [
migrations.AlterField(
model_name='group',
name='header_logo_img',
field=models.FileField(default=f'logo_img/{settings.CLIENT_G3WSUITE_LOGO}', upload_to='logo_img', verbose_name='Logo image'),
),
]
3 changes: 2 additions & 1 deletion g3w-admin/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class Group(TimeStampedModel, OrderedModel):
is_active = models.BooleanField(_('Is active'), default=1)

# Company logo
header_logo_img = models.FileField(_('Logo image'), upload_to='logo_img')
header_logo_img = models.FileField(_('Logo image'), upload_to='logo_img',
default=f'logo_img/{settings.CLIENT_G3WSUITE_LOGO}')
header_logo_link = models.URLField(_('Logo link'), blank=True, null=True,
help_text=_('Enter link with http:// or https//'))

Expand Down
2 changes: 1 addition & 1 deletion g3w-admin/core/templates/core/group_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h1>{% trans 'Cartographic groups' %}</h1>
<div class="col-md-3 col-sm-6" id="group_{{ object.pk }}">
<div class="box box-widget widget-user" id="group_{{ object.slug }}">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-aqua-active col-sm-12" style="background: url('{{ MEDIA_URL }}{{ object.header_logo_img }}') center center;">
<div class="widget-user-header bg-aqua-active col-sm-12" style="background: url('{{ MEDIA_URL }}{{ object.header_logo_img }}') no-repeat center center;">
<div class="row">
<div class="col-sm-12 widget-group-title handle">
<h3 class="widget-user-username">{{ object.name }}</h3>
Expand Down
9 changes: 8 additions & 1 deletion g3w-admin/core/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.template.response import HttpResponse
from django.http import JsonResponse, HttpResponseBadRequest, HttpResponse, HttpResponseServerError
from django.views.generic import (
Expand Down Expand Up @@ -145,7 +146,13 @@ def dispatch(self, *args, **kwargs):
return super(GroupCreateView, self).dispatch(*args, **kwargs)

def get_initial(self):
return {'mapcontrols': MapControl.objects.all()}

# Fake group for build a initial default header_logo_img for new groups.
g = Group(name='fake', title='fake', srid_id=1, header_logo_img=f'logo_img/{settings.CLIENT_G3WSUITE_LOGO}')

return {'mapcontrols': MapControl.objects.all(),
'header_logo_img': g.header_logo_img
}

def get_success_url(self):
return reverse('group-list')
Expand Down