Skip to content

Commit

Permalink
Allow user to edit scores for assigning badge in manage reputation
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitrp committed Mar 20, 2019
1 parent 7f6644c commit b01f770
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 69 deletions.
12 changes: 7 additions & 5 deletions Reputation/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ class Meta:
model = FlagReason
fields = ['id', 'reason']

class BadgeToUserSerializer(serializers.ModelSerializer):
class Meta:
model = BadgeToUser
fields = ['user', 'badge', 'community']

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']
65 changes: 55 additions & 10 deletions Reputation/meta_badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ACLevel1(MetaBadge):
progress_start = 0
progress_finish = badge_score.articles_contributed_level_1

def get_progress(self, user, community):
return CommunityArticles.objects.filter(user=user, community=community).count()

def get_user(self, instance):
return instance.user

Expand All @@ -41,6 +44,9 @@ class ACLevel2(MetaBadge):
progress_start = 0
progress_finish = badge_score.articles_contributed_level_2

def get_progress(self, user, community):
return CommunityArticles.objects.filter(user=user, community=community).count()

def get_user(self, instance):
return instance.user

Expand All @@ -64,6 +70,9 @@ class ACLevel3(MetaBadge):
progress_start = 0
progress_finish = badge_score.articles_contributed_level_3

def get_progress(self, user, community):
return CommunityArticles.objects.filter(user=user, community=community).count()

def get_user(self, instance):
return instance.user

Expand All @@ -87,6 +96,9 @@ class ACLevel4(MetaBadge):
progress_start = 0
progress_finish = badge_score.articles_contributed_level_4

def get_progress(self, user, community):
return CommunityArticles.objects.filter(user=user, community=community).count()

def get_user(self, instance):
return instance.user

Expand All @@ -110,6 +122,9 @@ class ACLevel5(MetaBadge):
progress_start = 0
progress_finish = badge_score.articles_contributed_level_5

def get_progress(self, user, community):
return CommunityArticles.objects.filter(user=user, community=community).count()

def get_user(self, instance):
return instance.user

Expand All @@ -133,6 +148,9 @@ class APLevel1(MetaBadge):
progress_start = 0
progress_finish = badge_score.my_articles_published_level_1

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_count

def get_user(self, instance):
return instance.user

Expand All @@ -156,6 +174,9 @@ class APLevel2(MetaBadge):
progress_start = 0
progress_finish = badge_score.my_articles_published_level_2

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_count

def get_user(self, instance):
return instance.user

Expand All @@ -179,6 +200,9 @@ class APLevel3(MetaBadge):
progress_start = 0
progress_finish = badge_score.my_articles_published_level_3

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_count

def get_user(self, instance):
return instance.user

Expand All @@ -202,6 +226,9 @@ class APLevel4(MetaBadge):
progress_start = 0
progress_finish = badge_score.my_articles_published_level_4

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_count

def get_user(self, instance):
return instance.user

Expand All @@ -225,6 +252,9 @@ class APLevel5(MetaBadge):
progress_start = 0
progress_finish = badge_score.my_articles_published_level_5

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_count

def get_user(self, instance):
return instance.user

Expand All @@ -246,7 +276,10 @@ class PALevel1(MetaBadge):
badge_score = BadgeScore.objects.get_or_create()[0]

progress_start = 0
progress_finish = badge_score.articles_published_be_me_level_1
progress_finish = badge_score.articles_published_by_me_level_1

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_by_me_count

def get_user(self, instance):
return instance.user
Expand All @@ -255,7 +288,7 @@ def get_community(self, instance):
return instance.community

def check_articles_published_by_me_count(self, instance):
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_be_me_level_1
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_by_me_level_1

class PALevel2(MetaBadge):
id = 'pa-level-2'
Expand All @@ -269,7 +302,10 @@ class PALevel2(MetaBadge):
badge_score = BadgeScore.objects.get_or_create()[0]

progress_start = 0
progress_finish = badge_score.articles_published_be_me_level_2
progress_finish = badge_score.articles_published_by_me_level_2

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_by_me_count

