-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#288 feat: WIP - Update PDF upload and render logic
- Loading branch information
1 parent
2bd4102
commit e08a98b
Showing
22 changed files
with
901 additions
and
530 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
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,50 +1,56 @@ | ||
|
||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
from . import Experiment | ||
from .population import Population | ||
|
||
|
||
class PDFCategory(models.TextChoices): | ||
ELECTROPHYSIOLOGY = 'ELECTROPHYSIOLOGY' | ||
BEHAVIOUR = 'BEHAVIOUR' | ||
IO_MAPPING = 'IO_MAPPING' | ||
ELECTROPHYSIOLOGY = 'ELECTROPHYSIOLOGY' | ||
BEHAVIOUR = 'BEHAVIOUR' | ||
IO_MAPPING = 'IO_MAPPING' | ||
|
||
|
||
''' | ||
PopulationPDF associate to each population. | ||
Population can have multiple PDFs of any of following categories: | ||
- ELECTROPHYSIOLOGY, BEHAVIOUR, IO_MAPPING | ||
''' | ||
|
||
|
||
class Pdf(models.Model): | ||
name = models.CharField(max_length=100) | ||
category = models.CharField(max_length=40, choices=PDFCategory.choices) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
created_by = models.ForeignKey( | ||
User, | ||
related_name="pdf_created_by", | ||
on_delete=models.CASCADE, | ||
) | ||
User, | ||
related_name="pdf_created_by", | ||
on_delete=models.CASCADE, | ||
) | ||
file = models.FileField(null=True, blank=True, max_length=255) | ||
population = models.ForeignKey( | ||
Population, | ||
related_name="population_pdf", | ||
on_delete=models.CASCADE, | ||
) | ||
|
||
Population, | ||
related_name="population_pdf", | ||
on_delete=models.CASCADE, | ||
) | ||
experiment = models.ForeignKey( | ||
Experiment, | ||
on_delete=models.CASCADE, | ||
related_name="experiment_pdfs" | ||
) | ||
|
||
@staticmethod | ||
def has_read_permission(request): | ||
return True | ||
|
||
@staticmethod | ||
def has_list_permission(request): | ||
return True | ||
|
||
@staticmethod | ||
def has_destroy_permission(request): | ||
return True | ||
|
||
def has_object_write_permission(self, request): | ||
# return self.population.experiment and self.population.experiment.has_object_write_permission(request) | ||
def has_write_permission(request): | ||
return True | ||
|
||
def has_object_read_permission(self, request): | ||
if request.user == self.created_by: | ||
return True | ||
return not self.experiment.is_private | ||
|
||
def has_object_destroy_permission(self, request): | ||
return request.user == self.created_by |
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,20 +1,25 @@ | ||
from rest_framework import serializers | ||
from api.models import Pdf, PDFCategory | ||
import os | ||
|
||
from api.models import Pdf | ||
|
||
|
||
class PdfSerializer(serializers.ModelSerializer): | ||
created_by = serializers.SerializerMethodField() | ||
class Meta: | ||
model = Pdf | ||
fields = ( | ||
"id", | ||
"name", | ||
"category", | ||
"created_at", | ||
"created_by", | ||
"file" | ||
) | ||
created_by = serializers.SerializerMethodField() | ||
experiment = serializers.PrimaryKeyRelatedField(read_only=True) | ||
population = serializers.PrimaryKeyRelatedField(read_only=True) | ||
|
||
class Meta: | ||
model = Pdf | ||
fields = ( | ||
"id", | ||
"name", | ||
"category", | ||
"created_at", | ||
"created_by", | ||
"file", | ||
"experiment", | ||
"population", | ||
) | ||
|
||
def get_created_by(self, obj): | ||
return obj.created_by.first_name + " " + obj.created_by.last_name | ||
def get_created_by(self, obj): | ||
return obj.created_by.first_name + " " + obj.created_by.last_name |
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
Oops, something went wrong.