Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tion-System into n-level
  • Loading branch information
Minali24 committed Mar 22, 2019
2 parents d100e35 + 67aa773 commit 1289074
Show file tree
Hide file tree
Showing 25 changed files with 1,027 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ src/
.DS_Store/
node_modules/
static/js/dist/
media/badge_images
2 changes: 1 addition & 1 deletion BasicArticle/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class ArticleSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Articles
fields = ('id','title', 'body')
fields = ('id','title', 'body', 'image', 'tags')
9 changes: 8 additions & 1 deletion CollaborationSystem/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())

BADGE_LEVEL_CHOICES = (
("1", "Grey"),
("2", "Red"),
("3", "Yellow"),
("4", "Blue"),
("5", "Green"),
)

# Application definition

Expand Down Expand Up @@ -284,7 +291,7 @@
),

'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
)
}

Expand Down
1 change: 1 addition & 0 deletions CollaborationSystem/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
url(r'^article-revision/(?P<pk>\d*)/$', articleview.SimpleModelHistoryCompareView.as_view(template_name='revision_article.html'), name='article_revision' ),

url(r'^mydashboard/$', user_views.user_dashboard, name='user_dashboard'),
url(r'^mydashboard/badges$', user_views.badges_progress_dashboard, name='badges_progress_dashboard'),
url(r'^community-group-create/(?P<pk>\d+)/$', communityview.CreateSubCommunityView.as_view(), name='community_group'),

url(r'^group-view/(?P<pk>\d+)/$', group_views.group_view, name='group_view'),
Expand Down
7 changes: 7 additions & 0 deletions Community/api/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import permissions
from Community.models import CommunityMembership, Community

class IsCommunityMember(permissions.BasePermission):

def has_permission(self, request, view):
return CommunityMembership.objects.filter(user=request.user, community=Community.objects.get(pk=view.kwargs['pk']))
3 changes: 2 additions & 1 deletion Community/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf.urls import url
from .views import CommunityListsApi, CommunityArticlesApi, CommunityMediaApi
from .views import CommunityListsApi, CommunityArticlesApi, CommunityMediaApi, CreateCommunityResource

urlpatterns = [
url(r'^list/$', CommunityListsApi.as_view(), name='community-list-api'),
url(r'^(?P<pk>\d*)/articles/$', CommunityArticlesApi.as_view(), name='community-articles-api'),
url(r'^(?P<pk>\d*)/media/(?P<type>[\w\-]+)/$', CommunityMediaApi.as_view(), name='community-media-api'),
url(r'^(?P<pk>\d*)/create/(?P<resource_type>[\w\-]+)/$', CreateCommunityResource.as_view(), name='community-resource-create')
]
27 changes: 25 additions & 2 deletions Community/api/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from Community.models import Community, CommunityArticles, CommunityMedia
from .serializers import CommunitySerializer, CommunityArticlesSerializer, CommunityMediaSerializer
from rest_framework import generics

from BasicArticle.serializers import ArticleSerializer
from BasicArticle.models import Articles
from Media.api.serializers import MediaCreateSerializer
from Media.models import Media
from rest_framework.permissions import IsAdminUser
from .permissions import IsCommunityMember
class CommunityListsApi(generics.ListAPIView):
queryset = Community.objects.all()
serializer_class = CommunitySerializer
Expand All @@ -17,4 +22,22 @@ class CommunityMediaApi(generics.ListAPIView):
serializer_class = CommunityMediaSerializer

def get_queryset(self):
return CommunityMedia.objects.filter(media__state__name='publish', media__mediatype=self.kwargs['type'], community = self.kwargs['pk'])
return CommunityMedia.objects.filter(media__state__name='publish', media__mediatype=self.kwargs['type'], community = self.kwargs['pk'])


class CreateCommunityResource(generics.CreateAPIView):
permission_classes = (IsAdminUser, IsCommunityMember,)

def get_serializer_class(self):
if self.kwargs['resource_type'] == 'article':
return ArticleSerializer
elif self.kwargs['resource_type'] == 'media':
return MediaCreateSerializer

