-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from matthiaskoenig/develop
PKDB-v0.2.5
- Loading branch information
Showing
49 changed files
with
3,149 additions
and
1,328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Definition of version string. | ||
""" | ||
__version__ = "0.2.0" | ||
__version__ = "0.2.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
from pkdb_app.interventions.models import Intervention, InterventionSet, Timecourse, OutputSet, Output | ||
from pkdb_app.interventions.models import InterventionEx, InterventionSet, TimecourseEx, OutputSet, OutputEx | ||
from pkdb_app.studies.models import Reference, Study | ||
from pkdb_app.subjects.models import Individual, IndividualSet, Characteristica, GroupSet, Group | ||
from pkdb_app.subjects.models import IndividualEx, IndividualSet, CharacteristicaEx, GroupSet, GroupEx | ||
from pkdb_app.users.models import User | ||
|
||
|
||
|
||
class Comment(models.Model): | ||
|
||
text = models.TextField(blank=True, null=True) | ||
user = models.ForeignKey(User, related_name="comments", on_delete=False) | ||
time = models.DateTimeField(auto_created=True) | ||
user = models.ForeignKey(User, related_name="comments", blank=True, null=True, on_delete = models.CASCADE) | ||
date_time = models.DateTimeField(auto_now_add=True, blank=True) | ||
#### | ||
|
||
individual = models.ForeignKey(Individual,related_name="comments",blank=True, null=True, on_delete=False) | ||
individualset = models.ForeignKey(IndividualSet,related_name="comments",blank=True, null=True, on_delete=False) | ||
group = models.ForeignKey(Group,related_name="comments", blank=True, null=True,on_delete=False) | ||
groupset = models.ForeignKey(GroupSet,related_name="comments",blank=True, null=True, on_delete=False) | ||
characteristica = models.ForeignKey(Characteristica,related_name="comments",blank=True, null=True, on_delete=False) | ||
individual_ex = models.ForeignKey(IndividualEx, related_name="comments", blank=True, null=True, on_delete=models.CASCADE) | ||
individualset = models.ForeignKey(IndividualSet,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
group_ex = models.ForeignKey(GroupEx,related_name="comments", blank=True, null=True,on_delete=models.CASCADE) | ||
groupset = models.ForeignKey(GroupSet,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
characteristica_ex = models.ForeignKey(CharacteristicaEx,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
|
||
|
||
output = models.ForeignKey(Output,related_name="comments",blank=True, null=True, on_delete=False) | ||
outputset = models.ForeignKey(OutputSet,related_name="comments",blank=True, null=True, on_delete=False) | ||
timecourse = models.ForeignKey(Timecourse,related_name="comments", blank=True, null=True,on_delete=False) | ||
output_ex = models.ForeignKey(OutputEx,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
outputset = models.ForeignKey(OutputSet,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
timecourse_ex = models.ForeignKey(TimecourseEx,related_name="comments", blank=True, null=True,on_delete=models.CASCADE) | ||
|
||
intervention = models.ForeignKey(Intervention,related_name="comments",blank=True, null=True, on_delete=False) | ||
interventionset = models.ForeignKey(InterventionSet,related_name="comments", blank=True, null=True,on_delete=False) | ||
intervention_ex = models.ForeignKey(InterventionEx,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
interventionset = models.ForeignKey(InterventionSet,related_name="comments", blank=True, null=True,on_delete=models.CASCADE) | ||
|
||
|
||
reference = models.ForeignKey(Reference,related_name="comments",blank=True, null=True, on_delete=False) | ||
study = models.ForeignKey(Study, related_name="comments",blank=True, null=True,on_delete=False) | ||
reference = models.ForeignKey(Reference,related_name="comments",blank=True, null=True, on_delete=models.CASCADE) | ||
study = models.ForeignKey(Study, related_name="comments",blank=True, null=True,on_delete=models.CASCADE) | ||
|
||
|
||
class Description(models.Model): | ||
text = models.TextField(blank=True, null=True) | ||
|
||
groupset = models.ForeignKey(GroupSet,related_name="descriptions",blank=True, null=True, on_delete=False) | ||
interventionset = models.ForeignKey(InterventionSet,related_name="descriptions", blank=True, null=True,on_delete=False) | ||
outputset = models.ForeignKey(OutputSet,related_name="descriptions",blank=True, null=True, on_delete=False) | ||
individualset = models.ForeignKey(IndividualSet,related_name="descriptions",blank=True, null=True, on_delete=False) | ||
groupset = models.ForeignKey(GroupSet,related_name="descriptions",blank=True, null=True, on_delete=models.CASCADE) | ||
interventionset = models.ForeignKey(InterventionSet,related_name="descriptions", blank=True, null=True,on_delete=models.CASCADE) | ||
outputset = models.ForeignKey(OutputSet,related_name="descriptions",blank=True, null=True, on_delete=models.CASCADE) | ||
individualset = models.ForeignKey(IndividualSet,related_name="descriptions",blank=True, null=True, on_delete=models.CASCADE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
from rest_framework import serializers | ||
|
||
from pkdb_app.comments.models import Description | ||
from pkdb_app.comments.models import Description, Comment | ||
from pkdb_app.serializers import WrongKeyValidationSerializer | ||
from pkdb_app.users.models import User | ||
|
||
|
||
class DescriptionsSerializer(serializers.ModelSerializer): | ||
class DescriptionSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
fields = ["text"] | ||
model = Description | ||
|
||
def to_internal_value(self, data): | ||
return {"text": data} | ||
return super().to_internal_value({"text": data}) | ||
|
||
def to_representation(self, instance): | ||
return instance.text | ||
|
||
class CommentSerializer(WrongKeyValidationSerializer): | ||
|
||
class Meta: | ||
fields = ["text","user"] | ||
model = Comment | ||
|
||
def _validate_comment(self, data): | ||
if not (isinstance(data, list) and len(data) == 2): | ||
raise serializers.ValidationError({"comments": "comment must be a list of the form ['username', 'comment']", "detail":{data}}) | ||
|
||
def to_internal_value(self, data): | ||
self._validate_comment(data) | ||
user = self.get_or_val_error(User, username=data[0]) | ||
return {"text": data[1],"user":user} | ||
|
||
def to_representation(self, instance): | ||
return [instance.user.username,instance.text] | ||
|
||
############################################################################################### | ||
# Read Serializer | ||
############################################################################################### | ||
class DescriptionReadSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
fields = ["pk","text"] | ||
model = Description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from rest_framework import viewsets, filters | ||
from rest_framework.permissions import AllowAny | ||
|
||
from pkdb_app.comments.models import Description | ||
from pkdb_app.comments.serializers import DescriptionReadSerializer | ||
|
||
|
||
class DescriptionReadViewSet(viewsets.ModelViewSet): | ||
|
||
queryset = Description.objects.all() | ||
serializer_class = DescriptionReadSerializer | ||
filter_backends = (filters.SearchFilter,) | ||
filter_fields = ('text',) | ||
search_fields = filter_fields | ||
permission_classes = (AllowAny,) |
Oops, something went wrong.