Commit 6e9625b6 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Add API to partners app for events

parent 0ebeb903
......@@ -32,7 +32,7 @@
var sources = {
events: "/api/events",
birthdays: "/api/members/birthdays",
{# extern: ".nu/api/ext-events"#} {# TODO IMPLEMENT THIS #}
partners: "/api/partners/events"
};
$('#calendar').fullCalendar({
......@@ -77,7 +77,7 @@
titleRangeSeparator: ' - ',
timeFormat: 'H:mm',
eventLimit: true, // allow "more" link when too many events
eventSources: Cookies.get('showbirthdays') ? [sources.events, sources.birthdays, sources.extern] : [sources.events, sources.extern],
eventSources: Cookies.get('showbirthdays') ? [sources.events, sources.birthdays, sources.partners] : [sources.events, sources.partners],
eventClick: function(event) {
if(event.url && event.blank) {
window.open(event.url, '_blank');
......
......@@ -7,6 +7,7 @@ from partners.models import (
PartnerImage,
VacancyCategory,
Vacancy,
PartnerEvent
)
......@@ -58,3 +59,12 @@ class VacancyAdmin(admin.ModelAdmin):
'fields': ('categories', )
}),
)
@admin.register(PartnerEvent)
class PartnerEventAdmin(TranslatedModelAdmin):
fields = ['partner', 'title', 'description', 'location', 'start', 'end',
'url', 'published']
list_display = ('title', 'start', 'end',
'partner', 'published')
list_filter = ('start', 'published')
from django.utils import timezone
from django.urls import reverse
from rest_framework import serializers
from events.api.serializers import CalenderJSSerializer
from partners.models import PartnerEvent
class PartnerEventSerializer(CalenderJSSerializer):
class Meta(CalenderJSSerializer.Meta):
model = PartnerEvent
def _background_color(self, instance):
return '#E62272'
def _text_color(self, instance):
return '#FFFFF'
def _url(self, instance):
return instance.url
def _target_blank(self, instance):
return True
from rest_framework import routers
from partners.api import viewsets
router = routers.SimpleRouter()
router.register(r'partners', viewsets.PartnerViewset)
urlpatterns = router.urls
from rest_framework import viewsets
from rest_framework.exceptions import ParseError
from rest_framework.response import Response
from rest_framework.decorators import list_route
from django.utils import timezone
from datetime import datetime
from partners.api.serializers import PartnerEventSerializer
from partners.models import Partner, PartnerEvent
class PartnerViewset(viewsets.ViewSet):
queryset = Partner.objects.all()
@list_route()
def events(self, request):
try:
start = timezone.make_aware(
datetime.strptime(request.query_params['start'], '%Y-%m-%d')
)
end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d')
)
except:
raise ParseError(detail='start or end query parameters invalid')
queryset = PartnerEvent.objects.filter(
end__gte=start,
start__lte=end,
published=True
)
serializer = PartnerEventSerializer(queryset, many=True)
return Response(serializer.data)
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-25 18:42
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('partners', '0004_add_tinymce_to_vacancy_and_partner'),
]
operations = [
migrations.CreateModel(
name='PartnerEvent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start', models.DateTimeField(verbose_name='start time')),
('end', models.DateTimeField(verbose_name='end time')),
('url', models.URLField(verbose_name='website')),
('published', models.BooleanField(default=False, verbose_name='published')),
('location_en', models.CharField(max_length=255, verbose_name='location (EN)')),
('location_nl', models.CharField(max_length=255, verbose_name='location (NL)')),
('title_en', models.CharField(max_length=100, verbose_name='title (EN)')),
('title_nl', models.CharField(max_length=100, verbose_name='title (NL)')),
('description_en', models.TextField(verbose_name='description (EN)')),
('description_nl', models.TextField(verbose_name='description (NL)')),
('partner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='partners.Partner')),
],
),
]
from django.db import models
from django.core.validators import RegexValidator, URLValidator
from django.urls import reverse
from django.utils.translation import ugettext, ugettext_lazy as _, \
string_concat
from utils.translation import MultilingualField, ModelTranslateMeta
from tinymce.models import HTMLField
......@@ -126,3 +128,39 @@ class Vacancy(models.Model):
class Meta:
verbose_name_plural = 'Vacancies'
class PartnerEvent(models.Model, metaclass=ModelTranslateMeta):
partner = models.ForeignKey(
Partner,
on_delete=models.CASCADE,
related_name="events"
)
title = MultilingualField(
models.CharField,
_("title"),
max_length=100
)
description = MultilingualField(
models.TextField,
_("description")
)
location = MultilingualField(
models.CharField,
_("location"),
max_length=255,
)
start = models.DateTimeField(_("start time"))
end = models.DateTimeField(_("end time"))
url = models.URLField(_("website"))
published = models.BooleanField(_("published"), default=False)
def __str__(self):
return self.title
......@@ -76,6 +76,7 @@ urlpatterns = [
url(r'^api/', include([
url(r'^', include('events.api.urls')),
url(r'^', include('members.api.urls')),
url(r'^', include('partners.api.urls')),
])),
url(r'^education/', include('education.urls', namespace='education')),
# Default login helpers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment