Commit a12c5411 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

add p3

parent a354e0ff
Pipeline #37 failed with stages
......@@ -65,6 +65,22 @@ def create_p2(instance, now_prefix, prev_prefix, series_of_prefix):
prefix.save()
def create_p3(instance, now_prefix, prev_prefix, series_of_prefix):
try :
prefix = OccuringFunctionalityP3.objects.get(prefix_of_occuring_functionality_p3 = instance, prefix_boilerplate_of_occuring_functionality_p3 = instance.boilerplate, prefix_series_of_occuring_functionality_p3 = series_of_prefix)
if now_prefix == prev_prefix:
return
prefix = OccuringFunctionalityP3.objects.get(prefix_of_occuring_functionality_p3 = instance, prefix_boilerplate_of_occuring_functionality_p3 = instance.boilerplate, prefix_series_of_occuring_functionality_p3 = series_of_prefix )
prefix.delete()
if now_prefix == SIMPLE_PREFIX_CHOICES[3][0]:
prefix = OccuringFunctionalityP3(prefix_of_occuring_functionality_p3 = instance, prefix_boilerplate_of_occuring_functionality_p3 = instance.boilerplate, prefix_series_of_occuring_functionality_p3 = series_of_prefix)
prefix.save()
except OccuringFunctionalityP3.DoesNotExist:
if now_prefix == SIMPLE_PREFIX_CHOICES[3][0]:
prefix = OccuringFunctionalityP3(prefix_of_occuring_functionality_p3 = instance, prefix_boilerplate_of_occuring_functionality_p3 = instance.boilerplate, prefix_series_of_occuring_functionality_p3 = series_of_prefix)
prefix.save()
def create_state_value_constraint_from_logical_expression(instance, logical_expression, prev_logical_expression, series_of_log_expr):
try :
log_expr = StateValueConstraint.objects.get(logical_expression = instance, prefix_of_logical_expression = instance.prefix, log_expr_series = series_of_log_expr)
......@@ -149,7 +165,11 @@ class Prefix(models.Model):
create_p2( self, self.simple_prefix_1, prev_prefix_list[0], '1')
create_p2( self, self.simple_prefix_2, prev_prefix_list[1], '2')
create_p2( self, self.simple_prefix_3, prev_prefix_list[2], '3')
'''Create P3 '''
create_p3( self, self.simple_prefix_1, prev_prefix_list[0], '1')
create_p3( self, self.simple_prefix_2, prev_prefix_list[1], '2')
create_p3( self, self.simple_prefix_3, prev_prefix_list[2], '3')
class Meta:
ordering = ['boilerplate']
......@@ -208,6 +228,20 @@ class OccuringFunctionalityP2(models.Model):
ordering = ['prefix_boilerplate_of_occuring_functionality_p2']
class OccuringFunctionalityP3(models.Model):
prefix_of_occuring_functionality_p3 = models.ForeignKey(Prefix, related_name='occuring_functionality_p3', on_delete=models.CASCADE)
prefix_boilerplate_of_occuring_functionality_p3 = models.ForeignKey(Boilerplate, related_name='occuring_functionality_b_p3', on_delete=models.CASCADE)
prefix_series_of_occuring_functionality_p3 = models.TextField(default='0')
system_for_occuring_functionality_p3 = models.TextField(max_length=100, blank=True,)
perform_for_occuring_functionality_p3 = models.TextField(max_length=100, blank=True,)
function_for_occuring_functionality_p3 = models.TextField(max_length=100, blank=True,)
item_for_occuring_functionality_p3 = models.TextField(max_length=100, blank=True,)
flow_for_occuring_functionality_p3 = models.TextField(max_length=100, blank=True,)
class Meta:
ordering = ['prefix_boilerplate_of_occuring_functionality_p3']
class StateValueConstraint(models.Model):
prefix_of_logical_expression = models.ForeignKey(Prefix, related_name='prefix_of_log_expr', on_delete=models.CASCADE)
logical_expression = models.ForeignKey(LogicalExpression, related_name='own_log_expr', on_delete=models.CASCADE)
......
from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, LogicalExpression, OccuringFunctionalityP2, StateValueConstraint, OccuringFunctionalityForLogicalExpression
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, LogicalExpression, OccuringFunctionalityP2, StateValueConstraint, OccuringFunctionalityForLogicalExpression, OccuringFunctionalityP3
class BoilerplateSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
......@@ -35,6 +35,16 @@ class OccuringFunctionalityP2Serializer(serializers.ModelSerializer):
class OccuringFunctionalityP3Serializer(serializers.ModelSerializer):
prefix_of_occuring_functionality_p3 = serializers.PrimaryKeyRelatedField(read_only=True)
prefix_boilerplate_of_occuring_functionality_p3 = serializers.PrimaryKeyRelatedField(read_only=True)
prefix_series_of_occuring_functionality_p3 = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = OccuringFunctionalityP3
fields = ('id', 'prefix_of_occuring_functionality_p3', 'prefix_boilerplate_of_occuring_functionality_p3', 'prefix_series_of_occuring_functionality_p3', 'system_for_occuring_functionality_p3', 'perform_for_occuring_functionality_p3', 'function_for_occuring_functionality_p3', 'item_for_occuring_functionality_p3', 'flow_for_occuring_functionality_p3')
class StateValueConstraintSerializer(serializers.ModelSerializer):
prefix_of_logical_expression = serializers.PrimaryKeyRelatedField(read_only=True)
logical_expression = serializers.PrimaryKeyRelatedField(read_only=True)
......
......@@ -15,9 +15,12 @@ urlpatterns = [
#'''P1'''
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/', requirements_views.LogicalExpressionListCreateAPIView.as_view(), name='api-log_expr-list'),
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/<int:pk>/', requirements_views.LogicalExpressionDetailsAPIView.as_view(), name='api-log_expr-details'),
#'''P2 or P3'''
#'''P2'''
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p2/', requirements_views.OccuringFunctionalityP2ListCreateAPIView.as_view(), name='api-occur_func-list'),
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p2/<int:pk>/', requirements_views.OccuringFunctionalityP2DetailsAPIView.as_view(), name='api-occur_func-details'),
#'''P3'''
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p3/', requirements_views.OccuringFunctionalityP3ListCreateAPIView.as_view(), name='api-occur_func_p3-list'),
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p3/<int:pk>/', requirements_views.OccuringFunctionalityP3DetailsAPIView.as_view(), name='api-occur_func_p3-details'),
#'''Logical expression of P1'''
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/<int:log_expr>/constraint/', requirements_views.StateValueConstraintListCreateAPIView.as_view(), name='api-constraint-list'),
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/<int:log_expr>/constraint/<int:pk>/', requirements_views.StateValueConstraintDetailsAPIView.as_view(), name='api-constraint-details'),
......
......@@ -5,8 +5,8 @@ from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, LogicalExpression, OccuringFunctionalityP2, StateValueConstraint, OccuringFunctionalityForLogicalExpression
from reqman.apps.reqtool.rest_api.serializers.requirements import PrefixSerializer, BoilerplateSerializer, LogicalExpressionSerializer, OccuringFunctionalityP2Serializer,StateValueConstraintSerializer, OccuringFunctionalityForLogicalExpressionSerializer
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, LogicalExpression, OccuringFunctionalityP2, OccuringFunctionalityP3, StateValueConstraint, OccuringFunctionalityForLogicalExpression
from reqman.apps.reqtool.rest_api.serializers.requirements import PrefixSerializer, BoilerplateSerializer, LogicalExpressionSerializer, OccuringFunctionalityP2Serializer, OccuringFunctionalityP3Serializer, StateValueConstraintSerializer, OccuringFunctionalityForLogicalExpressionSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.rest_api.services import fuseki
......@@ -189,6 +189,49 @@ class OccuringFunctionalityP2DetailsAPIView(RetrieveUpdateDestroyAPIView):
class OccuringFunctionalityP3ListCreateAPIView(ListCreateAPIView):
"""
API view to retrieve list of posts or create new
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = OccuringFunctionalityP3Serializer
#queryset = LogicalExpression.objects.all()
def get_queryset(self):
bp = self.kwargs['boilerplate']
pr = self.kwargs['prefixs']
queryset_prefix = OccuringFunctionalityP3.objects.filter(prefix_boilerplate_of_occuring_functionality_p3 = bp, prefix_of_occuring_functionality_p3 = pr)
return queryset_prefix
#Custom actions when POST
def perform_create(self, serializer):
serializer.save()
#print the data of the post
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
class OccuringFunctionalityP3DetailsAPIView(RetrieveUpdateDestroyAPIView):
"""
API view to retrieve, update or delete post
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = OccuringFunctionalityP3Serializer
queryset = OccuringFunctionalityP3.objects.all()
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.save()
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
#Custom actions when DELETE
def perform_destroy(self, instance):
#print("deleted")
instance.delete()
class StateValueConstraintListCreateAPIView(ListCreateAPIView):
"""
API view to retrieve list of posts or create new
......
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