Skip to content

Commit

Permalink
Merge pull request #183 from ankitamk14/refactor
Browse files Browse the repository at this point in the history
refactored snippets
  • Loading branch information
sunilshetye authored Mar 5, 2024
2 parents e9547fb + 0c65a5b commit a73be37
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
49 changes: 49 additions & 0 deletions blocks/blocks/xcosblocks/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator


class BlockType(models.Model):
Expand Down Expand Up @@ -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')
]
17 changes: 17 additions & 0 deletions blocks/blocks/xcosblocks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .models import BlockType, Category, ParameterDataType, BlockPrefix, \
BlockPrefixParameter, Block, BlockParameter, BlockPort

from .models import CommonBlockParameterTemp, BlockTemp
from .xcosblocks import *


Expand Down Expand Up @@ -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']

0 comments on commit a73be37

Please sign in to comment.