Skip to content

Commit

Permalink
Added volunteer model, page, and view. Missing adding categories
Browse files Browse the repository at this point in the history
  • Loading branch information
aquilesC committed Sep 18, 2021
1 parent 922c27c commit e83fed2
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/settings/base.py
Expand Up @@ -102,6 +102,7 @@
"klimaat_helpdesk.users.apps.UsersConfig",
"klimaat_helpdesk.core.apps.CoreConfig",
"klimaat_helpdesk.experts.apps.ExpertsConfig",
"klimaat_helpdesk.volunteers.apps.VolunteersConfig",
"klimaat_helpdesk.cms.apps.CmsConfig",
"klimaat_helpdesk.search.apps.SearchConfig",
]
Expand Down
29 changes: 29 additions & 0 deletions klimaat_helpdesk/cms/migrations/0027_volunteerindexpage.py
@@ -0,0 +1,29 @@
# Generated by Django 3.1.13 on 2021-09-18 09:50

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0060_fix_workflow_unique_constraint'),
('cms', '0026_auto_20201108_1222'),
]

operations = [
migrations.CreateModel(
name='VolunteerIndexPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('subtitle', models.CharField(max_length=128)),
('intro', wagtail.core.fields.RichTextField(blank=True)),
('outro', wagtail.core.fields.RichTextField(blank=True)),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
27 changes: 26 additions & 1 deletion klimaat_helpdesk/cms/models.py
Expand Up @@ -21,6 +21,7 @@
from klimaat_helpdesk.cms.blocks import AnswerRichTextBlock, QuoteBlock, AnswerImageBlock, AnswerOriginBlock, \
RelatedItemsBlock
from klimaat_helpdesk.experts.models import Expert
from klimaat_helpdesk.volunteers.models import Volunteer


class ExpertAnswerRelationship(Orderable, models.Model):
Expand Down Expand Up @@ -204,7 +205,7 @@ def get_references(self):
TODO: References for articles can be separated from the origin and make them a proper ListBlock that can be
handled by editors as they see fit. Having the references within a StreamField of 'origins' seems counter
intuitive.
"""
ref_list = []
try:
Expand Down Expand Up @@ -391,6 +392,30 @@ def get_context(self, request, *args, **kwargs):
return context


class VolunteerIndexPage(Page):
""" List of volunteers on the website """
template = 'volunteers/volunteers_list.html'
subtitle = models.CharField(max_length=128, blank=False)
intro = RichTextField(blank=True)
outro = RichTextField(blank=True)

content_panels = Page.content_panels + [
FieldPanel('subtitle'),
FieldPanel('intro'),
FieldPanel('outro'),
]

def get_context(self, request, *args, **kwargs):
context = super(VolunteerIndexPage, self).get_context(request, *args, **kwargs)
volunteers = Volunteer.objects.all()

context.update({
'volunteers': volunteers,
'answers_page': AnswerIndexPage.objects.first().url,
})
return context


class GeneralPage(Page):
""" A page that won't show sidebar. Ideal for privacy policy, etc. """
template = 'cms/general_page.html'
Expand Down
@@ -0,0 +1,35 @@
{% load static wagtailimages_tags i18n %}

<div class="expert" id="{{ volunteer.pk }}">
<div class="expert__image-container">
{% image volunteer.picture fill-200x200 as image %}
<img class="expert__image" src="{{ image.url }}" alt="{{ image.alt }}">
</div>

<div class="expert__content">
<div class="expert__title-container">
<h3 class="expert__title">{{ volunteer.name }}</h3>
{% if volunteer.website %}
<a class="exper__linkedinlink" href="{{ volunteer.website }}"><span class="expert__link-icon"></span></a>
{% endif %}
{% if volunteer.linkedin_profile %}
<a class="exper__linkedinlink" href="{{ volunteer.linkedin_profile }}"><span class="expert__linkedin-icon"></span></a>
{% endif %}
{% if volunteer.twitter_profile %}
<a class="exper__linkedinlink" href="{{ volunteer.twitter_profile }}"><span class="expert__twitter-icon"></span></a>
{% endif %}
{% if volunteer.orcid_profile %}
<a class="exper__linkedinlink" href="{{ volunteer.orcid_profile }}"><span class="expert__orcid-icon"></span></a>
{% endif %}
</div>
<div class="expert__text richtext">
<p><strong>{{ volunteer.affiliation }}</strong></p>
<p>{{ volunteer.bio }}</p>
</div>
<div class="expert__link">
<a class="expert__link-text"
href="/answers_by/{{ volunteer.pk }}">{% trans 'Bekijk de vragen die beantwoord zijn door ' %} {{ volunteer.name }}</a>
</div>

</div>
</div>
66 changes: 66 additions & 0 deletions klimaat_helpdesk/templates/volunteers/volunteers_list.html
@@ -0,0 +1,66 @@
{% extends "base.html" %}
{% load i18n static wagtailcore_tags%}

{% block smokedglass %}
{% endblock %}

{% block content_area %}
<div {% block smokedglass-class %}{% endblock %}>

{% block head %}
<div class="simple-header">
<div class="simple-header__wrapper">
<a class="simple-header__back-link" href="/">
<span class="simple-header__back-link-icon"></span>
</a>

<div class="simple-header__title-container">
<h1 class="simple-header__title">{{ page.title }}</h1>
</div>

<div class="simple-header__introduction-container">
<div class="simple-header__introduction">
{{ page.intro|richtext }}
</div>
</div>

</div>
</div>
{% endblock %}

{% block content %}
<div class="expert-list">
<div class="expert-list__wrapper">
<div class="expert-list__experts">
{% for volunteer in volunteers %}
{% include 'volunteers/includes/volunteer_block.html' with volunteer=volunteer %}
{% endfor %}
</div>
</div>
</div>

<div class="link-block">
<div class="link-block__wrapper">
<div class="link-block__title-container">
<h2 class="link-block__title">
{% trans 'Wie zijn de mensen achter de KlimaatHelpdesk' %}
</h2>
</div>

<div class="link-block__text-container">
<div class="link-block__text richtext">
{{ page.outro|richtext }}
</div>
<a href="/about">
<button class="button">
<span class="button__text">{% trans 'Wie zijn wij?' %}</span>
<span class="button__icon"></span>
</button>
</a>
</div>
</div>
</div>

{% endblock %}
</div>
{% endblock content_area %}
Empty file.
23 changes: 23 additions & 0 deletions klimaat_helpdesk/volunteers/admin.py
@@ -0,0 +1,23 @@
from django.utils.translation import gettext_lazy as _
from django.contrib import admin
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register

from klimaat_helpdesk.volunteers.models import Volunteer


class VolunteerAdmin(ModelAdmin):
model = Volunteer
menu_label = _('Volunteers')
menu_icon = 'user'
menu_order = 280
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('name', 'affiliation', 'email')
search_fields = ('name', 'affiliation')


modeladmin_register(VolunteerAdmin)

admin.site.register([
Volunteer,
])
7 changes: 7 additions & 0 deletions klimaat_helpdesk/volunteers/apps.py
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class VolunteersConfig(AppConfig):
name = "klimaat_helpdesk.volunteers"
verbose_name = _("Volunteers")
57 changes: 57 additions & 0 deletions klimaat_helpdesk/volunteers/models.py
@@ -0,0 +1,57 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel

from wagtail.snippets.models import register_snippet

@register_snippet
class Volunteer(models.Model):
""" Volunteers are people who contribute time to Klimaat Helpdesk. The model is similar to those of
experts, with some minor differences that's why it is not a plain inherited object.
"""

name = models.CharField(_('name'), max_length=255, null=False, blank=False)
email = models.EmailField(_('email'), null=True, blank=True)
bio = models.TextField(verbose_name=_('biography'), null=False, blank=False)
picture = models.ForeignKey('wagtailimages.Image', null=True, related_name='+', on_delete=models.SET_NULL)
areas_expertise = TaggableManager(verbose_name=_('areas of expertise'))
affiliation = models.CharField(_('Affiliation'), blank=False, max_length=128)
website = models.URLField(_('Website'), blank=True)
twitter_profile = models.URLField(_('Twitter Profile'), blank=True, null=True)
linkedin_profile = models.URLField(_('LinkedIn Profile'), blank=True, null=True)
orcid_profile = models.URLField(_('OrcID Link'), blank=True, null=True)
creation_date = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now_add=True)
active_since = models.DateTimeField(null=True, auto_now=False, default=None)

panels = [
FieldPanel('name'),
ImageChooserPanel('picture', heading="Volunteer's photo, 1:1 aspect ratio (square) works best"),
FieldPanel('email'),
FieldPanel('bio'),
FieldPanel('affiliation'),
FieldPanel('areas_expertise', heading="Areas of expertise. A maximum of 16 characters per word is recommended for optimal mobile display"),
FieldPanel('website'),
FieldPanel('twitter_profile'),
FieldPanel('linkedin_profile'),
FieldPanel('orcid_profile'),
]

def __str__(self):
return f"{self.name}"

@property
def twitter_username(self):
if self.twitter_profile:
if self.twitter_profile.endswith('/'):
self.twitter_profile = self.twitter_profile[:-1]
self.save()
twitter_username = self.twitter_profile.split('/')[-1]
return twitter_username

class Meta:
ordering = ['name', ]


0 comments on commit e83fed2

Please sign in to comment.