Skip to content

Commit

Permalink
Company picture
Browse files Browse the repository at this point in the history
  • Loading branch information
berk76 committed Mar 12, 2024
1 parent 1a97f05 commit 8056095
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 101 deletions.
3 changes: 2 additions & 1 deletion svjis/articles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Meta:
class CompanyForm(forms.ModelForm):
class Meta:
model = models.Company
fields = ("name", "address", "city", "post_code", "phone", "email", "registration_no", "vat_registration_no", "internet_domain")
fields = ("name", "address", "city", "post_code", "phone", "email", "registration_no", "vat_registration_no", "internet_domain", "header_picture")
widgets = {
'name': forms.widgets.TextInput(attrs={'class': 'common-input', 'size': '50'}),
'address': forms.widgets.TextInput(attrs={'class': 'common-input', 'size': '50'}),
Expand All @@ -137,6 +137,7 @@ class Meta:
'registration_no': forms.widgets.TextInput(attrs={'class': 'common-input', 'size': '50'}),
'vat_registration_no': forms.widgets.TextInput(attrs={'class': 'common-input', 'size': '50'}),
'internet_domain': forms.widgets.TextInput(attrs={'class': 'common-input', 'size': '50'}),
'header_picture': forms.widgets.FileInput(attrs={'class': 'common-input', 'size': '50'}),
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.0.2 on 2024-03-12 13:48
# Generated by Django 5.0.2 on 2024-03-12 21:23

import articles.models
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
Expand All @@ -19,8 +20,6 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order', models.SmallIntegerField(verbose_name='Order')),
('position', models.CharField(max_length=30, verbose_name='Position')),
('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.company', verbose_name='Company')),
('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['order'],
Expand Down Expand Up @@ -84,6 +83,21 @@ class Migration(migrations.Migration):
name='userprofile',
options={'permissions': (('svjis_view_admin_menu', 'Can view Administration menu'), ('svjis_edit_admin_users', 'Can edit Users'), ('svjis_edit_admin_groups', 'Can edit Groups'), ('svjis_view_personal_menu', 'Can view Personal settings menu'), ('svjis_view_phonelist', 'Can view Phonelist'))},
),
migrations.AddField(
model_name='company',
name='header_picture',
field=models.FileField(blank=True, null=True, upload_to=articles.models.company_directory_path, verbose_name='Header picture (940 x 94)'),
),
migrations.AddField(
model_name='board',
name='company',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.company', verbose_name='Company'),
),
migrations.AddField(
model_name='board',
name='member',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='buildingunit',
name='type',
Expand Down
5 changes: 5 additions & 0 deletions svjis/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class Meta:
)


def company_directory_path(instance, filename):
return 'company/{0}'.format(filename)


class Company(models.Model):
name = models.CharField(_("Name"), max_length=50, blank=True)
address = models.CharField(_("Address"), max_length=50, blank=True)
Expand All @@ -168,6 +172,7 @@ class Company(models.Model):
registration_no = models.CharField(_("Registration no."), max_length=20, blank=True)
vat_registration_no = models.CharField(_("VAT Registration no."), max_length=20, blank=True)
internet_domain = models.CharField(_("Internet domain"), max_length=50, blank=True)
header_picture = models.FileField(_("Header picture (940 x 94)"), upload_to=company_directory_path, null=True, blank=True)

@property
def board(self):
Expand Down
6 changes: 5 additions & 1 deletion svjis/articles/templates/admin_company_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block content %}

<h1 class="page-title">{% trans 'Company' %}</h1>
<form action="{% url 'admin_company_save' %}" method="post">
<form action="{% url 'admin_company_save' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<fieldset>
<legend>{% trans 'Company' %}</legend>
Expand Down Expand Up @@ -45,6 +45,10 @@ <h1 class="page-title">{% trans 'Company' %}</h1>
<label class="common-label" for="{{ form.internet_domain.auto_id }}">{{ form.internet_domain.label }}</label>
{{ form.internet_domain }}
</p>
<p>
<label class="common-label" for="{{ form.header_picture.auto_id }}">{{ form.header_picture.label }}</label>
{{ form.header_picture }}
</p>
</fieldset>
<p>
<input class="my-button" id="submit" type="submit" value="{% trans 'Save' %}" />
Expand Down
2 changes: 1 addition & 1 deletion svjis/articles/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link rel="stylesheet" media="screen,projection" type="text/css" href="/static/css/style.css" />
<link rel="stylesheet" media="print" type="text/css" href="/static/css/print.css" />

