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

Local file storage #70

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ venv
.venv
media
staticfiles
documents
1 change: 1 addition & 0 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
"days",
"approved",
"file",
"local_file",
"reason",
),
"description": "%s" % REBATE_DESC_TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.8 on 2024-08-18 17:51
mittal-ishaan marked this conversation as resolved.
Show resolved Hide resolved

import cloudinary_storage.storage
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('home', '0002_remove_allocationautumn22_month_and_more'),
]

operations = [
migrations.AddField(
model_name='longrebate',
name='local_file',
field=models.FileField(blank=True, default=None, null=True, upload_to='documents/', verbose_name='Local File'),
),
migrations.AlterField(
model_name='longrebate',
name='file',
field=models.FileField(blank=True, default=None, null=True, storage=cloudinary_storage.storage.MediaCloudinaryStorage(), upload_to='documents/', verbose_name='File'),
),
]
7 changes: 6 additions & 1 deletion home/models/students.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext as _
from cloudinary_storage.storage import RawMediaCloudinaryStorage


class Student(models.Model):
Expand Down Expand Up @@ -174,10 +175,14 @@ class LongRebate(models.Model):
date_applied = models.DateField(
default=now, help_text="Date on which the rebate was applied"
)

## To delete this field when we no longer need old rebate data
file = models.FileField(
_("File"), upload_to="documents/", default=None, null=True, blank=True
_("File"), upload_to="documents/", default=None, null=True, blank=True, storage=RawMediaCloudinaryStorage()
)

local_file = models.FileField(_("Local File"), upload_to="documents/", default=None, null=True, blank=True)

def __str__(self):
return str(self.date_applied) + " " + str(self.email)

Expand Down
2 changes: 1 addition & 1 deletion home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def addLongRebateBill(request):
end_date=end_date,
days=days,
approved=False,
file=file,
local_file=file,
)
long.save()
text = "Long Term rebate added Successfully"
Expand Down
5 changes: 2 additions & 3 deletions messWebsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import environ

env = environ.Env()
environ.Env.read_env()
environ.Env.read_env(Path(__file__).resolve().parent.parent / '.env')
mittal-ishaan marked this conversation as resolved.
Show resolved Hide resolved

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -192,8 +192,7 @@
"API_SECRET": env("API_SECRET_CLOUD"),
}

DEFAULT_FILE_STORAGE = "cloudinary_storage.storage.RawMediaCloudinaryStorage"
DEFAULT_FILE_STORAGE = "cloudinary_storage.storage.MediaCloudinaryStorage"
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
MEDIA_URL = "/media/"


Expand Down
Loading