Skip to content

Commit

Permalink
Merge branch 'main' into 741-graphql-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurocon committed Jun 15, 2023
2 parents 96eed3e + 54985c2 commit 6b6e103
Show file tree
Hide file tree
Showing 50 changed files with 763 additions and 800 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Replace the `MEDIA_ROOT` and `DATA_EXPORT_ROOT` settings with proper locations.

For example: *(make sure the directory exists!)*

MEDIA_ROOT = "/tmp/amelie_uploads/"
MEDIA_ROOT = "/tmp/amelie_uploads"

##### Populate the database
python manage.py migrate
Expand Down
2 changes: 1 addition & 1 deletion amelie/activities/templates/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="h2-with-buttons">
<div class="content">
{% if login_for_more %}
<p class="icon icon-information">
{% url 'login' as login_url %}
{% url 'oidc_authentication_init' as login_url %}
{% trans "More photos are available if you" %} <a href="{{ login_url }}?next={% url 'activities:gallery' pk %}">{% trans 'logged in' %}</a>.
</p>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion amelie/activities/templates/gallery_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h2>

{% if not request.person %}
<p class="icon icon-information">
{% url 'login' as login_url %}
{% url 'oidc_authentication_init' as login_url %}
{% trans "More photos are available if you" %} <a
href="{{ login_url }}?next={% url 'activities:photos' %}">{% trans 'logged in' %}</a>.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
{% endif %}
{% else %}
<p class="icon warning">
{% url 'login' as login_url %}
{% url 'oidc_authentication_init' as login_url %}
{% blocktrans with login_url=login_url next_url=obj.get_absolute_url %}
To view or alter your enrollment, please <a href="{{ login_url }}?next={{ next_url }}">log in</a>.
{% endblocktrans %}
Expand Down
3 changes: 3 additions & 0 deletions amelie/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from modernrpc.core import Protocol
from modernrpc.views import RPCEntryPoint

from amelie.companies.views import vivatbanner_get

app_name = 'api'


urlpatterns = [
path('', RPCEntryPoint.as_view(protocol=Protocol.JSON_RPC), name="jsonrpc_mountpoint"),
path('docs/', RPCEntryPoint.as_view(enable_doc=True, enable_rpc=False, template_name="api/doc_index.html")),
path('vivat_banners/', vivatbanner_get, name='vivatbanner_get'),
]
2 changes: 1 addition & 1 deletion amelie/claudia/account_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def dispatch(self, request, *args, **kwargs):
class AccountPasswordResetLink(FormView):
template_name = "accounts/password_reset_link.html"
form_class = AccountPasswordResetLinkForm
success_url = reverse_lazy('login')
success_url = reverse_lazy('oidc_authentication_init')

def dispatch(self, request, *args, **kwargs):
if self.request.user.is_authenticated:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>{% trans "Reset e-mail sent" %}</h2>
<p>
{% trans 'Check the email address you have registered at Inter-<i>Actief</i> for a link to reset your password. If it doesn’t appear within a few minutes, check your spam folder.' %}
</p>
<a class="looks-like-a-button" href="{% url "login" %}">{% trans 'Return to login' %}</a>
<a class="looks-like-a-button" href="{% url "oidc_authentication_init" %}">{% trans 'Return to login' %}</a>
</div>
</div></div>
{% endblock content %}
7 changes: 6 additions & 1 deletion amelie/companies/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from amelie.companies.models import Company, TelevisionBanner, WebsiteBanner
from amelie.companies.models import Company, TelevisionBanner, WebsiteBanner, VivatBanner


class CompanyAdmin(admin.ModelAdmin):
Expand All @@ -16,6 +16,11 @@ class TelevisionBannerAdmin(admin.ModelAdmin):
list_display = ['name', 'start_date', 'end_date', 'active']


class VivatBannerAdmin(admin.ModelAdmin):
list_display = ['name', 'start_date', 'end_date', 'active']