def get_user(self, instance):
return instance.user
Expand All @@ -278,7 +314,7 @@ def get_community(self, instance):
return instance.community

def check_articles_published_by_me_count(self, instance):
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_be_me_level_2
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_by_me_level_2

class PALevel3(MetaBadge):
id = 'pa-level-3'
Expand All @@ -292,7 +328,10 @@ class PALevel3(MetaBadge):
badge_score = BadgeScore.objects.get_or_create()[0]

progress_start = 0
progress_finish = badge_score.articles_published_be_me_level_3
progress_finish = badge_score.articles_published_by_me_level_3

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_by_me_count

def get_user(self, instance):
return instance.user
Expand All @@ -301,7 +340,7 @@ def get_community(self, instance):
return instance.community

def check_articles_published_by_me_count(self, instance):
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_be_me_level_3
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_by_me_level_3

class PALevel4(MetaBadge):
id = 'pa-level-4'
Expand All @@ -315,7 +354,10 @@ class PALevel4(MetaBadge):
badge_score = BadgeScore.objects.get_or_create()[0]

progress_start = 0
progress_finish = badge_score.articles_published_be_me_level_4
progress_finish = badge_score.articles_published_by_me_level_4

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_by_me_count

def get_user(self, instance):
return instance.user
Expand All @@ -324,7 +366,7 @@ def get_community(self, instance):
return instance.community

def check_articles_published_by_me_count(self, instance):
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_be_me_level_4
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_by_me_level_4

class PALevel5(MetaBadge):
id = 'pa-level-5'
Expand All @@ -338,7 +380,10 @@ class PALevel5(MetaBadge):
badge_score = BadgeScore.objects.get_or_create()[0]

progress_start = 0
progress_finish = badge_score.articles_published_be_me_level_5
progress_finish = badge_score.articles_published_by_me_level_5

def get_progress(self, user, community):
return CommunityReputaion.objects.get(user=user, community=community).published_by_me_count

def get_user(self, instance):
return instance.user
Expand All @@ -347,7 +392,7 @@ def get_community(self, instance):
return instance.community

def check_articles_published_by_me_count(self, instance):
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_be_me_level_5
return CommunityReputaion.objects.get(user=instance.user, community=instance.community).published_by_me_count > self.badge_score.articles_published_by_me_level_5


# class Publisher(MetaBadge):
Expand Down
40 changes: 40 additions & 0 deletions Reputation/migrations/0005_auto_20190318_1041.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-18 10:41
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('Reputation', '0004_communityreputaion_published_by_me_count'),
]

operations = [
migrations.RenameField(
model_name='badgescore',
old_name='articles_published_be_me_level_1',
new_name='articles_published_by_me_level_1',
),
migrations.RenameField(
model_name='badgescore',
old_name='articles_published_be_me_level_2',
new_name='articles_published_by_me_level_2',
),
migrations.RenameField(
model_name='badgescore',
old_name='articles_published_be_me_level_3',
new_name='articles_published_by_me_level_3',
),
migrations.RenameField(
model_name='badgescore',
old_name='articles_published_be_me_level_4',
new_name='articles_published_by_me_level_4',
),
migrations.RenameField(
model_name='badgescore',
old_name='articles_published_be_me_level_5',
new_name='articles_published_by_me_level_5',
),
]
10 changes: 5 additions & 5 deletions Reputation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class BadgeScore(models.Model):
articles_revised_by_me_level_3 = models.IntegerField(default=0)
articles_revised_by_me_level_4 = models.IntegerField(default=0)
articles_revised_by_me_level_5 = models.IntegerField(default=0)
articles_published_be_me_level_1 = models.IntegerField(default=0)
articles_published_be_me_level_2 = models.IntegerField(default=0)
articles_published_be_me_level_3 = models.IntegerField(default=0)
articles_published_be_me_level_4 = models.IntegerField(default=0)
articles_published_be_me_level_5 = models.IntegerField(default=0)
articles_published_by_me_level_1 = models.IntegerField(default=0)
articles_published_by_me_level_2 = models.IntegerField(default=0)
articles_published_by_me_level_3 = models.IntegerField(default=0)
articles_published_by_me_level_4 = models.IntegerField(default=0)
articles_published_by_me_level_5 = models.IntegerField(default=0)


