Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the app deployment ready #2

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SECRET_KEY=

DB_NAME=
DB_USER=
DB_PASSWORD=
Expand Down
4 changes: 2 additions & 2 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class QuestionPaper(models.Model):
month = models.CharField(max_length=20)
year = models.IntegerField()
file_id = models.CharField(max_length=255)
file_size = models.IntegerField(max_length=20)
file_size = models.IntegerField()
file_format = models.CharField(max_length=20)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
description = models.TextField(null=True, blank=True)
Expand All @@ -67,7 +67,7 @@ class Note(models.Model):
note_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=255)
file_id = models.CharField(max_length=255)
file_size = models.IntegerField(max_length=20)
file_size = models.IntegerField()
file_format = models.CharField(max_length=20)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
description = models.TextField(null=True, blank=True)
Expand Down
20 changes: 19 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import viewsets
from rest_framework import viewsets, status
from rest_framework.response import Response

from .models import (Branch, Note, QuestionPaper, Semester, SemesterGroup,
Subject, SubjectType)
Expand Down Expand Up @@ -28,6 +29,23 @@ class SubjectViewSet(viewsets.ModelViewSet):
queryset = Subject.objects.all()
serializer_class = SubjectSerializer

def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)

code = serializer.validated_data['code']
if Subject.objects.filter(code=code).first():
return Response({"detail": "Subject already exists."}, status=status.HTTP_400_BAD_REQUEST)

self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

def get_queryset(self):
if code := self.request.query_params.get('code'):
return Subject.objects.filter(code=code)
return Subject.objects.all()

class QuestionPaperViewSet(viewsets.ModelViewSet):
queryset = QuestionPaper.objects.all()
serializer_class = QuestionPaperSerializer
Expand Down
6 changes: 4 additions & 2 deletions prepportal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-*lau3ea78+)lm9ey#p#dpnih6_n67p*twei&$@vg34c3l*f4s9'
SECRET_KEY = os.environ.get("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*", "chrome-extension://amknoiejhlmhancpahfcfcfhllgkpbld"]
ALLOWED_HOSTS = ["*"]


# Application definition
Expand Down Expand Up @@ -130,6 +130,8 @@
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
Expand Down
11 changes: 11 additions & 0 deletions railway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ djangorestframework
psycopg2-binary
python-dotenv
django-cors-headers
django-debug-toolbar
django-debug-toolbar
gunicorn
Empty file added static/.gitkeep
Empty file.