<title>{% settings_value "SVJIS_TITLE" %}</title>
<title>{{ web_title|default:"SVJIS-PY" }}</title>
</head>

<body>
Expand Down
6 changes: 4 additions & 2 deletions svjis/articles/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<!-- Header -->
<div id="header">

<!-- <div id="logo"><a href="/" title="[Přejít na domovskou stránku]"><span style="background:url('static/gfx/Header_1.jpg') 0 0 no-repeat;"></span></a></div> -->
{% if company_picture %}
<div id="logo"><a href="/" title="[Přejít na domovskou stránku]"><span style="background:url('/media/{{ company_picture }}') 0 0 no-repeat;"></span></a></div>
{% endif %}

<div id="company_name">{% settings_value "SVJIS_TITLE" %}</div>
<div id="company_name">{{ company_name|default:"SVJIS-PY" }}</div>
<hr class="noscreen" />

</div> <!-- /header -->
10 changes: 10 additions & 0 deletions svjis/articles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
logger = logging.getLogger(__name__)


def get_context():
ctx = {}
company, created = models.Company.objects.get_or_create(pk=1)
if company is not None:
ctx['company_picture'] = company.header_picture
ctx['company_name'] = company.name
ctx['web_title'] = company.name
return ctx


def get_tray_menu(active_item: str, user) -> list:
result = []
result.append({'description': _("Articles"), 'link': reverse(views.main_view), 'active': True if active_item == 'articles' else False})
Expand Down
11 changes: 5 additions & 6 deletions svjis/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ def main_filtered_view(request, menu):
for ta in top_articles:
ta['article'] = get_object_or_404(models.Article, pk=ta['article_id'])