admin.site.register(Company, CompanyAdmin)
admin.site.register(WebsiteBanner, WebsiteBannerAdmin)
admin.site.register(TelevisionBanner, TelevisionBannerAdmin)
admin.site.register(VivatBanner, VivatBannerAdmin)
18 changes: 14 additions & 4 deletions amelie/companies/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from amelie.companies.models import Company, WebsiteBanner, TelevisionBanner, CompanyEvent
from amelie.companies.models import Company, WebsiteBanner, TelevisionBanner, CompanyEvent, VivatBanner
from amelie.style.forms import inject_style
from amelie.calendar.forms import EventForm
from amelie.tools.widgets import DateTimeSelector, DateSelector
Expand Down Expand Up @@ -62,7 +62,7 @@ def clean_app_logo(self):


class BannerForm(forms.ModelForm):
picture = forms.FileField(label=_('Website banner'), widget=AdminFileWidget)
picture = forms.ImageField(label=_('Website banner'), widget=AdminFileWidget)
start_date = forms.DateField(widget=DateSelector)
end_date = forms.DateField(widget=DateSelector)

Expand All @@ -72,7 +72,7 @@ class Meta:


class TelevisionBannerForm(forms.ModelForm):
picture = forms.FileField(label=_('Television banner'), widget=AdminFileWidget)
picture = forms.ImageField(label=_('Television banner'), widget=AdminFileWidget)
start_date = forms.DateField(widget=DateSelector)
end_date = forms.DateField(widget=DateSelector)

Expand All @@ -81,6 +81,16 @@ class Meta:
fields = ["picture", "name", 'start_date', "end_date", 'active']


class VivatBannerForm(forms.ModelForm):
picture = forms.FileField(label=_('Vivat banner'), widget=AdminFileWidget)
start_date = forms.DateField(widget=DateSelector)
end_date = forms.DateField(widget=DateSelector)

class Meta:
model = VivatBanner
fields = ["picture", "name", 'start_date', "end_date", 'active', 'url']


class CompanyEventForm(EventForm):
company = forms.ModelChoiceField(queryset=Company.objects.filter(start_date__lte=timezone.now(), end_date__gte=timezone.now()), required=False)

Expand Down Expand Up @@ -130,4 +140,4 @@ class StatisticsForm(forms.Form):
end_date = forms.SplitDateTimeField(label=_('End (till)'), widget=DateTimeSelector, required=True)


inject_style(CompanyForm, CompanyEventForm, BannerForm, TelevisionBannerForm, StatisticsForm)
inject_style(CompanyForm, CompanyEventForm, BannerForm, TelevisionBannerForm, VivatBannerForm, StatisticsForm)
28 changes: 28 additions & 0 deletions amelie/companies/migrations/0006_vivatbanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.17 on 2023-05-23 14:54

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('companies', '0005_add_default_career_label'),
]

