testovi ne rade
This commit is contained in:
parent
92d98a299c
commit
75c00b0e91
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,18 +16,3 @@ class ObjektSigurnosti(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.naziv
|
||||
|
||||
# class Log(models.Model):
|
||||
|
||||
# AKCIJA_CHOICES = (
|
||||
# ('Brisanje', 'Brisanje'),
|
||||
# ('Unos', 'Unos'),
|
||||
# ('Uređivanje', 'Uređivanje')
|
||||
# )
|
||||
# user = models.ForeignKey("user.User", null=True, related_name='user_logs', on_delete=models.SET_NULL)
|
||||
# timestamp = models.DateTimeField(auto_now_add=True)
|
||||
# akcija = models.CharField(max_length=255, choices=AKCIJA_CHOICES)
|
||||
# opis = models.TextField()
|
||||
|
||||
# def __str__(self):
|
||||
# return self.opis
|
||||
@ -1,18 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.gis.geos import Point
|
||||
from .models import ObjektSigurnosti
|
||||
# class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||
# class Meta:
|
||||
# model = ObjektSigurnosti
|
||||
# fields = '__all__'
|
||||
|
||||
# class LogSerializer(serializers.ModelSerializer):
|
||||
|
||||
# user_full_name = serializers.ReadOnlyField(source='user.full_name')
|
||||
|
||||
# class Meta:
|
||||
# model = Log
|
||||
# fields = ('id', 'user', 'user_full_name', 'timestamp', 'akcija', 'opis')
|
||||
|
||||
class PointSerializer(serializers.Serializer):
|
||||
lat = serializers.FloatField()
|
||||
@ -21,9 +9,6 @@ class PointSerializer(serializers.Serializer):
|
||||
def to_representation(self, instance):
|
||||
return {'lat': instance.y, 'lon': instance.x}
|
||||
|
||||
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||
lokacija = PointSerializer()
|
||||
|
||||
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||
lokacija = PointSerializer()
|
||||
|
||||
|
||||
@ -43,27 +43,15 @@ class ObjektSigurnostiDetailTest(APITestCase):
|
||||
response = self.client.get(self.url)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# def test_update_objekt_sigurnosti(self):
|
||||
# data = {
|
||||
# 'lokacija': {'lat': 15.17517, 'lon': 44.01113},
|
||||
# 'naziv' : 'updated-naziv',
|
||||
def test_update_objekt_sigurnosti(self):
|
||||
data = {
|
||||
'lokacija': {'lat':18.457, 'lon':45.124},
|
||||
'naziv' : 'updated-naziv',
|
||||
|
||||
# }
|
||||
# response = self.client.patch(self.url, data, format='json')
|
||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
# # Reload the object from the database
|
||||
# updated_objekt = ObjektSigurnosti.objects.get(pk=self.objekt.pk)
|
||||
|
||||
# # Check if the values are updated correctly
|
||||
# self.assertEqual(updated_objekt.lokacija.x, 13.79758)
|
||||
# self.assertEqual(updated_objekt.lokacija.y, 44.9254)
|
||||
# self.assertEqual(updated_objekt.naziv, 'updated-naziv')
|
||||
}
|
||||
response = self.client.patch(self.url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
# def test_retrieve_objekt_sigurnosti(self):
|
||||
# url = reverse('objektisigurnosti-detail', args=[self.objekt.id])
|
||||
# response = self.client.get(url)
|
||||
|
||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
@ -6,5 +6,4 @@ from plovidba_aplikacija import views
|
||||
urlpatterns = [
|
||||
path('objekti/', ObjektSigurnostiList.as_view(), name='objektisigurnosti-list'),
|
||||
path('objekti/<int:pk>/', ObjektSigurnostiDetail.as_view(), name='objektisigurnosti-detail' ),
|
||||
# path('logs/', views.Log.as_view(), name='log-list')
|
||||
]
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
# views.py
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.response import Response
|
||||
@ -25,19 +24,9 @@ class ObjektSigurnostiList(generics.ListCreateAPIView):
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return user.accounts.all()
|
||||
# def get_queryset(self): #queryset je data iz database, listing and creating objects
|
||||
# queryset = ObjektSigurnosti.objects.all()
|
||||
# location = self.request.query_params.get('lokacija')
|
||||
# if location is not None:
|
||||
# queryset = queryset.filter(lokacija__icontains=location)
|
||||
# return queryset
|
||||
|
||||
def perform_create(self, serializer):
|
||||
#used to customize the behavior when creating an object, and in this case,
|
||||
#it sets the operater field and creates a log entry for the created object.
|
||||
serializer.save(operater=self.request.user)
|
||||
# instance = serializer.instance
|
||||
# self.create_log(instance)
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.request.method == "GET":
|
||||
@ -45,21 +34,7 @@ def get_serializer_class(self):
|
||||
return self.serializer_class()
|
||||
|
||||
|
||||
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView): #retrieving, updating, and deleting a specific object
|
||||
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = ObjektSigurnosti.objects.all()
|
||||
serializer_class = ObjektSigurnostiSerializer
|
||||
|
||||
# def perform_update(self, serializer):
|
||||
# instance = serializer.save()
|
||||
# opis = "Korisnik je uredio objekt sigurnosti {} (ID: {})".format(
|
||||
# instance.vrsta.naziv, instance.id
|
||||
# )
|
||||
# Log.objects.create(user=self.request.user, akcija="Uređivanje", opis=opis)
|
||||
|
||||
# def perform_destroy(self, instance):
|
||||
# super().perform_destroy(instance)
|
||||
# opis = "Korisnik je obrisao objekt sigurnosti {} (ID: {})".format(
|
||||
# instance.vrsta.naziv, instance.id
|
||||
# )
|
||||
# Log.objects.create(user=self.request.user, akcija="Brisanje", opis=opis)
|
||||
|
||||
permission_classes = []
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -9,7 +9,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
PARDIR = os.pardir
|
||||
|
||||
APPLICATION_NAME = "rgi-dev"
|
||||
APPLICATION_NAME = "plovidba_aplikacija "
|
||||
|
||||
ENV_PATH = os.path.join('/etc/secrets/', APPLICATION_NAME)
|
||||
|
||||
|
||||
@ -50,7 +50,6 @@ INSTALLED_APPS = [
|
||||
# 3rd party
|
||||
'rest_framework',
|
||||
'drf_yasg',
|
||||
'rest_framework_swagger',
|
||||
# Custom apps:
|
||||
'plovidba_aplikacija',
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user