Skip to content
This repository has been archived by the owner on Mar 22, 2020. It is now read-only.

Commit

Permalink
pbp8
Browse files Browse the repository at this point in the history
  • Loading branch information
johncosta committed Sep 29, 2013
1 parent e444f21 commit 9f55a60
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 23 deletions.
10 changes: 7 additions & 3 deletions scorinator/project/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import json

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.text import slugify

from core.queue import enqueue_analytics, enqueue_score
import json


def set_slug(name):
# make sure there are no duplicate slugs
Expand Down Expand Up @@ -89,8 +92,9 @@ def rebuild_score(self):
def recalculate_score(self):
""" Queue up a recalculate request for this project """
from score.models import ProjectScoreAttribute
results = [{x.score_attribute.slug: x.result} for x in ProjectScoreAttribute.objects.filter(
project_score__project__pk=self.pk)]
results = [{x.score_attribute.slug: x.result} for x in
ProjectScoreAttribute.objects.filter(
project_score__project__pk=self.pk)]
data = {'project': self.dict_val, 'results': results}
return enqueue_score(json.dumps(data))

Expand Down
4 changes: 3 additions & 1 deletion scorinator/project/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from rest_framework import serializers

from .models import Project


class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
model = Project
4 changes: 2 additions & 2 deletions scorinator/project/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import patterns, url
from project.views import (ProjectListView, ProjectAddView, ProjectDetailView,
ProjectBuildView)
from project.views import (
ProjectListView, ProjectAddView, ProjectDetailView, ProjectBuildView)


urlpatterns = patterns(
Expand Down
1 change: 1 addition & 0 deletions scorinator/project/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .models import Project
from .serializers import ProjectSerializer


class ProjectViewSet(viewsets.ModelViewSet):

model = Project
Expand Down
2 changes: 2 additions & 0 deletions scorinator/score/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __repr__(self):
def __str__(self):
return "{0} {1}".format(self.project, self.total_score)


class ScoreAttribute(models.Model):
name = models.CharField(max_length=50)
description = models.TextField()
Expand All @@ -46,6 +47,7 @@ def __repr__(self):
def __str__(self):
return self.slug


class ProjectScoreAttributeManager(models.Manager):
def for_score(self, project_score_id):
return self.get_query_set().filter(project_score__pk=project_score_id)
Expand Down
5 changes: 4 additions & 1 deletion scorinator/score/serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from rest_framework import serializers
from .models import ProjectScore, ScoreAttribute, ProjectScoreAttribute


class ScoreAttributeSerializer(serializers.ModelSerializer):
class Meta:
model = ScoreAttribute


class ProjectScoreSerializer(serializers.ModelSerializer):
class Meta:
model = ProjectScore


class ProjectScoreAttributeSerializer(serializers.ModelSerializer):
class Meta:
model = ProjectScoreAttribute
model = ProjectScoreAttribute
13 changes: 7 additions & 6 deletions scorinator/score/templatetags/score_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def display_score(value):
title = "Poor"
if fvalue >= 80.0:
tag = "success"
title ="Excellent"
title = "Excellent"
elif fvalue >= 70.0:
tag = "info"
title = "Very Good"
Expand All @@ -28,8 +28,9 @@ def display_score(value):
value = "?"
title = "Calculating Score'"

return mark_safe("<span class='label label-{tag} score' data-toggle='tooltip' title='{title}'>{score}</span>".format(
score=value,
tag=tag,
title=title.capitalize())
)
return mark_safe(
"<span class='label label-{tag} score' data-toggle='tooltip' "
"title='{title}'>{score}</span>".format(
score=value,
tag=tag,
title=title.capitalize()))
9 changes: 5 additions & 4 deletions scorinator/score/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@


class ProjectScoreViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated,]
permission_classes = [permissions.IsAuthenticated, ]
model = ProjectScore
serializer_class = ProjectScoreSerializer


class ScoreAttributeViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated,]
permission_classes = [permissions.IsAuthenticated, ]
model = ScoreAttribute
serializer_class = ScoreAttributeSerializer


class ProjectScoreAttribute(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated,]
permission_classes = [permissions.IsAuthenticated, ]
model = ProjectScoreAttribute
serializer_class = ProjectScoreAttributeSerializer


class ScoreAttributeDetail(APIView):
"""
Retrieve, score attrribute instance.
Expand All @@ -40,4 +41,4 @@ def get_object(self, slug):
def get(self, request, slug, format=None):
score = self.get_object(slug)
serializer = ScoreAttributeSerializer(score)
return Response(serializer.data)
return Response(serializer.data)
13 changes: 7 additions & 6 deletions scorinator/scorinator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from core.views import HomeView
from project.viewsets import ProjectViewSet
from score.viewsets import (ProjectScoreViewSet, ScoreAttributeViewSet,
ProjectScoreAttribute, ScoreAttributeDetail)
from score.viewsets import (
ProjectScoreViewSet, ScoreAttributeViewSet, ProjectScoreAttribute,
ScoreAttributeDetail)


router = routers.DefaultRouter()
Expand All @@ -22,10 +23,10 @@
url(r'^$', HomeView.as_view(), name='home'),
url(r'^project/', include('project.urls')),

# TODO we may want to disable this later post development.
# for now, it's useful to understand what is available
#TODO: this is a little hack to get the query by slug, replace with better way later
url(r'^api/v1/score-attributes/(?P<slug>[\w-]+)/$', ScoreAttributeDetail.as_view()),
#TODO: this is a little hack to get the query by slug,
# replace with better way later
url(r'^api/v1/score-attributes/(?P<slug>[\w-]+)/$',
ScoreAttributeDetail.as_view()),
url(r'^api/v1/', include(router.urls)),
url(r'^__admin__/', include(admin.site.urls)),

Expand Down

0 comments on commit 9f55a60

Please sign in to comment.