operations = [
migrations.CreateModel(
name='VivatBanner',
fields=[
('basebanner_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='companies.basebanner')),
('url', models.URLField()),
('views', models.PositiveIntegerField(default=0, editable=False)),
],
options={
'verbose_name': 'I/O Vivat banner',
'verbose_name_plural': 'I/O Vivat banners',
'ordering': ['-end_date'],
},
bases=('companies.basebanner',),
),
]
14 changes: 14 additions & 0 deletions amelie/companies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ class Meta:
verbose_name_plural = _('Television banners')


class VivatBanner(BaseBanner):
url = models.URLField()
views = models.PositiveIntegerField(editable=False, default=0)

def save(self, **kwargs):
self.slug = slugify(self.name)
super(VivatBanner, self).save(**kwargs)

class Meta:
ordering = ['-end_date']
verbose_name = _('I/O Vivat banner')
verbose_name_plural = _('I/O Vivat banners')


class CompanyEvent(Event):
objects = EventManager()
company = models.ForeignKey('Company', blank=True, null=True, on_delete=models.SET_NULL)
Expand Down
41 changes: 38 additions & 3 deletions amelie/companies/templates/companies/company_banners.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>{% trans 'Website banners' %}</h2>
<div class="content">
<p>
{% blocktrans %}
Click on the website banner to edit it
Click on the website banner to edit it.
{% endblocktrans %}
</p>
<a href="{% url 'companies:websitebanner_create' %}" class="looks-like-a-button">{% trans 'New' %}</a>
Expand Down Expand Up @@ -47,8 +47,7 @@ <h2> {% trans "Television banners" %} </h2>
<div class="content">
<p>
{% blocktrans %}
Clicking on the television banner should allow you to edit it, but this feature has not been
implemented yet.
Click on the television banner to edit it.
{% endblocktrans %}
</p>
<a href="{% url 'companies:televisionbanner_create' %}" class="looks-like-a-button">{% trans "New" %}</a>
Expand Down Expand Up @@ -76,4 +75,40 @@ <h2> {% trans "Television banners" %} </h2>
</a>
</div>
{% endfor %}

<div class="col-xs-12">
<div class="ia">
<h2> {% trans "I/O Vivat banners" %} </h2>

<div class="content">
<p>
{% blocktrans %}
Click on the vivat banner to edit it.
{% endblocktrans %}
</p>
<a href="{% url 'companies:vivatbanner_create' %}" class="looks-like-a-button">{% trans "New" %}</a>
</div>
</div>
</div>
{% for vb in vivat_banners %}
<div class="col-xs-12 col-md-6">
<a href="{% url 'companies:banner_edit' vb.id %}" class="panel panel-default banner-grid vivat">
<div class="ia"><h2>{{ vb.name }}</h2></div>
<img src="{{ MEDIA_URL }}{{ vb.picture }}">
{% if vb.end_date >= today and vb.start_date <= today and vb.active %}
<span>{% blocktrans with end_date=vb.end_date %}Expires: {{ end_date }}{% endblocktrans %}
<span class="label label-success">{% trans 'Active' %}</span></span>
{% elif vb.end_date >= today and vb.start_date <= today %}
<span>{% blocktrans with end_date=vb.end_date %}Expires: {{ end_date }}{% endblocktrans %}
<span class="label label-default">{% trans "Turned off" %}</span></span>
{% elif vb.start_date > today %}
<span>{% blocktrans with start_date=vb.start_date %}Active from: {{ start_date }}{% endblocktrans %}
<span class="label label-primary">{% trans "Future" %}</span></span>
{% else %}
<span>{% blocktrans with end_date=vb.end_date %}Has expired on: {{ end_date }}{% endblocktrans %}
<span class="label label-default">{% trans "Past" %}</span></span>
{% endif %}
</a>
</div>
{% endfor %}
{% endblock %}
1 change: 1 addition & 0 deletions amelie/companies/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
path('banners/<int:id>/', views.banner_edit, name='banner_edit'),
path('banners/create_web/', views.websitebanner_create, name='websitebanner_create'),
path('banners/create_tv/', views.televisionbanner_create, name='televisionbanner_create'),
path('banners/create_vivat/', views.vivatbanner_create, name='vivatbanner_create'),

path('activities/', views.event_list, name='event_list'),
path('activities/<int:id>/', views.event_details, name='event_details'),
Expand Down
64 changes: 60 additions & 4 deletions amelie/companies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import random

from django.conf import settings
from django.urls import reverse
from django.db.models import Q
from django.http import HttpResponseRedirect, HttpResponse
Expand All @@ -10,13 +11,15 @@
from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView

from amelie.companies.forms import CompanyForm, BannerForm, TelevisionBannerForm, CompanyEventForm, StatisticsForm
from amelie.companies.models import BaseBanner, Company, CompanyEvent, TelevisionBanner, WebsiteBanner
from amelie.companies.forms import CompanyForm, BannerForm, TelevisionBannerForm, CompanyEventForm, StatisticsForm, \
VivatBannerForm
from amelie.companies.models import BaseBanner, Company, CompanyEvent, TelevisionBanner, WebsiteBanner, VivatBanner
from amelie.members.models import Committee
from amelie.statistics.decorators import track_hits
from amelie.tools.decorators import require_board
from amelie.tools.forms import PeriodForm
from amelie.tools.calendar import ical_calendar
from amelie.tools.http import HttpJSONResponse
from amelie.tools.mixins import RequireBoardMixin, RequireCommitteeMixin

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -58,19 +61,25 @@ def banner_list(request):
""" List of all banners """
website_banners = WebsiteBanner.objects.all()
television_banners = TelevisionBanner.objects.all()
vivat_banners = VivatBanner.objects.all()
today = datetime.date.today()
return render(request, 'companies/company_banners.html', {'website_banners': website_banners, 'television_banners': television_banners, 'today': today})
return render(request, 'companies/company_banners.html', {
'website_banners': website_banners, 'television_banners': television_banners, 'vivat_banners': vivat_banners,
'today': today
})


@require_board
def banner_edit(request, id):
""" Edit either a website banner or television banner. """
""" Edit either a website banner, television banner or vivat banner. """
obj = get_object_or_404(BaseBanner, id=id)
form = None

if request.method == "POST":
if hasattr(obj, 'websitebanner'):
form = BannerForm(request.POST, request.FILES, instance=obj.websitebanner)
elif hasattr(obj, 'vivatbanner'):
form = VivatBannerForm(request.POST, request.FILES, instance=obj.vivatbanner)
else:
form = TelevisionBannerForm(request.POST, request.FILES, instance=obj.televisionbanner)

Expand All @@ -81,6 +90,8 @@ def banner_edit(request, id):
else:
if hasattr(obj, 'websitebanner'):
form = BannerForm(instance=obj.websitebanner)
elif hasattr(obj, 'vivatbanner'):
form = VivatBannerForm(instance=obj.vivatbanner)
else:
form = TelevisionBannerForm(instance=obj.televisionbanner)

Expand Down Expand Up @@ -117,6 +128,51 @@ def televisionbanner_create(request):
return render(request, 'companies/company_banners_form.html', locals())


@require_board
def vivatbanner_create(request):
""" Create a vivat banner. """
if request.method == "POST":
form = VivatBannerForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('companies:banner_list'))

