Skip to content

Commit

Permalink
Added term views, test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelliott committed Sep 23, 2013
1 parent 17d3a4d commit b36b511
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Production

### Deploy ###
* to update, simply `git pull` in the repository

* make sure to run `./manage.py syncdb` if any changes were made to database schemas
233 changes: 233 additions & 0 deletions fixtures/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
[
{
"pk": "eng",
"model": "lex.language",
"fields": {
"name": "English"
}
},
{
"pk": "spa",
"model": "lex.language",
"fields": {
"name": "Spanish"
}
},
{
"pk": 1,
"model": "lex.lexicalclass",
"fields": {
"name": "noun",
"language": "eng"
}
},
{
"pk": 2,
"model": "lex.lexicalclass",
"fields": {
"name": "noun",
"language": "spa"
}
},
{
"pk": 3,
"model": "lex.lexicalclass",
"fields": {
"name": "verb",
"language": "eng"
}
},
{
"pk": 1,
"model": "lex.representationtype",
"fields": {
"name": "written",
"language": "eng"
}
},
{
"pk": 2,
"model": "lex.representationtype",
"fields": {
"name": "written",
"language": "spa"
}
},
{
"pk": 1,
"model": "lex.enumeration",
"fields": {
"name": "number",
"language": "eng"
}
},
{
"pk": 2,
"model": "lex.enumeration",
"fields": {
"name": "number",
"language": "spa"
}
},
{
"pk": 3,
"model": "lex.enumeration",
"fields": {
"name": "gender",
"language": "spa"
}
},
{
"pk": 1,
"model": "lex.enumvalue",
"fields": {
"enum": 1,
"value": "sg"
}
},
{
"pk": 2,
"model": "lex.enumvalue",
"fields": {
"enum": 1,
"value": "pl"
}
},
{
"pk": 3,
"model": "lex.enumvalue",
"fields": {
"enum": 2,
"value": "sg"
}
},
{
"pk": 4,
"model": "lex.enumvalue",
"fields": {
"enum": 2,
"value": "pl"
}
},
{
"pk": 5,
"model": "lex.enumvalue",
"fields": {
"enum": 3,
"value": "masc"
}
},
{
"pk": 6,
"model": "lex.enumvalue",
"fields": {
"enum": 3,
"value": "fem"
}
},
{
"pk": 1,
"model": "lex.lexemeterm",
"fields": {
"usage": "",
"termNote": "",
"concept": 1,
"name": "steering_wheel",
"language": "eng"
}
},
{
"pk": 2,
"model": "lex.lexemeterm",
"fields": {
"usage": "",
"termNote": "",
"concept": 2,
"name": "tire",
"language": "eng"
}
},
{
"pk": 3,
"model": "lex.lexemeterm",
"fields": {
"usage": "",
"termNote": "",
"concept": 3,
"name": "wheel",
"language": "eng"
}
},
{
"pk": 1,
"model": "term.subjectfield",
"fields": {
"name": "general"
}
},
{
"pk": 2,
"model": "term.subjectfield",
"fields": {
"name": "automotive"
}
},
{
"pk": 1,
"model": "term.concept",
"fields": {
"subjectField": [
2
],
"name": "steering_wheel"
}
},
{
"pk": 2,
"model": "term.concept",
"fields": {
"subjectField": [
2
],
"name": "tire"
}
},
{
"pk": 3,
"model": "term.concept",
"fields": {
"subjectField": [
1,
2
],
"name": "wheel"
}
},
{
"pk": 1,
"model": "term.conceptdefinition",
"fields": {
"definition": "A car's steering wheel",
"concept": 1,
"language": "eng"
}
},
{
"pk": 2,
"model": "term.conceptdefinition",
"fields": {
"definition": "A car's tire",
"concept": 2,
"language": "eng"
}
},
{
"pk": 3,
"model": "term.conceptdefinition",
"fields": {
"definition": "A thin cylindrical object",
"concept": 3,
"language": "eng"
}
}
]
4 changes: 4 additions & 0 deletions lexTerm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
for logger in LOGGING['loggers']:
LOGGING['loggers'][logger]['handlers'] = ['console']

FIXTURE_DIRS = (
ROOT('fixtures'),
)

# Load separate settings file for development and production-specific settings
# Do not add local_settings.py to version control
try:
Expand Down
2 changes: 1 addition & 1 deletion term/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from term.models import *
from django.contrib import admin

admin.site.register(TermBase)
# admin.site.register(TermBase)
admin.site.register(SubjectField)
admin.site.register(Concept)
admin.site.register(ConceptDefinition)
Expand Down
15 changes: 15 additions & 0 deletions term/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework.filters import BaseFilterBackend