def get_queryset(self):
if self.kwargs['resource_type'] == 'article':
return Article.objects.all()
elif self.kwargs['resource_type'] == 'media':
return Media.objects.all()


Empty file added Media/api/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions Media/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from Media.models import Media


class MediaCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Media
fields = ('mediatype', 'title', 'mediafile', 'medialink')
3 changes: 2 additions & 1 deletion Reputation/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.contrib import admin
from .models import ResourceScore, CommunityReputaion, FlagReason, ArticleFlagLogs, MediaFlagLogs
from .models import ResourceScore, CommunityReputaion, FlagReason, ArticleFlagLogs, MediaFlagLogs, BadgeScore
# Register your models here.

admin.site.register(ResourceScore)
admin.site.register(CommunityReputaion)
admin.site.register(FlagReason)
admin.site.register(ArticleFlagLogs)
admin.site.register(MediaFlagLogs)
admin.site.register(BadgeScore)
12 changes: 9 additions & 3 deletions Reputation/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers
from Reputation.models import CommunityReputaion, FlagReason
from Reputation.models import ArticleScoreLog, ArticleUserScoreLogs, MediaScoreLog, MediaUserScoreLogs
from badges.models import BadgeToUser
from badges.models import BadgeToUser, Badge

class CommunityReputaionSerializer(serializers.ModelSerializer):
class Meta:
Expand Down Expand Up @@ -61,8 +61,14 @@ class Meta:
model = FlagReason
fields = ['id', 'reason']

class BadgeSerializer(serializers.ModelSerializer):
class Meta:
model = Badge
fields = ['id', 'user', 'level', 'icon', 'title', 'description']

class BadgeToUserSerializer(serializers.ModelSerializer):
badge = BadgeSerializer(read_only=True)

class Meta:
model = BadgeToUser
fields = ['user', 'badge', 'community']

fields = ['user', 'badge', 'community']
4 changes: 3 additions & 1 deletion Reputation/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.conf.urls import url
from .views import ReputationStats, ReputationStatsDetails, FlagReasons, ResourceReports, ReputationScore
from .views import BadgesProgress

urlpatterns = [

url(r'^reputation_stats/$', ReputationStats.as_view()),
url(r'^reputation_stats/(?P<pk>[0-9]+)/$', ReputationStatsDetails.as_view()),
url(r'^flag_reasons/$', FlagReasons.as_view()),
url(r'^resource_reports/$', ResourceReports.as_view()),
url(r'^score/$', ReputationScore.as_view())
url(r'^score/$', ReputationScore.as_view()),
url(r'^badges/$', BadgesProgress.as_view()),
]
36 changes: 33 additions & 3 deletions Reputation/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from django.http import Http404
from django.db.models import F
import json
from badges.models import BadgeToUser
from .serializers import BadgeToUserSerializer
from badges.models import BadgeToUser, Badge
from .serializers import BadgeToUserSerializer, BadgeSerializer

class ReputationStats(generics.ListCreateAPIView):
permission_classes = (IsAuthenticated,)
Expand Down Expand Up @@ -228,6 +228,7 @@ def get(self, request):

return Response(response)

# for getting badges earned by user
class ReputationScore(APIView):
permission_classes = (IsAuthenticated,)

Expand All @@ -246,4 +247,33 @@ def get(self, request):

reputation_score.append(res)

return Response(reputation_score)
return Response(reputation_score)

# for getting progress of all badges of a user
class BadgesProgress(APIView):
permission_classes = (IsAuthenticated,)

def get(self, request):
badges_progress = []

badges = Badge.objects.all()

community_membership = CommunityMembership.objects.filter(user=request.user).order_by('community__name')

for comm in community_membership:
community_data = CommunityMembershipSerializer(comm).data
community_data['badges'] = []

community = comm.community

for badge in badges:
badge_serialized = BadgeSerializer(badge).data
badge_serialized['progress'] = badge.meta_badge.get_progress_percentage(user=request.user, community=community)
community_data['badges'].append(badge_serialized)

badges_progress.append(community_data)


return Response(badges_progress)


Loading

0 comments on commit 1289074

Please sign in to comment.