# -*- coding: utf-8 -*-
#
# (c) 2014 Bjoern Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of 'trex' for details.
#

from rest_framework import generics

from trex.models.project import Project, Entry
from trex.serializers import (
    ProjectSerializer, ProjectDetailSerializer, EntryDetailSerializer)


class ProjectListCreateAPIView(generics.ListCreateAPIView):

    queryset = Project.objects.all()
    serializer_class = ProjectSerializer


class ProjectDetailAPIView(generics.RetrieveUpdateDestroyAPIView):

    queryset = Project.objects.all()
    serializer_class = ProjectDetailSerializer


class EntryDetailAPIView(generics.RetrieveUpdateDestroyAPIView):

    queryset = Entry.objects.all()
    serializer_class = EntryDetailSerializer

@@ -169,17 +169,70 @@
 generics
+, status%0Afrom rest_framework.response import Response
 %0A
-
 %0Afrom tr
@@ -271,16 +271,57 @@
 , Entry%0A
+from trex.parsers import PlainTextParser%0A
 from tre
@@ -414,16 +414,53 @@
 alizer)%0A
+from trex.utils import Zeiterfassung%0A
 %0A%0Aclass 
@@ -691,32 +691,32 @@
 t.objects.all()%0A
-
     serializer_c
@@ -744,24 +744,1142 @@
 erializer%0A%0A%0A
+class ProjectZeiterfassungAPIView(generics.CreateAPIView):%0A%0A    queryset = Project.objects.all()%0A    parser_classes = (PlainTextParser,)%0A    serializer_class = ProjectDetailSerializer%0A%0A    def create(self, request, *args, **kwargs):%0A        try:%0A            proj = self.get_object()%0A        except Project.DoesNotExist:%0A            errors = self._create_errors(%22Project does not exist%22)%0A            return Response(errors, status=status.HTTP_400_BAD_REQUEST)%0A%0A        zeiterfassung = Zeiterfassung(request.DATA)%0A        try:%0A            proj.create_entries_from_zeiterfassung(zeiterfassung)%0A        except Exception, e:%0A            errors = self._create_errors(str(e))%0A            # TODO review if e could contain info not suited for the user%0A            return Response(errors, status=status.HTTP_400_BAD_REQUEST)%0A%0A        serializer = self.get_serializer(proj)%0A        headers = self.get_success_headers(serializer.data)%0A        return Response(serializer.data, status=status.HTTP_201_CREATED,%0A                        headers=headers)%0A%0A    def _create_errors(self, msg):%0A        return %7B%22non_field_errors%22: %5Bmsg%5D%7D%0A%0A%0A
 class EntryD

Add view to add Zeiterfassung entries from a plain text submission