ctx = {
'aside_menu_name': _("Articles"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Articles")
ctx['is_paginated'] = is_paginated
ctx['page_obj'] = page_obj
ctx['page_parameter'] = page_parameter
Expand All @@ -93,12 +92,12 @@ def article_view(request, pk):
if user.is_anonymous:
user = None
models.ArticleLog.objects.create(article=article, user=user)
ctx = {
'aside_menu_name': _("Articles"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Articles")
ctx['search'] = request.GET.get('search', '')
ctx['header'] = article.menu.description
ctx['obj'] = article
ctx['web_title'] = article.header
ctx['aside_menu_items'] = get_side_menu(ctx)
ctx['tray_menu_items'] = utils.get_tray_menu('articles', request.user)
return render(request, "article.html", ctx)
Expand Down
87 changes: 35 additions & 52 deletions svjis/articles/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def get_side_menu(active_item, user):
def admin_company_edit_view(request):
instance, created = models.Company.objects.get_or_create(pk=1)
form = forms.CompanyForm(instance=instance)
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['aside_menu_items'] = get_side_menu('company', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
Expand All @@ -78,7 +77,7 @@ def admin_company_edit_view(request):
@require_POST
def admin_company_save_view(request):
instance, created = models.Company.objects.get_or_create(pk=1)
form = forms.CompanyForm(request.POST, instance=instance)
form = forms.CompanyForm(request.POST, request.FILES, instance=instance)
if form.is_valid:
form.save()
else:
Expand All @@ -93,9 +92,8 @@ def admin_company_save_view(request):
@require_GET
def admin_board_view(request):
board_list = models.Board.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('board', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = board_list
Expand All @@ -111,9 +109,8 @@ def admin_board_edit_view(request, pk):
else:
form = forms.BoardForm

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['pk'] = pk
ctx['aside_menu_items'] = get_side_menu('board', request.user)
Expand Down Expand Up @@ -154,9 +151,8 @@ def admin_board_delete_view(request, pk):
def admin_building_edit_view(request):
instance, created = models.Building.objects.get_or_create(pk=1)
form = forms.BuildingForm(instance=instance)
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['aside_menu_items'] = get_side_menu('building', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
Expand All @@ -181,9 +177,8 @@ def admin_building_save_view(request):
@require_GET
def admin_entrance_view(request):
entrance_list = models.BuildingEntrance.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('entrances', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = entrance_list
Expand All @@ -199,9 +194,8 @@ def admin_entrance_edit_view(request, pk):
else:
form = forms.BuildingEntranceForm

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['pk'] = pk
ctx['aside_menu_items'] = get_side_menu('entrances', request.user)
Expand Down Expand Up @@ -242,9 +236,8 @@ def admin_entrance_delete_view(request, pk):
@require_GET
def admin_building_unit_view(request):
unit_list = models.BuildingUnit.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('units', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = unit_list
Expand All @@ -260,9 +253,8 @@ def admin_building_unit_edit_view(request, pk):
else:
form = forms.BuildingUnitForm

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['pk'] = pk
ctx['aside_menu_items'] = get_side_menu('units', request.user)
Expand Down Expand Up @@ -304,9 +296,8 @@ def admin_building_unit_owners_view(request, pk):
bu = get_object_or_404(models.BuildingUnit, pk=pk)
user_list = [ u for u in User.objects.filter(is_active=True).order_by('last_name') if u not in bu.owners.all()]

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['bu'] = bu
ctx['pk'] = pk
ctx['user_list'] = user_list
Expand Down Expand Up @@ -343,9 +334,8 @@ def admin_building_unit_owners_delete_view(request, pk, owner):
@require_GET
def admin_user_view(request):
user_list = User.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('users', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = user_list
Expand Down Expand Up @@ -373,9 +363,8 @@ def admin_user_edit_view(request, pk):
item = {'name': g.name, 'checked': g in user_group_list}
group_list.append(item)

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['uform'] = uform
ctx['pform'] = pform
ctx['group_list'] = group_list
Expand Down Expand Up @@ -435,9 +424,8 @@ def admin_user_save_view(request):
def admin_user_owns_view(request, pk):
u = get_object_or_404(User, pk=pk)
bu_list = [ bu for bu in models.BuildingUnit.objects.all().order_by('description') if bu not in u.buildingunit_set.all()]
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['u'] = u
ctx['pk'] = pk
ctx['bu_list'] = bu_list
Expand Down Expand Up @@ -474,9 +462,8 @@ def admin_user_owns_delete_view(request, pk, owner):
@require_GET
def admin_group_view(request):
group_list = Group.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('groups', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = group_list
Expand All @@ -502,9 +489,8 @@ def admin_group_edit_view(request, pk):
item = {'name': p.codename, 'checked': p in group_perm_list}
permission_list.append(item)

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['instance'] = i
ctx['permission_list'] = permission_list
Expand Down Expand Up @@ -555,9 +541,8 @@ def admin_group_delete_view(request, pk):
@require_GET
def admin_preferences_view(request):
property_list = models.Preferences.objects.all()
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('preferences', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = property_list
Expand All @@ -573,9 +558,8 @@ def admin_preferences_edit_view(request, pk):
else:
form = forms.PreferencesForm

ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['form'] = form
ctx['pk'] = pk
ctx['aside_menu_items'] = get_side_menu('preferences', request.user)
Expand Down Expand Up @@ -613,9 +597,8 @@ def admin_preferences_delete_view(request, pk):
@require_GET
def admin_messages_view(request):
message_list = models.MessageQueue.objects.filter(status=0)
ctx = {
'aside_menu_name': _("Administration"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Administration")
ctx['aside_menu_items'] = get_side_menu('messages', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('admin', request.user)
ctx['object_list'] = message_list
Expand Down
10 changes: 4 additions & 6 deletions svjis/articles/views_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def get_side_menu(active_item, user):
@require_GET
def contact_view(request):
instance, created = models.Company.objects.get_or_create(pk=1)
ctx = {
'aside_menu_name': _("Contact"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Contact")
ctx['company'] = instance
ctx['aside_menu_items'] = get_side_menu('company', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('contact', request.user)
Expand All @@ -36,9 +35,8 @@ def contact_view(request):
@require_GET
def phonelist_view(request):
phone_list = User.objects.filter(is_active=True, userprofile__show_in_phonelist=True).order_by('last_name')
ctx = {
'aside_menu_name': _("Contact"),
}
ctx = utils.get_context()
ctx['aside_menu_name'] = _("Contact")
ctx['object_list'] = phone_list
ctx['aside_menu_items'] = get_side_menu('phonelist', request.user)
ctx['tray_menu_items'] = utils.get_tray_menu('contact', request.user)
Expand Down
Loading

0 comments on commit 8056095

Please sign in to comment.