diff --git a/blocks/blocks/xcosblocks/models.py b/blocks/blocks/xcosblocks/models.py index a8d19dd2..d9e336b1 100644 --- a/blocks/blocks/xcosblocks/models.py +++ b/blocks/blocks/xcosblocks/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.core.validators import MaxValueValidator, MinValueValidator class BlockType(models.Model): @@ -488,3 +489,51 @@ class Meta: models.UniqueConstraint(fields=['block', 'port_order'], name='unique_block_port_order') ] + + +class BlockTemp(models.Model): + id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100) + blockprefix = models.ForeignKey(BlockPrefix, default=1, + on_delete=models.PROTECT, related_name='+') + main_category = models.ForeignKey(Category, null=True, + on_delete=models.PROTECT, related_name='+') + categories = models.ManyToManyField(Category) + block_name = models.CharField(max_length=200, + unique=True, null=True) + initial_display_parameter = models.CharField(max_length=100, + blank=True, null=True) + simulation_function = models.CharField(max_length=100, + blank=True, null=True) + block_image_path = models.CharField(max_length=100, + blank=True, null=True) + block_width = models.IntegerField(default=40) + block_height = models.IntegerField(default=40) + + def __str__(self): + """String for representing the Model object.""" + return self.name + + class Meta: + constraints = [ + models.UniqueConstraint(fields=['main_category', 'name'], + name='unique_category_name') + ] + +class CommonBlockParameterTemp(models.Model): + block_param_id = models.IntegerField(validators=[MinValueValidator(0),MaxValueValidator(60)]) # 0 to 60 + label = models.CharField(max_length=100, blank=True, null=True) #p000 + type = models.ForeignKey(ParameterDataType, on_delete=models.PROTECT, + related_name='+', blank=True, null=True) #p000_type + help = models.CharField(max_length=100, blank=True, null=True) #p000_help + block = models.ForeignKey(BlockTemp, on_delete=models.CASCADE, related_name='+', blank=True, null=True) #p000_block + value = models.CharField(max_length=100, blank=True, null=True) #p000_value_initial + def __str__(self): + """String for representing the Model object.""" + return self.name + + class Meta: + constraints = [ + models.UniqueConstraint(fields=['block_id', 'block'], + name='unique_block_parameter_name') + ] diff --git a/blocks/blocks/xcosblocks/serializers.py b/blocks/blocks/xcosblocks/serializers.py index 6ee0d4ad..2445dc56 100644 --- a/blocks/blocks/xcosblocks/serializers.py +++ b/blocks/blocks/xcosblocks/serializers.py @@ -3,6 +3,7 @@ from .models import BlockType, Category, ParameterDataType, BlockPrefix, \ BlockPrefixParameter, Block, BlockParameter, BlockPort +from .models import CommonBlockParameterTemp, BlockTemp from .xcosblocks import * @@ -465,3 +466,19 @@ class SetBlockPortSerializer(serializers.Serializer): simulation_function = serializers.CharField( max_length=100, allow_blank=True, trim_whitespace=True) ports = serializers.StringRelatedField(many=True) + + +class CommonBlockParameterTemp(serializers.ModelSerializer): + class Meta: + model = CommonBlockParameterTemp + fields = [ 'id', 'label', 'type', 'help','value', 'block', 'block_param_id'] + +class BlockTemp(serializers.ModelSerializer): + blockprefix = BlockPrefixSerializer() + main_category = CategorySerializer() + categories = CategorySerializer(many=True) + blockport_set = BlockPortSerializer(many=True) + class Meta: + model = BlockTemp + fields = [ 'id','name', 'blockprefix', 'main_category', 'categories', 'block_name', 'initial_display_parameter', + 'simulation_function', 'block_image_path', 'block_width', 'block_height']