else:
form = VivatBannerForm()

return render(request, 'companies/company_banners_form.html', locals())


def vivatbanner_get(request):
""" Gets a number (3 default) of vivat banners in JSON format for use on the IO Vivat website. """
try:
# Get amount from argument 'n', default is 3
amount = int(request.GET.get("n", "3"))
# Clamp amount between 1 and 20
amount = max(1, min(amount, 20))
except ValueError:
# Could not parse argument, use default
amount = 3

# Get banners (only currently active banners, random order)
banners = VivatBanner.objects.filter(
active=True, start_date__lte=datetime.date.today(), end_date__gte=datetime.date.today()
).order_by('?')[:amount]

# Return them as JSON data
return HttpJSONResponse({
'amount': amount,
'banners': [
{
"picture": "{}{}".format(settings.MEDIA_URL, banner.picture),
"name": banner.name,
"link": banner.url
}
for banner in banners
]
})


@require_board
def company_overview_old(request):
"""
Expand Down
7 changes: 0 additions & 7 deletions amelie/data_export/exporters/amelie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from oauth2_provider.models import Application, AccessToken, Grant
from zipfile import ZipFile

from social_django.models import UserSocialAuth

from amelie.claudia.models import Mapping, Timeline, Event as ClaudiaEvent
from amelie.data_export.exporters.exporter import DataExporter
from amelie.personal_tab.models import ReversalTransaction, DebtCollectionTransaction, CustomTransaction, \
Expand Down Expand Up @@ -310,11 +308,6 @@ def export_oauth(self):
'expiry_date': str(grant.expires),
'scopes': str(grant.scope),
} for grant in Grant.objects.filter(user=person.user)],
'authentication_providers': [{
'provider': auth.provider,
'uid': auth.uid,
'extra_data': auth.extra_data,
} for auth in UserSocialAuth.objects.filter(user=person.user)],
}

return oauth_data, []
Expand Down
Loading

0 comments on commit 6b6e103

Please sign in to comment.