-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add files app, add models, add view to serve files
- Loading branch information
Showing
12 changed files
with
93 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ build | |
.env | ||
.idea | ||
.env.example | ||
|
||
ENV | ||
.venv | ||
venv |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from ephios.plugins.files.models import Document | ||
|
||
admin.site.register(Document) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from ephios.core.plugins import PluginConfig | ||
|
||
|
||
class PluginApp(PluginConfig): | ||
name = "ephios.plugins.files" | ||
|
||
class EphiosPluginMeta: | ||
name = _("Files") | ||
author = "Ephios Team" | ||
description = _("This plugins allows you to upload files and link to them in events.") | ||
|
||
def ready(self): | ||
from . import signals # pylint: disable=unused-import |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.0.8 on 2024-09-21 12:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Document", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("title", models.CharField(max_length=255)), | ||
("file", models.FileField(upload_to="documents/")), | ||
], | ||
), | ||
] |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
|
||
|
||
class Document(models.Model): | ||
title = models.CharField(max_length=255) | ||
file = models.FileField(upload_to="documents/") | ||
|
||
def __str__(self): | ||
return self.title |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from ephios.plugins.files.views import DocumentView | ||
|
||
app_name = "files" | ||
urlpatterns = [ | ||
path("documents/<int:pk>/", DocumentView.as_view(), name="document"), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
|
||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.shortcuts import get_object_or_404 | ||
from django.views import View | ||
from guardian.mixins import LoginRequiredMixin | ||
|
||
from ephios.plugins.files.models import Document | ||
|
||
|
||
class DocumentView(View, LoginRequiredMixin): | ||
def get(self, request, *args, **kwargs): | ||
document = get_object_or_404(Document, id=kwargs["pk"]) | ||
response = HttpResponse() | ||
response["Content-Disposition"] = ( | ||
"attachment; filename=" + os.path.split(document.file.name)[1] | ||
) | ||
response["X-Accel-Redirect"] = settings.MEDIA_URL + document.file.name | ||
return response |
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