Skip to content

Commit

Permalink
Adjusting default configuration for front-end local development (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9291 authored Mar 23, 2024
1 parent 73df6dd commit 9bd51cb
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"console": "integratedTerminal"
}
]
}
}
14 changes: 9 additions & 5 deletions canopeum_backend/canopeum_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ class Batchmulchlayer(models.Model):

class BatchSpecies(models.Model):
batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True)
quantity = models.IntegerField(blank=True, null=True)


class BatchSeed(models.Model):
batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True)
quantity = models.IntegerField(blank=True, null=True)


class BatchSupportedSpecies(models.Model):
batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True)
tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True)


class Comment(models.Model):
body = models.TextField(blank=True, null=True)
Expand Down Expand Up @@ -160,6 +163,7 @@ class Like(models.Model):
auth_user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING, blank=True, null=True)
post = models.ForeignKey(Post, models.DO_NOTHING, blank=True, null=True)


class Internationalization(models.Model):
en = models.TextField(db_column='EN', blank=True, null=True)
fr = models.TextField(db_column='FR', blank=True, null=True)
en = models.TextField(db_column="EN", blank=True, null=True)
fr = models.TextField(db_column="FR", blank=True, null=True)
158 changes: 117 additions & 41 deletions canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
from django.contrib.auth.models import User
from rest_framework import serializers
from .models import BatchSeed, BatchSpecies, BatchSupportedSpecies, Batchfertilizer, Contact, Coordinate, Internationalization, Mulchlayertype, Site, Post, Batch, Announcement, Like, Comment, Sitetreespecies, Sitetype, SitetypeInternationalization, Treetype, Widget

from .models import (
Announcement,
Batch,
Batchfertilizer,
BatchSeed,
BatchSpecies,
BatchSupportedSpecies,
Comment,
Contact,
Coordinate,
Internationalization,
Like,
Mulchlayertype,
Post,
Site,
Sitetreespecies,
Sitetype,
Treetype,
Widget,
)


class AuthUserSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -17,67 +38,77 @@ class Meta:
class CoordinatesSerializer(serializers.ModelSerializer):
class Meta:
model = Coordinate
fields = '__all__'
fields = "__all__"


class WidgetSerializer(serializers.ModelSerializer):
class Meta:
model = Widget
fields = '__all__'
fields = "__all__"


class InternationalizationSerializer(serializers.ModelSerializer):
class Meta:
model = Internationalization
fields = ('en', 'fr')
fields = ("en", "fr")


class SiteTypeSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = Sitetype
fields = ['id', 'en', 'fr']
fields = ["id", "en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.name).data.get('en', None)
return InternationalizationSerializer(obj.name).data.get("en", None)

Check failure on line 65 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 65 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

def get_fr(self, obj):
return InternationalizationSerializer(obj.name).data.get('fr', None)
return InternationalizationSerializer(obj.name).data.get("fr", None)

Check failure on line 68 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 68 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)


class TreeTypeSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = Treetype
fields = ['en', 'fr']
fields = ["en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.name).data.get('en', None)
return InternationalizationSerializer(obj.name).data.get("en", None)

Check failure on line 80 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 80 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

def get_fr(self, obj):
return InternationalizationSerializer(obj.name).data.get('fr', None)
return InternationalizationSerializer(obj.name).data.get("fr", None)

Check failure on line 83 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 83 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)


class AnnouncementSerializer(serializers.ModelSerializer):
class Meta:
model = Announcement
fields = '__all__'
fields = "__all__"


class ContactSerializer(serializers.ModelSerializer):
class Meta:
model = Contact
fields = '__all__'
fields = "__all__"


class SitetreespeciesSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = Sitetreespecies
fields = ('id', 'quantity', 'en', 'fr')
fields = ("id", "quantity", "en", "fr")

def get_en(self, obj):
return TreeTypeSerializer(obj.tree_type).data.get('en', None)
return TreeTypeSerializer(obj.tree_type).data.get("en", None)

Check failure on line 107 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 107 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

def get_fr(self, obj):
return TreeTypeSerializer(obj.tree_type).data.get('fr', None)
return TreeTypeSerializer(obj.tree_type).data.get("fr", None)

Check failure on line 110 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 110 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)


class SiteSerializer(serializers.ModelSerializer):
site_type = SiteTypeSerializer()
Expand All @@ -88,11 +119,12 @@ class SiteSerializer(serializers.ModelSerializer):

class Meta:
model = Site
fields = '__all__'
fields = "__all__"

def get_site_tree_species(self, obj):
return SitetreespeciesSerializer(obj.sitetreespecies_set.all(), many=True).data


class SiteSocialSerializer(serializers.ModelSerializer):
site_type = SiteTypeSerializer()
contact = ContactSerializer()
Expand All @@ -102,85 +134,96 @@ class SiteSocialSerializer(serializers.ModelSerializer):

class Meta:
model = Site
fields = ('name', 'site_type', 'image', 'description', 'contact', 'announcement', 'sponsors', 'widget')
fields = ("name", "site_type", "image", "description", "contact", "announcement", "sponsors", "widget")

def get_sponsors(self, obj):
return self.context.get("sponsors")

def get_widget(self, obj):
return WidgetSerializer(obj.widget_set.all(), many=True).data


class BatchfertilizerSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = Batchfertilizer
fields = ['id', 'en', 'fr']
fields = ["id", "en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.fertilizer_type).data.get('en', None)
return InternationalizationSerializer(obj.fertilizer_type).data.get("en", None)

Check failure on line 155 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 155 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

def get_fr(self, obj):
return InternationalizationSerializer(obj.fertilizer_type).data.get('fr', None)
return InternationalizationSerializer(obj.fertilizer_type).data.get("fr", None)

Check failure on line 158 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 158 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)


class BatchMulchLayerSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = Mulchlayertype
fields = ['id', 'en', 'fr']
fields = ["id", "en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.mulch_layer_type).data.get('en', None)
return InternationalizationSerializer(obj.mulch_layer_type).data.get("en", None)

Check failure on line 170 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 170 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

def get_fr(self, obj):
return InternationalizationSerializer(obj.mulch_layer_type).data.get('fr', None)
return InternationalizationSerializer(obj.mulch_layer_type).data.get("fr", None)

Check failure on line 173 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (ubuntu-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 173 in canopeum_backend/canopeum_backend/serializers.py

View workflow job for this annotation

GitHub Actions / pyright (windows-latest)

Cannot access member "get" for type "ReturnList"   Member "get" is unknown (reportAttributeAccessIssue)


class BatchSupportedSpeciesSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = BatchSupportedSpecies
fields = ['en', 'fr']
fields = ["en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('en', None)
return InternationalizationSerializer(obj.tree_type).data.get("en", None)

def get_fr(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('fr', None)
return InternationalizationSerializer(obj.tree_type).data.get("fr", None)


class BatchSeedSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = BatchSeed
fields = ['quantity', 'en', 'fr']
fields = ["quantity", "en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('en', None)
return InternationalizationSerializer(obj.tree_type).data.get("en", None)

def get_fr(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('fr', None)
return InternationalizationSerializer(obj.tree_type).data.get("fr", None)


class BatchSpeciesSerializer(serializers.ModelSerializer):
en = serializers.SerializerMethodField()
fr = serializers.SerializerMethodField()

class Meta:
model = BatchSpecies
fields = ['quantity', 'en', 'fr']
fields = ["quantity", "en", "fr"]

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('en', None)
return InternationalizationSerializer(obj.tree_type).data.get("en", None)

def get_fr(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get('fr', None)
return InternationalizationSerializer(obj.tree_type).data.get("fr", None)


class BatchSerializer(serializers.ModelSerializer):
class Meta:
model = Batch
fields = '__all__'
fields = "__all__"


class BatchAnalyticsSerializer(serializers.ModelSerializer):
fertilizers = serializers.SerializerMethodField()
mulch_layers = serializers.SerializerMethodField()
Expand All @@ -191,9 +234,24 @@ class BatchAnalyticsSerializer(serializers.ModelSerializer):
seed_collected_count = serializers.SerializerMethodField()
seeds = serializers.SerializerMethodField()
species = serializers.SerializerMethodField()

class Meta:
model = Batch
fields = ('id', 'name', 'size', 'soil_condition', 'fertilizers', 'mulch_layers', 'supported_species', 'plant_count', 'survived_count', 'replace_count', 'seed_collected_count', 'seeds', 'species')
fields = (
"id",
"name",
"size",
"soil_condition",
"fertilizers",
"mulch_layers",
"supported_species",
"plant_count",
"survived_count",
"replace_count",
"seed_collected_count",
"seeds",
"species",
)

def get_plant_count(self, obj):
return self.context.get("plant_count")
Expand Down Expand Up @@ -222,16 +280,27 @@ def get_seeds(self, obj):
def get_species(self, obj):
return BatchSpeciesSerializer(obj.batchspecies_set.all(), many=True).data


class SiteSummarySerializer(serializers.ModelSerializer):
site_type = SiteTypeSerializer()
plant_count = serializers.SerializerMethodField()
survived_count = serializers.SerializerMethodField()
propagation_count = serializers.SerializerMethodField()
progress = serializers.SerializerMethodField()
sponsor = serializers.SerializerMethodField()

class Meta:
model = Site
fields = ('name', 'site_type', 'plant_count', 'survived_count', 'propagation_count', 'visitor_count', 'sponsor', 'progress')
fields = (
"name",
"site_type",
"plant_count",
"survived_count",
"propagation_count",
"visitor_count",
"sponsor",
"progress",
)

def get_plant_count(self, obj):
return self.context.get("plant_count")
Expand All @@ -246,39 +315,46 @@ def get_progress(self, obj):
return self.context.get("progress")

def get_sponsor(self, obj):
return BatchSerializer(obj).data.get('sponsor', None)
return BatchSerializer(obj).data.get("sponsor", None)


class SiteMapSerializer(serializers.ModelSerializer):
site_type = SiteTypeSerializer()

class Meta:
model = Site
fields = ('id', 'name', 'site_type', 'coordinate', 'image')
fields = ("id", "name", "site_type", "coordinate", "image")


class SiteOverviewSerializer(serializers.ModelSerializer):
class Meta:
model = Site
fields = ('id', 'name')
fields = ("id", "name")


class PostSerializer(serializers.ModelSerializer):
site = SiteOverviewSerializer()
comment_count = serializers.SerializerMethodField()
has_liked = serializers.SerializerMethodField()

class Meta:
model = Post
fields = ('id', 'site', 'created_at', 'body', 'like_count', 'share_count', 'comment_count', 'has_liked')
fields = ("id", "site", "created_at", "body", "like_count", "share_count", "comment_count", "has_liked")

def get_comment_count(self, obj):
return self.context.get("comment_count")

def get_has_liked(self, obj):
return self.context.get("has_liked")


class CommentSerializer(serializers.ModelSerializer):
class Meta:
model = Comment
fields = ('id', 'body', 'auth_user', 'created_at')
fields = ("id", "body", "auth_user", "created_at")


class LikeSerializer(serializers.ModelSerializer):
class Meta:
model = Like
fields = '__all__'
fields = "__all__"
Loading

0 comments on commit 9bd51cb

Please sign in to comment.