Skip to content

Commit

Permalink
Merge branch 'main' into dockerize
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonsaraiva authored Jan 26, 2023
2 parents f1542ee + 7f292fc commit f46d1ce
Show file tree
Hide file tree
Showing 201 changed files with 5,448 additions and 4,698 deletions.
5 changes: 3 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Explanation
# E722 - do not use bare 'except'
# F841 - local variable is assigned to but never used # TODO - address these
# W503 - line break before binary operator # Black adds this line break

ignore = E722, F841
ignore = E722, F841, W503
exclude =
.env,
.git,
Expand All @@ -12,4 +13,4 @@ exclude =
.venv,
__pycache__,
**/migrations/**
max-line-length = 119
max-line-length = 120
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ jobs:
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
PYTHON: '3.9'
PYTHON: '3.10'

strategy:
max-parallel: 4
matrix:
python-version:
- 3.9
- '3.10'

services:
postgres:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
max-parallel: 4
matrix:
python-version:
- 3.9
- '3.10'

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/slack-notify.yml

This file was deleted.

42 changes: 40 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
ci:
autofix_commit_msg: |
ci: auto fixes from pre-commit hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_commit_msg: 'ci: pre-commit autoupdate'
autoupdate_schedule: monthly

fail_fast: true

repos:
- repo: https://github.com/PyCQA/flake8
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
hooks:
- id: autoflake
entry: bash -c 'autoflake "$@"; git add -u;' --
language: python
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variables",
"--expand-star-imports",
"--ignore-init-module-imports",
]
files: \.py$
- repo: https://github.com/pycqa/isort
rev: 5.11.4
hooks:
- id: isort
name: isort
entry: bash -c 'isort "$@"; git add -u;' --
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
entry: bash -c 'black "$@"; git add -u;' --
language_version: python3.10
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- id: flake8
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ If you have Docker and Docker compose installed, run `docker-compose up`

### Non Docker

Create a new virtual environment (python 3.9) if needed. Then, install all the required dependencies.
Create a new virtual environment (Python 3.10) if needed. Then, install all the required dependencies.

The dependencies are compiled by [pip-tools](https://github.com/jazzband/pip-tools), which
compiles `requirements.txt` ensuring compatibility between packages.

Expand All @@ -89,7 +90,13 @@ pip install pip-tools
pip-sync
```

There is more information on how `pip-tools` work below.
> There is more information on how `pip-tools` work below in [Using pip-tools](#using-pip-tools).
Install the [pre-commit](https://github.com/pre-commit/pre-commit) hook. It's useful so we automatically format and lint code before committing any changes.

```bash
pre-commit install
```

Start the [PostgreSQL database server](http://www.postgresql.org/docs/current/static/server-start.html) and enter the `psql` shell (you need to have [PostgreSQL](http://www.postgresql.org/download/) installed):

Expand Down
38 changes: 17 additions & 21 deletions applications/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from adminsortable2.admin import SortableAdminMixin
from django.contrib import admin
from django.shortcuts import redirect, render
from django.urls import reverse, path
from django.urls import path, reverse
from django.utils.html import format_html

from core.models import Event
Expand All @@ -10,11 +10,7 @@


class FormAdmin(admin.ModelAdmin):
list_display = (
'text_header', 'event',
'open_from', 'open_until', 'number_of_applications',
'get_submissions_url'
)
list_display = ("text_header", "event", "open_from", "open_until", "number_of_applications", "get_submissions_url")

def get_queryset(self, request):
qs = super().get_queryset(request)
Expand All @@ -26,13 +22,13 @@ def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
if not request.user.is_superuser:
event = Event.objects.filter(team__in=[request.user])
form.base_fields['event'].queryset = event
form.base_fields["event"].queryset = event
return form

def get_urls(self):
urls = super().get_urls()
my_urls = [
path('submissions/', self.admin_site.admin_view(self.view_submissions)),
path("submissions/", self.admin_site.admin_view(self.view_submissions)),
]
return my_urls + urls

Expand All @@ -41,15 +37,15 @@ def view_submissions(self, request):
if forms.count() == 1:
# There is only one form, redirect to applications list straight away
form = forms.get()
return redirect('applications:applications', form.event.page_url)
return render(request, 'admin/applications/form/view_submissions.html', {
'forms': forms
})
return redirect("applications:applications", form.event.page_url)
return render(request, "admin/applications/form/view_submissions.html", {"forms": forms})

def get_submissions_url(self, obj):
return format_html(
'<a href="{}" target="_blank">See all submitted applications</a>',
reverse('applications:applications', args=[obj.event.page_url]))
reverse("applications:applications", args=[obj.event.page_url]),
)

get_submissions_url.short_description = "Applications"


Expand All @@ -71,7 +67,7 @@ def queryset(self, request, queryset):


class QuestionAdmin(SortableAdminMixin, admin.ModelAdmin):
list_display = ('form', 'title', 'question_type', 'is_required', 'order')
list_display = ("form", "title", "question_type", "is_required", "order")
list_filter = (FormFilter,)

def get_queryset(self, request):
Expand All @@ -84,30 +80,30 @@ def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
if not request.user.is_superuser:
form_objs = Form.objects.filter(event__team__in=[request.user])
form.base_fields['form'].queryset = form_objs
form.base_fields["form"].queryset = form_objs
return form


class AnswerInlineAdmin(admin.TabularInline):
model = Answer
can_delete = False
extra = 0
readonly_fields = ('question', 'answer')
readonly_fields = ("question", "answer")


class ApplicationAdmin(admin.ModelAdmin):
list_display = ('number', 'form', 'newsletter_optin', 'email', 'created')
list_filter = ('form', 'newsletter_optin')
list_display = ("number", "form", "newsletter_optin", "email", "created")
list_filter = ("form", "newsletter_optin")
inlines = [AnswerInlineAdmin]


class AnswerAdmin(admin.ModelAdmin):
list_display = ('application', 'question', 'answer')
raw_id_fields = ('question', 'application')
list_display = ("application", "question", "answer")
raw_id_fields = ("question", "application")


class EmailAdmin(admin.ModelAdmin):
list_display = ('form', 'author', 'subject', 'recipients_group', 'created', 'sent')
list_display = ("form", "author", "subject", "recipients_group", "created", "sent")


admin.site.register(Form, FormAdmin)
Expand Down
9 changes: 4 additions & 5 deletions applications/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ def organiser_only(function):

@wraps(function)
def decorator(request, *args, **kwargs):
page_url = kwargs.get('page_url')
page_url = kwargs.get("page_url")

if not page_url:
raise ValueError(
_('"page_url" slug must be present to user this decorator.')
)
raise ValueError(_('"page_url" slug must be present to user this decorator.'))

if not request.user.is_authenticated:
return redirect('core:event', page_url)
return redirect("core:event", page_url)

event = get_event(page_url, request.user.is_authenticated, False)
if event and (request.user in event.team.all() or request.user.is_superuser):
return function(request, *args, **kwargs)
return HttpResponseNotFound()

return decorator
Loading

0 comments on commit f46d1ce

Please sign in to comment.