import json
import logging

from django.shortcuts import render
from django.http import HttpResponse

from .models import Event


logger = logging.getLogger(__name__)


def fetch_events(request):
    """
    Return Events-Resultset in json format.
    """
    logger.info("request post: {}".format(request.POST))
    logger.info("request get: {}".format(request.GET))
    categories = set([request.GET["foo"],])
    logger.info('categories: {}'.format(categories))
    events = Event.objects.all()
    result = []
    for event in Event.objects.all():
        e_categories = set(event.categories.split(','))
        logger.info("ecategories: {}".format(e_categories))
        intersection = categories.intersection(e_categories)
        logger.info("intersection: {}".format(intersection))
        if len(intersection) > 0:
            result.append({
                'title': event.title,
                'description': event.description,
            })
    json_response = json.dumps(result)
    return HttpResponse(json_response, content_type="application/json")

@@ -1059,8 +1059,185 @@
 /json%22)%0A
+%0A%0Adef create_event(request):%0A    %22%22%22%0A    Create a new event%0A    %22%22%22%0A    json_response = json.dumps('ok')%0A    return HttpResponse(json_response, content_type=%22application/json%22)%0A

create new event stub