diff --git a/djangoldp_tzcld/djangoldp_urls.py b/djangoldp_tzcld/djangoldp_urls.py new file mode 100644 index 0000000000000000000000000000000000000000..ec50d60d357244209d87309da3873187fd035a01 --- /dev/null +++ b/djangoldp_tzcld/djangoldp_urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from .views import MyTerritoriesView, MemberOfCommunitiesView +from djangoldp_community.models import Community + +urlpatterns = [ + path('myterritories/', MyTerritoriesView.as_view({'get': 'list'}, model=Community), name='myterritories'), + path('memberofcommunities/', MemberOfCommunitiesView.as_view({'get': 'list'}, model=Community), name='memberofcommunities'), +] \ No newline at end of file diff --git a/djangoldp_tzcld/migrations/0047_auto_20230901_1744.py b/djangoldp_tzcld/migrations/0047_auto_20230901_1744.py new file mode 100644 index 0000000000000000000000000000000000000000..254243f2f3f9078cc5c82939ad1572c102d11188 --- /dev/null +++ b/djangoldp_tzcld/migrations/0047_auto_20230901_1744.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2023-09-01 15:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangoldp_tzcld', '0046_rename_tzcldterritoriestrainingpromotoion_tzcldterritoriestrainingpromotion_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='tzcldcommunityfollowedpointanswer', + name='answer', + field=models.TextField(default=False), + ), + ] diff --git a/djangoldp_tzcld/migrations/0048_auto_20230904_1421.py b/djangoldp_tzcld/migrations/0048_auto_20230904_1421.py new file mode 100644 index 0000000000000000000000000000000000000000..5cd3bcda61dba61eadf97cd154cd348ece5ba97b --- /dev/null +++ b/djangoldp_tzcld/migrations/0048_auto_20230904_1421.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2023-09-04 12:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangoldp_tzcld', '0047_auto_20230901_1744'), + ] + + operations = [ + migrations.AlterField( + model_name='tzcldcommunityfollowedpointanswer', + name='answer', + field=models.TextField(null=True), + ), + ] diff --git a/djangoldp_tzcld/migrations/0049_tzcldsharednote_date.py b/djangoldp_tzcld/migrations/0049_tzcldsharednote_date.py new file mode 100644 index 0000000000000000000000000000000000000000..74b942cf8b65c63f66e0eeb2165fb82e5a558774 --- /dev/null +++ b/djangoldp_tzcld/migrations/0049_tzcldsharednote_date.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2023-09-15 11:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangoldp_tzcld', '0048_auto_20230904_1421'), + ] + + operations = [ + migrations.AddField( + model_name='tzcldsharednote', + name='date', + field=models.DateField(auto_now=True, verbose_name='Date'), + ), + ] diff --git a/djangoldp_tzcld/models.py b/djangoldp_tzcld/models.py index 1cff1f7b5d823403d16030eac9e03fc994c3a184..54e3e80aa908a21be0a9d0068ce36728dc0650dc 100644 --- a/djangoldp_tzcld/models.py +++ b/djangoldp_tzcld/models.py @@ -54,7 +54,7 @@ class TzcldTerritoryRegion(Model): owner_perms = ['inherit', 'add', 'change', 'delete'] superuser_perms = ['inherit', 'change', 'delete'] container_path = "tzcld-regions/" - serializer_fields = ['@id', 'name'] + serializer_fields = ['@id', 'name', 'referents'] nested_fields = [] rdf_type = "tzcld:regions" @@ -323,7 +323,7 @@ class TzcldTerritoriesTrainingPromotion(Model): container_path = "tzcld-training-promotions/" serializer_fields = ['@id', 'name'] nested_fields = [] - rdf_type = "tzcld:territoryTrainingPromotoion" + rdf_type = "tzcld:territoryTrainingPromotion" class TzcldCommunity(Model): @@ -462,7 +462,7 @@ class TzcldTerritoryTraining(Model): owner_perms = ['inherit', 'change', 'delete'] superuser_perms = ['inherit'] container_path = "tzcld-territories-training/" - serializer_fields = ['@id', 'training_course', 'training_promotoion', 'training_person', 'community_identity'] + serializer_fields = ['@id', 'training_course', 'training_promotion', 'training_person', 'community_identity'] nested_fields = ['community_identity'] rdf_type = "tzcld:territoryTraining" @@ -704,6 +704,7 @@ class TzcldSharedNote(Model): choices=VISIBILITY_CHOICES, default=VISIBILITY_REFERENTS, ) + date = models.DateField(verbose_name="Date", auto_now=True) def __str__(self): try: @@ -712,6 +713,7 @@ class TzcldSharedNote(Model): return self.urlid class Meta(Model.Meta): + auto_author = 'user' verbose_name = _('TZCLD Shared Note') verbose_name_plural = _("TZCLD Shared Notes") anonymous_perms = [] @@ -719,7 +721,7 @@ class TzcldSharedNote(Model): owner_perms = ['inherit', 'change', 'delete'] superuser_perms = ['inherit'] container_path = "tzcld-shared-note/" - serializer_fields = ['@id', 'user', 'longdesc', 'community', 'visible', 'conversations'] + serializer_fields = ['@id', 'user', 'longdesc', 'community', 'visible', 'conversations', 'date'] nested_fields = ['community', 'conversations'] rdf_type = "tzcld:sharedNote" @@ -843,7 +845,7 @@ class TzcldCommunityFollowedPoint(Model): class TzcldCommunityFollowedPointAnswer(Model): - answer = models.BooleanField(default=False) + answer = models.TextField(blank=False, null=True) followed_point = models.ForeignKey(TzcldCommunityFollowedPoint, on_delete=models.DO_NOTHING,related_name='followed_point_answer', blank=False, null=True) community = models.ForeignKey(Community, on_delete=models.DO_NOTHING,related_name='tzcld_community_followed_answer', blank=False, null=True) @@ -895,6 +897,7 @@ class TzcldTerritorySharedFile(Model): return self.urlid class Meta(Model.Meta): + auto_author = 'author' verbose_name = _('TZCLD Territory Shared File') verbose_name_plural = _("TZCLD Territories Shared Files") anonymous_perms = [] @@ -968,8 +971,8 @@ def create_followed_point_answers(sender, instance, created, **kwargs): if created: communities = Community.objects.all() for community in communities: - # Create TzcldCommunityFollowedPointAsnwer - evaluation_point_answer = TzcldCommunityFollowedPointAnswer.objects.create( + # Create TzcldCommunityFollowedPointAnswer + followed_point_answer = TzcldCommunityFollowedPointAnswer.objects.create( community=community, followed_point=instance ) \ No newline at end of file diff --git a/djangoldp_tzcld/settings.py b/djangoldp_tzcld/settings.py index 196b80f469fa56efb1cf9c0f52170d69260097ea..f6f34b2b95826a5feb69798938baefb50ade5b0b 100644 --- a/djangoldp_tzcld/settings.py +++ b/djangoldp_tzcld/settings.py @@ -1,3 +1,3 @@ -COMMUNITY_NESTED_FIELDS = ['tzcld_profile', 'tzcld_profile_identity'] +COMMUNITY_NESTED_FIELDS = ['tzcld_profile', 'tzcld_profile_identity', 'tzcld_community_synthesis_followed', 'tzcld_community_shared_notes'] COMMUNITY_ADMIN_INLINES = [("djangoldp_tzcld.admin", "TzcldCommunityInline",)] USER_NESTED_FIELDS = ['tzcld_profile'] \ No newline at end of file diff --git a/djangoldp_tzcld/views.py b/djangoldp_tzcld/views.py new file mode 100644 index 0000000000000000000000000000000000000000..f6de4df2681d72527c95e8b2623cc91c1e2b9eee --- /dev/null +++ b/djangoldp_tzcld/views.py @@ -0,0 +1,17 @@ +from django.db.models import Q +from djangoldp.views import LDPViewSet +from djangoldp_community.models import Community + +class MyTerritoriesView(LDPViewSet): + model = Community + parent_model = Community + def get_queryset(self): + user = self.request.user + return super().get_queryset().filter(Q(tzcld_profile__regions__referents=user) | Q(members__in=user.communities.filter(is_admin=True))).distinct() + +class MemberOfCommunitiesView(LDPViewSet): + model = Community + parent_model = Community + def get_queryset(self): + user = self.request.user + return super().get_queryset().filter(Q(members__in=user.communities.filter(is_admin=True)) | Q(members__in=user.communities.filter(is_admin=False))).distinct() \ No newline at end of file