Skip to content

Commit

Permalink
Merge pull request #343 from MAKENTNU/dev
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
sigridge committed Mar 10, 2021
2 parents 2e50221 + 8cced3f commit dabc6e0
Show file tree
Hide file tree
Showing 275 changed files with 3,797 additions and 2,514 deletions.
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: ":arrow_up:"
include: "scope"

- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: ":construction_worker:"
include: "scope"
61 changes: 61 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "CodeQL"

on:
push:
branches: [ master, dev ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, dev ]
schedule:
# Runs at 03:45 UTC every day
- cron: '45 3 * * *'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'python', 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install System Dependencies
run: |
sudo apt update && sudo apt install python-dev libldap2-dev libsasl2-dev libssl-dev
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
local_settings_post.py
media/

# Flask stuff:
Expand Down
3 changes: 2 additions & 1 deletion announcements/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin

from announcements.models import Announcement
from web.multilingual.database import MultiLingualFieldAdmin
from web.multilingual.admin import MultiLingualFieldAdmin


admin.site.register(Announcement, MultiLingualFieldAdmin)
4 changes: 2 additions & 2 deletions announcements/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime
from django.db import migrations, models
import web.multilingual.database
import web.multilingual.modelfields


class Migration(migrations.Migration):
Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('classification', models.CharField(choices=[('I', 'Information'), ('W', 'Warning message'), ('E', 'Error message')], default='I', max_length=1, verbose_name='Type')),
('site_wide', models.BooleanField(verbose_name='Site-wide')),
('content', web.multilingual.database.MultiLingualTextField(max_length=256, verbose_name='Content')),
('content', web.multilingual.modelfields.MultiLingualTextField(max_length=256, verbose_name='Content')),
('link', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Link')),
('display_from', models.DateTimeField(default=datetime.datetime(2020, 3, 14, 13, 57, 40, 9695), verbose_name='Display from')),
('display_to', models.DateTimeField(blank=True, null=True, verbose_name='Display to')),
Expand Down
11 changes: 6 additions & 5 deletions announcements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from web.multilingual.database import MultiLingualTextField
from web.multilingual.modelfields import MultiLingualTextField


class AnnouncementManager(models.Manager):
Expand All @@ -27,27 +27,28 @@ class Announcement(models.Model):
Model for general announcements. All announcements are time-based, but can be shown for an indefinite time period if
there is no end time given. An announcement may also link to another page with more information.
"""
objects = AnnouncementManager()

class AnnouncementType(models.TextChoices):
INFO = "I", _("Information")
WARNING = "W", _("Warning")
CRITICAL = "C", _("Critical")

classification = models.CharField(max_length=1, choices=AnnouncementType.choices, default=AnnouncementType.INFO,
classification = models.CharField(choices=AnnouncementType.choices, max_length=1, default=AnnouncementType.INFO,
verbose_name=_("Type"))
site_wide = models.BooleanField(verbose_name=_("Site-wide"),
help_text=_("If selected, the announcement will be shown on all pages, otherwise it"
" is only shown on the front page."))
content = MultiLingualTextField(max_length=256, verbose_name=_("Content"))
link = models.CharField(max_length=2048, verbose_name=_("Link"), blank=True, null=True,
link = models.CharField(max_length=2048, null=True, blank=True, verbose_name=_("Link"),
help_text=_("An optional link to an information page."))
display_from = models.DateTimeField(default=timezone.localtime, verbose_name=_("Display from"),
help_text=_("The date from which the announcement will be shown."))
display_to = models.DateTimeField(blank=True, null=True, verbose_name=_("Display to"),
display_to = models.DateTimeField(null=True, blank=True, verbose_name=_("Display to"),
help_text=_("The announcement will be shown until this date. If none is given, it"
" is shown indefinitely."))

objects = AnnouncementManager()

def __str__(self):
return f"{self.get_classification_display()}: {self.content}"

Expand Down
3 changes: 2 additions & 1 deletion announcements/templates/announcements/announcement.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% load announcement_tags %}


<div class="{% announcement_css_class announcement %} announcement">
{% if announcement.link %}
<a href="{{ announcement.link }}">
<a href="{{ announcement.link }}" target="_blank">
{{ announcement.content }}
</a>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "web/base.html" %}
{% load i18n %}


{% block body %}
<div class="ui container">
<h1>
Expand All @@ -19,7 +20,7 @@ <h1>
{{ announcement.get_classification_display }}
{% if perms.announcements.change_announcement %}
<a href="{% url "edit_announcement" pk=announcement.pk %}">
<i class="yellow pencil icon"></i>
<i class="make-col-yellow pencil icon"></i>
</a>
{% endif %}
{% if perms.announcements.delete_announcement %}
Expand All @@ -30,9 +31,9 @@ <h1>
</div>
<div class="meta">
{% if announcement.site_wide %}
<i class="ui yellow globe icon"></i>{% trans "Site-wide" %}
<i class="ui make-col-yellow globe icon"></i>{% trans "Site-wide" %}
{% else %}
<i class="ui yellow home icon"></i>{% trans "Front page" %}
<i class="ui make-col-yellow home icon"></i>{% trans "Front page" %}
{% endif %}
</div>
<div class="description">{{ announcement.content }}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "web/base.html" %}
{% load i18n %}


{% block body %}
<div class="ui container">
<h1>{% block header_text %}{% trans "New Announcement" %}{% endblock %}</h1>
Expand All @@ -14,7 +15,7 @@ <h1>{% block header_text %}{% trans "New Announcement" %}{% endblock %}</h1>
<div class="ui field">
<label>{{ form.link.label }}
<span data-content="{{ form.link.help_text }}">
<i class="ui yellow question circle icon"></i>
<i class="ui make-col-yellow question circle icon"></i>
</span>
</label>
{{ form.link }}
Expand All @@ -24,15 +25,15 @@ <h1>{% block header_text %}{% trans "New Announcement" %}{% endblock %}</h1>
<div class="ui field">
<label>{{ form.display_from.label }}
<span data-content="{{ form.display_from.help_text }}">
<i class="ui yellow question circle icon"></i>
<i class="ui make-col-yellow question circle icon"></i>
</span>
</label>
{{ form.display_from }}
</div>
<div class="ui field">
<label>{{ form.display_to.label }}
<span data-content="{{ form.display_to.help_text }}">
<i class="ui yellow question circle icon"></i>
<i class="ui make-col-yellow question circle icon"></i>
</span>
</label>
{{ form.display_to }}
Expand All @@ -45,12 +46,12 @@ <h1>{% block header_text %}{% trans "New Announcement" %}{% endblock %}</h1>
<div class="ui field">
<label>{{ form.site_wide.label }}
<span data-content="{{ form.site_wide.help_text }}">
<i class="ui yellow question circle icon"></i>
<i class="ui make-col-yellow question circle icon"></i>
</span>
</label>
{{ form.site_wide }}
</div>
<button class="ui right floated yellow button">
<button class="ui right floated make-bg-yellow button">
{% trans "Save" %}
</button>
<a class="ui right floated red button" href="{% url "announcement_admin" %}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "announcements/create_announcement.html" %}
{% extends "announcements/announcement_create.html" %}
{% load i18n %}


{% block header_text %}
{% trans "Edit Announcement" %}
{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions announcements/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from announcements.views import AnnouncementAdminView, CreateAnnouncementView, EditAnnouncementView, \
DeleteAnnouncementView


urlpatterns = [
path('admin/', AnnouncementAdminView.as_view(), name="announcement_admin"),
path('create/', CreateAnnouncementView.as_view(), name="create_announcement"),
Expand Down
22 changes: 7 additions & 15 deletions announcements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,29 @@


class AnnouncementAdminView(PermissionRequiredMixin, ListView):
permission_required = ("announcements.change_announcement",)
model = Announcement
template_name = "announcements/announcements_admin.html"
template_name = "announcements/announcement_admin.html"
context_object_name = "announcements"
permission_required = (
"announcements.change_announcement",
)


class CreateAnnouncementView(PermissionRequiredMixin, CreateView):
permission_required = ("announcements.add_announcement",)
model = Announcement,
template_name = "announcements/create_announcement.html"
form_class = AnnouncementForm
permission_required = (
"announcements.add_announcement",
)
template_name = "announcements/announcement_create.html"
success_url = reverse_lazy("announcement_admin")


class EditAnnouncementView(PermissionRequiredMixin, UpdateView):
permission_required = ("announcements.change_announcement",)
model = Announcement
template_name = "announcements/edit_announcement.html"
form_class = AnnouncementForm
permission_required = (
"announcements.change_announcement",
)
template_name = "announcements/announcement_edit.html"
success_url = reverse_lazy("announcement_admin")


class DeleteAnnouncementView(PermissionRequiredMixin, DeleteView):
permission_required = ("announcements.delete_announcement",)
model = Announcement
permission_required = (
"announcements.delete_announcement",
)
success_url = reverse_lazy("announcement_admin")
14 changes: 5 additions & 9 deletions card/forms.py → card/formfields.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import re

from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.forms import CharField
from django.utils.translation import gettext_lazy as _

from card.widgets import CardNumberInput
from .validators import card_number_validator
from .widgets import CardNumberInput

card_number_validators = (
RegexValidator(r"^\d{10}$", _("Card number must be ten digits long.")),
)


class CardNumberField(CharField):
class CardNumberField(forms.CharField):
"""
Custom form field for card numbers
"""
widget = CardNumberInput
default_validators = card_number_validators
default_validators = [card_number_validator]

def __init__(self, **kwargs):
super().__init__(**{
Expand Down
11 changes: 7 additions & 4 deletions card/models.py → card/modelfields.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

import card.forms
from .validators import card_number_validator


class CardNumberField(models.CharField):
"""
Custom field for card numbers, doing some extra validation
"""
default_validators = [card_number_validator]

def __init__(self, **kwargs):
kwargs = {
"verbose_name": _("Card number"),
**kwargs,
"validators": card.forms.card_number_validators,
"validators": self.default_validators,
"max_length": 10,
"error_messages": {
"unique": _("Card number already in use"),
},
**kwargs,
}
super().__init__(**kwargs) # No card numbers are more than ten digits long

def formfield(self, **kwargs):
from . import formfields # avoids circular imports

if "form_class" not in kwargs:
kwargs["form_class"] = card.forms.CardNumberField
kwargs["form_class"] = formfields.CardNumberField
return super().formfield(**kwargs)

def get_prep_value(self, value):
Expand Down
1 change: 1 addition & 0 deletions card/templates/card/widgets/card_number_input.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load i18n %}


<div class="ui right labeled input">
<div class="ui label">EM</div>
{% include "django/forms/widgets/text.html" %}
Expand Down
2 changes: 1 addition & 1 deletion card/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase

from card.models import CardNumberField, CardNumber
from card.modelfields import CardNumberField, CardNumber


class CardNumberModelFieldTest(TestCase):
Expand Down
Loading

0 comments on commit dabc6e0

Please sign in to comment.