# We are doing filtering like this because it is based on multiple parameters from the urlconf

class SubjectFilter(BaseFilterBackend):
"""
Filters querysets based on subject, if present
"""
def filter_queryset(self, request, queryset, view):
if 'subject' in view.kwargs:
subj = view.kwargs['subject']
return queryset.filter(subject=subj)
else:
return queryset

14 changes: 7 additions & 7 deletions term/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.db import models
# from lex.models import Language, Lexeme

class TermBase(models.Model):
name = models.CharField(max_length=100)

def __unicode__(self):
return self.name
# class TermBase(models.Model):
# name = models.CharField(max_length=100)
#
# def __unicode__(self):
# return self.name

class SubjectField(models.Model):
name = models.CharField(max_length=100)
Expand All @@ -17,7 +17,7 @@ class Concept(models.Model):
name = models.CharField(max_length=100)
# termBase = models.ForeignKey(TermBase)
subjectField = models.ManyToManyField(SubjectField)
superOrdinate = models.ForeignKey('self', null=True, blank=True)
# superOrdinate = models.ForeignKey('self', null=True, blank=True)

def __unicode__(self):
return self.name
Expand All @@ -28,7 +28,7 @@ class ConceptDefinition(models.Model):
definition = models.TextField()

def __unicode__(self):
return "concept_definition:%s:%s" % (self.concept, self.language)
return "definition: %s: %s" % (self.concept, self.language)

# Try merging lexeme and term
# class Term(models.Model):
Expand Down
9 changes: 7 additions & 2 deletions term/serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from django.forms import widgets
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from term.models import *

# Serializers for termbase API

class SubjectSerializer(serializers.ModelSerializer):
class SubjectSerializer(ModelSerializer):
class Meta:
model = SubjectField
fields = ('name',)

class ConceptSerializer(ModelSerializer):
class Meta:
model = Concept
fields = ('name', 'subjectField')

# class LexemeSerializer(serializers.ModelSerializer):
#
# class Meta:
Expand Down
14 changes: 7 additions & 7 deletions term/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
detail_actions = {'get': 'retrieve', 'put': 'create', 'delete': 'destroy'}

urlpatterns = patterns('',
url(r'^subjects/$', SubjectView.as_view()),
url(r'^concepts/$', ConceptList.as_view()),
url(r'^concepts/(?P<id>\d+)/$', Concept.as_view()),
url(r'^lemmas/(?P<lemma>\w+)/$', Lemma.as_view()),
url(r'^subjects/(?P<subject>\w+)/concepts/$', ConceptList.as_view()),
url(r'^subjects/(?P<subject>\w+)/concepts/(?P<id>\d+)/$', Concept.as_view()),
url(r'^subjects/(?P<subject>\w+)/lemmas/(?P<lemma>\w+)/$', Lemma.as_view()),
url(r'^subjects/$', SubjectView.as_view(list_actions)),
url(r'^concepts/$', ConceptView.as_view(list_actions)),
url(r'^concepts/(?P<id>\d+)/$', ConceptView.as_view(detail_actions)),
url(r'^subjects/(?P<subject>\w+)/concepts/$', ConceptView.as_view(list_actions)),
url(r'^subjects/(?P<subject>\w+)/concepts/(?P<id>\d+)/$', ConceptView.as_view(detail_actions)),
# url(r'^lemmas/(?P<lemma>\w+)/$', Lemma.as_view()),
# url(r'^subjects/(?P<subject>\w+)/lemmas/(?P<lemma>\w+)/$', Lemma.as_view()),
)

20 changes: 9 additions & 11 deletions term/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from term.models import *
from term.serializers import *
from term.filters import *
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.generics import ListCreateAPIView
from rest_framework.viewsets import *

class SubjectView(ListCreateAPIView):
class TermAPIView(ModelViewSet):
filter_backends = (SubjectFilter,)

class SubjectView(TermAPIView):
model = SubjectField
serializer_class = SubjectSerializer
lookup_field = 'name'

class ConceptList(APIView):
def get(self, request, subject=None, format=None):
return Response(None)
class ConceptView(TermAPIView):
model = Concept
serializer_class = ConceptSerializer
lookup_field = 'name'

class Concept(APIView):
def get(self, request, id, subject=None, format=None):
return Response(None)

class Lemma(APIView):
def get(self, request, lemma, subject=None, format=None):
return Response(None)

0 comments on commit b36b511

Please sign in to comment.