Commit f44def27 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

has main

parent a12c5411
from .snippets import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
\ No newline at end of file
from .requirements import Boilerplate
\ No newline at end of file
from django.db import models
from reqman.apps.account.models import User
from pygments.formatters.html import HtmlFormatter
from pygments import highlight
MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quanti fier>] item [to stateValue]"),
("M2", "M2 : system/function shall [not] set state to stateValue"),
("M3", "M3 : system/function shall [not] send [<quanti fier>] item"),
("M4", "M4 : system/function shall [not] receive [<quantifi er>] item"),
("M5", "M5 : system/function shall [not] ingest flow"),
("M6", "M6 : system/function shall [not] emit flow"),
("M7", "M7 : system shall [not] perform function"),
("M8", "M8 : function shall [not] invoke function"),
("M9", "M9 : system shall [not] present interface [to system]"),
("M10", "M10 : system/interface shall [not] transfer flow/item"),
("M11", "M11 : system shall [not] interact with system [using <connection>] [as de ned in <text>]"),
("M12", "M12 : system shall [not] have state state [with values stateSet]"),
("M13", "M13 : system state stateValue shall [not] have substate state [with values stateSet]"),
("M14", "M14 : system item shall [not] take values from stateSet"),
("M15", "M15 : system item shall [not] be composed from item"),
("M16", "M16 : system shall [not] contain system")
)
def create_main(instance):
'''Create the Main Model for the Boilerplate'''
try :
main = Main.objects.get(boilerplate_of_main = instance, prefix_owner_of_main = instance.owner)
if instance.has_main:
return
main = Main.objects.get(boilerplate_of_main = instance, prefix_owner_of_main = instance.owner)
main.delete()
except Main.DoesNotExist:
if instance.has_main:
main = Main(boilerplate_of_main = instance, prefix_owner_of_main = instance.owner)
main.save()
class Main(models.Model):
boilerplate_of_main = models.ForeignKey('reqtool.Boilerplate', related_name='main', on_delete=models.CASCADE)
prefix_owner_of_main = models.ForeignKey(User, related_name='main_owner', on_delete=models.CASCADE)
main_choices = models.CharField(choices=MAIN_CHOICES, max_length=100)
def __init__(self, *args, **kwargs):
super(Main, self).__init__(*args, **kwargs)
self.__important_fields = ['main_choices']
for field in self.__important_fields:
setattr(self, '__original_%s' % field, getattr(self, field))
def save(self, **kwargs):
"""Create P1, P2 or P3 """
prev_main_list = []
super(Main, self).save(**kwargs)
for field in self.__important_fields:
orig = '__original_%s' % field
previous_main = getattr(self, orig)
prev_main_list.append(previous_main)
'''Create Main '''
#create_M1( self, self.simple_prefix_1, prev_prefix_list[0], '1')
class Meta:
ordering = ['prefix_owner_of_main']
\ No newline at end of file
from django.db import models
#from reqman.apps.common.models import CoreModel
from reqman.apps.account.models import User
from reqman.apps.reqtool.models.main_req import create_main
from pygments.formatters.html import HtmlFormatter
from pygments import highlight
SIMPLE_PREFIX_CHOICES = ( ("",""), ("P1", "If/Unless <logical expression>"), ("P2", "As soon as <occuring functionality>"), ("P3", "As long as <occuring functionality>"))
LOGIC_CONNECTIVE = ( ("",""), ("or","OR"), ("and", "AND"), ("xor", "XOR"))
LOGICAL_EXPRESSION = ( ("",""), ("state value constraint", "state value constraint"), ("occuring functionality", "occuring functionality"))
SIMPLE_PREFIX_CHOICES = ( ("",""),
("P1", "If/Unless <logical expression>"),
("P2", "As soon as <occuring functionality>"),
("P3", "As long as <occuring functionality>")
)
LOGIC_CONNECTIVE = ( ("",""),
("or","OR"),
("and", "AND"),
("xor", "XOR")
)
LOGICAL_EXPRESSION = ( ("",""),
("state value constraint", "state value constraint"),
("occuring functionality", "occuring functionality")
)
def create_prefix(instance):
'''Create the Prefix Model for the Boilerplate'''
......@@ -23,11 +37,6 @@ def create_prefix(instance):
prefix.save()
def create_main(instance):
'''Create the Main Model for the Boilerplate'''
pass
def create_suffix(instance):
'''Create the Suffix Model for the Boilerplate'''
pass
......@@ -126,6 +135,7 @@ class Boilerplate(models.Model):
"""Create prefix, main or suffix """
super(Boilerplate, self).save(**kwargs)
create_prefix(self)
create_main(self)
class Meta:
......
from django.db import models
#from reqman.apps.common.models import CoreModel
from reqman.apps.account.models import User
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles
from pygments.lexers import get_lexer_by_name
from pygments.formatters.html import HtmlFormatter
from pygments import highlight
LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted([(item, item) for item in get_all_styles()])
class Snippet(models.Model):
owner = models.ForeignKey(User, related_name='snippets', on_delete=models.CASCADE)
highlighted = models.TextField()
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
code = models.TextField()
linenos = models.BooleanField(default=False)
language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
def save(self, *args, **kwargs):
"""Use the `pygments` library to create a highlighted HTML
representation of the code snippet. """
lexer = get_lexer_by_name(self.language)
linenos = 'table' if self.linenos else False
options = {'title': self.title} if self.title else {}
formatter = HtmlFormatter(style=self.style, linenos=linenos,
full=True, **options)
self.highlighted = highlight(self.code, lexer, formatter)
super(Snippet, self).save(*args, **kwargs)
class Meta:
ordering = ['created']
\ No newline at end of file
from .snippets import SnippetSerializer
from .user import UserSerializer
from .requirements import PrefixSerializer
\ No newline at end of file
from .requirements import BoilerplateSerializer
\ No newline at end of file
from rest_framework import serializers
from reqman.apps.reqtool.models.main_req import Main
class MainSerializer(serializers.ModelSerializer):
boilerplate_of_main = serializers.PrimaryKeyRelatedField(read_only=True)
prefix_owner_of_main = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = Main
fields = ( 'id', 'prefix_owner_of_main', 'boilerplate_of_main', 'main_choices')
\ No newline at end of file
from rest_framework import serializers
from reqman.apps.reqtool.models import Snippet
class SnippetSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = Snippet
fields = ('id', 'owner', 'title', 'code', 'linenos', 'language', 'style')
\ No newline at end of file
from rest_framework import serializers
from reqman.apps.account.models import User
from reqman.apps.reqtool.models import Snippet
from reqman.apps.reqtool.models.requirements import Boilerplate
class UserSerializer(serializers.ModelSerializer):
snippets = serializers.PrimaryKeyRelatedField(many=True, queryset=Snippet.objects.all())
boilerplates = serializers.PrimaryKeyRelatedField(many=True, queryset=Boilerplate.objects.all())
class Meta:
model = User
fields = ['pk', 'first_name', 'last_name', 'email', 'snippets']
\ No newline at end of file
fields = ['pk', 'first_name', 'last_name', 'email', 'boilerplates']
\ No newline at end of file
from django.urls import path
from .views import user_views, snippet_views, requirements_views
from .views import user_views, requirements_views, main_req_views
urlpatterns = [
path('users/', user_views.UserList.as_view(), name='api-user-list'),
path('users/<uuid:pk>/', user_views.UserDetail.as_view(), name='api-post-details'),
#path('snippets/', snippet_views.SnippetListCreateAPIView.as_view(), name='api-snippet-list'),
#path('snippets/<int:pk>/', snippet_views.SnippetDetailsAPIView.as_view(), name='api-snippet-details'),
path('requirements/', requirements_views.BoilerplateListCreateAPIView.as_view(), name='api-requirements-list'),
path('requirements/<int:pk>/', requirements_views.BoilerplateDetailsAPIView.as_view(), name='api-requirements-details'),
#'''Prefix'''
path('requirements/<int:boilerplate>/prefix/', requirements_views.PrefixListCreateAPIView.as_view(), name='api-prefix-list'),
path('requirements/<int:boilerplate>/prefix/<int:pk>/', requirements_views.PrefixDetailsAPIView.as_view(), name='api-prefix-details'),
......@@ -27,4 +26,9 @@ urlpatterns = [
#'''Occuring functionality of P1'''
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/<int:log_expr>/functionality/', requirements_views.OccuringFunctionalityForLogicalExpressionListCreateAPIView.as_view(), name='api-functionality-for-log-list'),
path('requirements/<int:boilerplate>/prefix/<int:prefixs>/p1/<int:log_expr>/functionality/<int:pk>/', requirements_views.OccuringFunctionalityForLogicalExpressionDetailsAPIView.as_view(), name='api-functionality-for-log-list'),
#'''MAIN'''
path('requirements/<int:boilerplate>/main/', main_req_views.MainListCreateAPIView.as_view(), name='api-main-list'),
path('requirements/<int:boilerplate>/main/<int:pk>/', main_req_views.MainDetailsAPIView.as_view(), name='api-main-details'),
]
\ No newline at end of file
......@@ -5,42 +5,56 @@ 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 import Snippet
from reqman.apps.reqtool.rest_api.serializers import SnippetSerializer
from reqman.apps.reqtool.models.main_req import Main
from reqman.apps.reqtool.rest_api.serializers.main_req import MainSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.rest_api.services import fuseki
class SnippetListCreateAPIView(ListCreateAPIView):
class MainListCreateAPIView(ListCreateAPIView):
"""
API view to retrieve list of posts or create new
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = SnippetSerializer
queryset = Snippet.objects.all()
serializer_class = MainSerializer
#
queryset = Main.objects.all()
def get_queryset(self):
group_pk = self.kwargs['boilerplate']
#print(group_pk)
queryset_main = Main.objects.filter(boilerplate_of_main = group_pk)
return queryset_main
#Custom actions when POST
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
serializer.save()
#print the data of the post
write_fuseki = fuseki.FusekiActions()
write_fuseki.write(serializer.data)
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
class SnippetDetailsAPIView(RetrieveUpdateDestroyAPIView):
class MainDetailsAPIView(RetrieveUpdateDestroyAPIView):
"""
API view to retrieve, update or delete post
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly,
IsOwnerOrReadOnly]
serializer_class = SnippetSerializer
queryset = Snippet.objects.all()
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = MainSerializer
def get_queryset(self):
group_pk = self.kwargs['boilerplate']
#print(group_pk)
queryset_main= Main.objects.filter(boilerplate_of_main = group_pk)
return queryset_main
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.save()
write_fuseki = fuseki.FusekiActions()
write_fuseki.write(serializer.data)
serializer.save()
#print(self.new.changed_data)
#instance = serializer.save()
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
#Custom actions when DELETE
def perform_destroy(self, instance):
print("deleted")
#print("deleted")
instance.delete()
\ No newline at end of file
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