CrashViewSet   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
wmc 0
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2014 Crystalnix Limited
7
8
Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
use this file except in compliance with the License. You may obtain a copy of
10
the License at
11
12
    http://www.apache.org/licenses/LICENSE-2.0
13
14
Unless required by applicable law or agreed to in writing, software
15
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
License for the specific language governing permissions and limitations under
18
the License.
19
"""
20
21
from django.db.utils import IntegrityError
22
23
from rest_framework import viewsets
24
from rest_framework import mixins
25
from rest_framework import status
26
from rest_framework.response import Response
27
28
from omaha.api import BaseView, StandardResultsSetPagination
29
from crash.serializers import SymbolsSerializer, CrashSerializer
30
from crash.models import Symbols, Crash
31
32
33
class SymbolsViewSet(BaseView):
34
    queryset = Symbols.objects.all().order_by('-id')
35
    serializer_class = SymbolsSerializer
36
37
    def create(self, request, *args, **kwargs):
38
        try:
39
            return super(SymbolsViewSet, self).create(request, *args, **kwargs)
40
        except IntegrityError:
41
            res = {"message": "Duplicate symbol"}
42
            return Response(data=res, status=status.HTTP_409_CONFLICT)
43
44
45
class CrashViewSet(mixins.ListModelMixin,
46
                   mixins.RetrieveModelMixin,
47
                   viewsets.GenericViewSet):
48
    queryset = Crash.objects.all().order_by('-id')
49
    serializer_class = CrashSerializer
50
    pagination_class = StandardResultsSetPagination
51