#score needed to achieve badges
Expand Down
50 changes: 34 additions & 16 deletions Reputation/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render, redirect
from .models import ResourceScore, UserScore
from .models import ResourceScore, BadgeScore
# Create your views here.

def manage_reputation(request):
Expand All @@ -8,8 +8,7 @@ def manage_reputation(request):
scr=0
if ResourceScore.objects.filter(resource_type='resource').exists():
res = ResourceScore.objects.get(resource_type='resource')
if UserScore.objects.filter(role_score='role_score').exists():
scr = UserScore.objects.get(role_score='role_score')
scr = BadgeScore.objects.get_or_create()[0]
return render(request, 'manage_reputation.html', {'res':res, 'scr':scr})

return redirect('home')
Expand Down Expand Up @@ -49,20 +48,39 @@ def manage_resource_score(request):
def manage_user_role_score(request):
if request.user.is_superuser:
if request.method == 'POST':
pub_value = request.POST.get('pub_value')
author_value = request.POST.get('author_value')
if pub_value == '':
pub_value = 0
if author_value == '':
author_value = 0
# pub_value = request.POST.get('pub_value')
# author_value = request.POST.get('author_value')
# if pub_value == '':
# pub_value = 0
# if author_value == '':
# author_value = 0

if UserScore.objects.filter(role_score='role_score').exists():
scr = UserScore.objects.get(role_score='role_score')
scr.publisher = pub_value
scr.author = author_value
scr.save()
else:
UserScore.objects.create(publisher=pub_value, author=author_value)
scr = BadgeScore.objects.get_or_create()[0]
# scr.publisher = pub_value
# scr.author = author_value

scr.articles_contributed_level_1 = request.POST.get('ac_level1_val')
scr.articles_contributed_level_2 = request.POST.get('ac_level2_val')
scr.articles_contributed_level_3 = request.POST.get('ac_level3_val')
scr.articles_contributed_level_4 = request.POST.get('ac_level4_val')
scr.articles_contributed_level_5 = request.POST.get('ac_level5_val')
scr.my_articles_published_level_1 = request.POST.get('ap_level1_val')
scr.my_articles_published_level_2 = request.POST.get('ap_level2_val')
scr.my_articles_published_level_3 = request.POST.get('ap_level3_val')
scr.my_articles_published_level_4 = request.POST.get('ap_level4_val')
scr.my_articles_published_level_5 = request.POST.get('ap_level5_val')
scr.articles_revised_by_me_level_1 = request.POST.get('ra_level1_val')
scr.articles_revised_by_me_level_2 = request.POST.get('ra_level2_val')
scr.articles_revised_by_me_level_3 = request.POST.get('ra_level3_val')
scr.articles_revised_by_me_level_4 = request.POST.get('ra_level4_val')
scr.articles_revised_by_me_level_5 = request.POST.get('ra_level5_val')
scr.articles_published_by_me_level_1 = request.POST.get('pa_level1_val')
scr.articles_published_by_me_level_2 = request.POST.get('pa_level2_val')
scr.articles_published_by_me_level_3 = request.POST.get('pa_level3_val')
scr.articles_published_by_me_level_4 = request.POST.get('pa_level4_val')
scr.articles_published_by_me_level_5 = request.POST.get('pa_level5_val')

scr.save()
return redirect('manage_reputation')
else:
return redirect('manage_reputation')
Expand Down
5 changes: 1 addition & 4 deletions templates/badges_progress_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>Badge Progress</h1>
'border': '1px solid grey',
'margin': '5px',
'border-radius': '5px',
'padding': '5px'
'padding': '5px',
}
});

Expand All @@ -83,9 +83,6 @@ <h5 class="card-title">
rowDiv.append(colDiv);
}




badgeContainer.append(rowDiv);
}
}
Expand Down
Loading

0 comments on commit b01f770

Please sign in to comment.