-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,320 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
branch = True | ||
source = | ||
config | ||
files | ||
pikau | ||
static | ||
templates | ||
|
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,3 +1,3 @@ | ||
"""Module for Django system configuration.""" | ||
|
||
__version__ = "0.3.0" | ||
__version__ = "0.4.0" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module for the files application.""" |
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,11 @@ | ||
"""Admin configuration for the files application.""" | ||
|
||
from django.contrib import admin | ||
from files.models import ( | ||
File, | ||
Licence, | ||
) | ||
|
||
|
||
admin.site.register(File) | ||
admin.site.register(Licence) |
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 @@ | ||
"""Application configuration for the files application.""" | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class FilesConfig(AppConfig): | ||
"""Configuration object for the files application.""" | ||
|
||
name = "files" |
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,6 @@ | ||
- name: "Unknown" | ||
url: "https://creativecommons.org/choose/" | ||
- name: "Creative Commons (BY-SA 4.0)" | ||
url: "https://creativecommons.org/licenses/by-sa/4.0/" | ||
- name: "Creative Commons (BY-NC-SA 4.0)" | ||
url: "https://creativecommons.org/licenses/by-nc-sa/4.0/" |
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,14 @@ | ||
"""Filters for the files application.""" | ||
|
||
import django_filters | ||
from files.models import File | ||
|
||
|
||
class FileFilter(django_filters.FilterSet): | ||
"""File filter for the files table.""" | ||
|
||
class Meta: | ||
"""Meta attributes for FileFilter class.""" | ||
|
||
model = File | ||
fields = ["licence"] |
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,37 @@ | ||
"""Forms for files application.""" | ||
|
||
from django.forms import ModelForm | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Layout, Submit, Field | ||
from files.models import ( | ||
File | ||
) | ||
|
||
|
||
class FileForm(ModelForm): | ||
"""Form for pages relating to actions of files.""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Set helper for form layout.""" | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper() | ||
self.helper.layout = Layout( | ||
Field("filename", css_class="slug-source"), | ||
"description", | ||
"location", | ||
"licence", | ||
Field("slug", css_class="slug-input"), | ||
Submit("submit", "Submit"), | ||
) | ||
|
||
class Meta: | ||
"""Meta attributes of GlossaryForm.""" | ||
|
||
model = File | ||
fields = ( | ||
"filename", | ||
"description", | ||
"location", | ||
"licence", | ||
"slug", | ||
) |
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 @@ | ||
"""Module for the management of the files application.""" |
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 @@ | ||
"""Custom loader for loading licences.""" | ||
|
||
from django.db import transaction | ||
from files.models import Licence | ||
from utils.BaseLoader import BaseLoader | ||
|
||
|
||
class LicenceLoader(BaseLoader): | ||
"""Custom loader for loading licences.""" | ||
|
||
@transaction.atomic | ||
def load(self): | ||
"""Load the licences into the database.""" | ||
licences = self.load_yaml_file("licences.yaml") | ||
|
||
for licence_data in licences: | ||
defaults = { | ||
"url": licence_data["url"], | ||
} | ||
licence, created = Licence.objects.update_or_create( | ||
name=licence_data["name"], | ||
defaults=defaults, | ||
) | ||
self.log_object_creation(created, licence) | ||
|
||
self.log("All licences loaded!\n") |
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 @@ | ||
"""Module for the custom commands for the files appliation.""" |
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,16 @@ | ||
"""Module for the custom Django loadlicences command.""" | ||
|
||
from django.conf import settings | ||
from django.core import management | ||
from files.management.commands._LicenceLoader import LicenceLoader | ||
|
||
|
||
class Command(management.base.BaseCommand): | ||
"""Required command class for the custom Django loadlicences command.""" | ||
|
||
help = "Loads licences into the website" | ||
|
||
def handle(self, *args, **options): | ||
"""Automatically called when the loadlicences command is given.""" | ||
base_path = settings.FILES_CONTENT_BASE_PATH | ||
LicenceLoader(base_path).load() |
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,42 @@ | ||
# Generated by Django 2.0.5 on 2018-05-21 04:19 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import files.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='File', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('slug', models.SlugField(unique=True)), | ||
('filename', models.CharField(max_length=200)), | ||
('description', models.TextField(blank=True)), | ||
('location', models.URLField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Licence', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=200, unique=True)), | ||
('url', models.URLField()), | ||
], | ||
options={ | ||
'ordering': ('name',), | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='file', | ||
name='licence', | ||
field=models.ForeignKey(default=files.models.default_licence, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='files', to='files.Licence'), | ||
), | ||
] |
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 @@ | ||
"""Migrations for the files application.""" |
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,86 @@ | ||
"""Models for the files application.""" | ||
|
||
from django.db import models | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.urls import reverse | ||
|
||
|
||
def default_licence(): | ||
"""Return default licence object. | ||
Returns: | ||
Licence 'Unknown' if available, otherwise None. | ||
""" | ||
try: | ||
default = Licence.objects.get(name="Unknown").pk | ||
except ObjectDoesNotExist: | ||
default = None | ||
return default | ||
|
||
|
||
class Licence(models.Model): | ||
"""Model for licence.""" | ||
|
||
name = models.CharField(max_length=200, unique=True) | ||
url = models.URLField() | ||
|
||
class Meta: | ||
"""Set consistent ordering of licences.""" | ||
|
||
ordering = ("name", ) | ||
|
||
def get_absolute_url(self): | ||
"""Return the URL for a licence. | ||
Returns: | ||
URL as string. | ||
""" | ||
return self.url | ||
|
||
def __str__(self): | ||
"""Text representation of Licence object. | ||
Returns: | ||
String describing licence. | ||
""" | ||
return self.name | ||
|
||
|
||
class File(models.Model): | ||
"""Model for file.""" | ||
|
||
slug = models.SlugField(unique=True) | ||
filename = models.CharField(max_length=200) | ||
description = models.TextField(blank=True) | ||
location = models.URLField() | ||
licence = models.ForeignKey( | ||
Licence, | ||
on_delete=models.CASCADE, | ||
related_name="files", | ||
default=default_licence, | ||
null=True, | ||
) | ||
|
||
def get_absolute_url(self): | ||
"""Return the URL for a file. | ||
Returns: | ||
URL as string. | ||
""" | ||
return reverse("files:file_detail", args=[self.slug]) | ||
|
||
def __str__(self): | ||
"""Text representation of File object. | ||
Returns: | ||
String describing file. | ||
""" | ||
return self.filename | ||
|
||
def __repr__(self): | ||
"""Text representation of File object for developers. | ||
Returns: | ||
String describing file. | ||
""" | ||
return "File: {}".format(self.slug) |
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 @@ | ||
"""Tables for the files application.""" | ||
|
||
import django_tables2 as tables | ||
from files.models import ( | ||
File, | ||
) | ||
|
||
|
||
class FileTable(tables.Table): | ||
"""Table to display all files.""" | ||
|
||
filename = tables.LinkColumn() | ||
licence = tables.RelatedLinkColumn() | ||
|
||
class Meta: | ||
"""Meta attributes for FileTable class.""" | ||
|
||
model = File | ||
fields = ("filename", "licence") | ||
order_by = "filename" |
Oops, something went wrong.