Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMorganNZ committed May 22, 2018
2 parents db0da91 + f19087f commit c11a73f
Show file tree
Hide file tree
Showing 64 changed files with 1,320 additions and 104 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
branch = True
source =
config
files
pikau
static
templates
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.4.0 (Pre-release)

- Add files application for tracking files and their licences. (fixes #34)
- Display warning if any files have unknown licence. (fixes #36)
- Allow filtering of files by licence type.
- Allow users to add and update files.
- Allow users to add and update pīkau glossary entries.
- Begin process of replacing manual HTML tables with tables from django-tables2.
- Dependency updates:
- Add django-tables2 2.0.0a2.
- Add django-filter 1.1.0.
- Update django from 2.0.4 to 2.0.5.
- Update django-allauth from 0.35.0 to 0.36.0.
- Update django-anymail from 2.0 to 2.2.
- Update django-debug-toolbar from 1.8 to 1.9.1.
- Update psycopg2 from 2.7.3.1 to 2.7.4.
- Update gunicorn from 19.7.1 to 19.8.1.
- Update python-markdown-math from 0.3 to 0.5.

## 0.3.0 (Pre-release)

- Add milestone list and detail pages, with table showing milestone statuses. (fixes #9)
Expand Down
2 changes: 1 addition & 1 deletion config/__init__.py
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"
5 changes: 5 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
"django_tables2",
"django_filters",
]

# Apps specific for this project go here.
LOCAL_APPS = [
"pikau.apps.PikauConfig",
"files.apps.FilesConfig",
]

# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
Expand Down Expand Up @@ -218,5 +221,7 @@
# OTHER SETTINGS
# ------------------------------------------------------------------------------
PIKAU_CONTENT_BASE_PATH = os.path.join(BASE_DIR, "pikau/content")
FILES_CONTENT_BASE_PATH = os.path.join(BASE_DIR, "files/content")
CUSTOM_VERTO_TEMPLATES = os.path.join(BASE_DIR, "utils/custom_converter_templates/")
BREADCRUMBS_TEMPLATE = "django_bootstrap_breadcrumbs/bootstrap4.html"
DJANGO_TABLES2_TEMPLATE = "tables/table.html"
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
path("faq/", views.FAQView.as_view(), name="faq"),
path("contact/", views.ContactView.as_view(), name="contact"),
path("pikau/", include("pikau.urls")),
path("files/", include("files.urls")),
path("accounts/", include("allauth.urls")),
path("admin/", admin.site.urls),
]
Expand Down
1 change: 1 addition & 0 deletions files/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module for the files application."""
11 changes: 11 additions & 0 deletions files/admin.py
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)
9 changes: 9 additions & 0 deletions files/apps.py
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"
6 changes: 6 additions & 0 deletions files/content/licences.yaml
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/"
14 changes: 14 additions & 0 deletions files/filters.py
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"]
37 changes: 37 additions & 0 deletions files/forms.py
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",
)
1 change: 1 addition & 0 deletions files/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module for the management of the files application."""
26 changes: 26 additions & 0 deletions files/management/commands/_LicenceLoader.py
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")
1 change: 1 addition & 0 deletions files/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module for the custom commands for the files appliation."""
16 changes: 16 additions & 0 deletions files/management/commands/loadlicences.py
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()
42 changes: 42 additions & 0 deletions files/migrations/0001_initial.py
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'),
),
]
1 change: 1 addition & 0 deletions files/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Migrations for the files application."""
86 changes: 86 additions & 0 deletions files/models.py
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)
20 changes: 20 additions & 0 deletions files/tables.py
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"
Loading

0 comments on commit c11a73f

Please sign in to comment.