Skip to content

Commit

Permalink
Merge branch 'master' into 1095-featureadmin-aktiviteter-default-sort…
Browse files Browse the repository at this point in the history
…ering-efter-periode-i-faldende-rækkefølge
  • Loading branch information
rasmusselsmark authored Aug 31, 2024
2 parents 80a944c + 1c128fe commit a08198f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 42 deletions.
32 changes: 16 additions & 16 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You are more than welcome to contribute to the system. This guide documents how

## Getting a local setup

- Installing Docker: Download and install [docker-compose][docker-guide]. If
- Installing Docker: Download and install [Docker Compose][docker-guide]. If
you use Ubuntu 18.04 (LTS), you can use [this guide][docker-ubuntu-guide] to
set up Docker.

Expand All @@ -13,15 +13,15 @@ You are more than welcome to contribute to the system. This guide documents how
- The setup adheres to the [twelve-factor-app][12f] principles. To get a
local development configuration, copy the file `.env.example` to `.env`

- Run `docker-compose up` to start your local system.
- Run `docker compose up` to start your local system.

- Run `docker-compose run web ./manage.py get_live_data` to download public
- Run `docker compose run web ./manage.py get_live_data` to download public
data and insert it into your local database.

- To get some dummy members, families, etc. you can use the [factories][factories] to create them.

```bash
docker-compose run web ./manage.py shell
docker compose run web ./manage.py shell
from members.tests.factories import MemberFactory
MemberFactory.create_batch(20)
```
Expand All @@ -31,7 +31,7 @@ You are more than welcome to contribute to the system. This guide documents how
with the real world. For instance each member belongs to their own department.

- To create a super user for the admin interface you can run
`docker-compose run web ./manage.py createsuperuser`
`docker compose run web ./manage.py createsuperuser`

- A pgAdmin container is configured as part of Docker Compose, and can be accessed on <http://localhost:5050>.
Log in with credentials `admin@example.com`/`admin`. Connection to database has been configured in
Expand Down Expand Up @@ -65,15 +65,15 @@ You are more than welcome to contribute to the system. This guide documents how

- [Django][django]: The base web framework used. The link is to their great
tutorial which takes an hour or two to complete.
- [Docker][docker-tutorial]: We use `docker-compose` to setup database,
- [Docker][docker-tutorial]: We use `docker compose` to setup database,
environment and dependencies. The following commands is all that's required
to work on the system.
- `docker-compose build` -- Builds the system.
- `docker-compose up` -- Starts the systems.
- `docker-compose down && docker volume rm backend_database`
- `docker compose build` -- Builds the system.
- `docker compose up` -- Starts the systems.
- `docker compose down && docker volume rm backend_database`
\-- Deletes your local database
- `docker-compose run web command` -- Replace `command` with what you want
- `docker compose run web command` -- Replace `command` with what you want
to run in the system.
- [SASS][sass]: CSS files belong in `members/static/members/sass`,
Expand All @@ -82,7 +82,7 @@ You are more than welcome to contribute to the system. This guide documents how
following command in a separate terminal:
```bash
docker-compose run web node_modules/.bin/sass --watch members/static/members/sass/main.scss members/static/members/css/main.css
docker compose run web node_modules/.bin/sass --watch members/static/members/sass/main.scss members/static/members/css/main.css
```
It will compile SASS when you save a file.
Expand All @@ -94,15 +94,15 @@ You are more than welcome to contribute to the system. This guide documents how
- [Selenium][selenium]: runs the functional tests. To run a specific test run
```bash
docker-compose run web ./manage.py test members.tests.test_functional.test_create_family
docker compose run web ./manage.py test members.tests.test_functional.test_create_family
```
where the name of your tests replaces the last part.
- [Unit tests][unittest]: runs the unittests. You run the unit tests the same way as the selenium tests. To run a specific test run
```bash
docker-compose run web ./manage.py test members.tests.test_dump_data
docker compose run web ./manage.py test members.tests.test_dump_data
```
where the name of your tests replaces the last part.
Expand All @@ -122,7 +122,7 @@ Pragmatic development is to use docker for database and run server and/or tests
- Install npm dependencies: `npm install`
- Copy the sample environment file: `cp .env.example .env`
- boot the database with `docker-compose start database`
- boot the database with `docker compose start database`
- boot a selenium docker with `docker run -it -p 4444:4444 -p 7900:7900 --network="host" -v /dev/shm:/dev/shm selenium/standalone-chrome`
- start the virtual env shell and work from there further on with `poetry shell`
- Run sass: `./node_modules/.bin/sass members/static/members/sass/main.scss`
Expand Down Expand Up @@ -159,13 +159,13 @@ p.user.username # show login email
discussion happens before the code and limits duplicate work.
4. Help us specify the requirements specification.
5. Code the features with tests, see the [testing guide][test_guide]
6. Run the entire test suite with: `docker-compose run web ./manage.py test`
6. Run the entire test suite with: `docker compose run web ./manage.py test`
7. Check that the following requirements are meet:
- The code has tests, code without tests is not accepted. (Except for
minimal CSS and text changes). Use the existing test as inspiration and
the [factories][factories] to create dummy data.
- The code conforms to the [black][black] formatting rules. To format your
code run `docker-compose run web black .`. Consider looking for an
code run `docker compose run web black .`. Consider looking for an
editor integration.
- The code passes [flake8][flake8] checks.
8. Submit the pull request.
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ jobs:
- name: Setup Enviroment
run: cp .env.example .env
- name: Builds the stack
run: docker-compose build
run: docker compose build
- name: Check formatting (Black)
run: docker-compose run web black --check .
run: docker compose run web black --check .
- name: Static error check (Flake8)
run: docker-compose run web flake8
run: docker compose run web flake8
- name: Test
run: docker-compose run web ./manage.py test
run: docker compose run web ./manage.py test
- uses: actions/upload-artifact@v2.1.4
if: always()
with:
name: selenium-screens
path: ./test-screens
- name: Create and upload UML diagram
run: mkdir -p UML && docker-compose run web ./manage.py graph_models members -o UML/UML_diagram.png
run: mkdir -p UML && docker compose run web ./manage.py graph_models members -o UML/UML_diagram.png
- uses: actions/upload-artifact@v2.1.4
with:
name: UML_diagram.png
Expand Down
1 change: 0 additions & 1 deletion members/admin/union_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def has_delete_permission(self, request, obj=None):
class UnionAdmin(admin.ModelAdmin):
inlines = [AdminUserUnionInline]
list_display = (
"id",
"union_link",
"address",
"union_email",
Expand Down
7 changes: 4 additions & 3 deletions members/admin/waitinglist_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def get_form(self, request, obj=None, change=False, **kwargs):
return form

list_display = (
"union_link",
"department_link",
"person_link",
"person_age_years",
Expand All @@ -89,6 +88,7 @@ def get_form(self, request, obj=None, change=False, **kwargs):
"user_waiting_list_number",
"user_created",
"user_added_waiting_list",
"union_link",
)

list_filter = (
Expand All @@ -101,10 +101,11 @@ def get_form(self, request, obj=None, change=False, **kwargs):
"department__name",
"department__union__name",
"person__name",
"zipcode",
"person__zipcode",
"person__municipality",
]
search_help_text = mark_safe(
"""Du kan søge på forening, afdeling eller person.<br>
"""Du kan søge på forening (navn), afdeling (navn) eller person (navn, postnummer eller kommune).<br>
'Nummer på venteliste' er relateret til personernes oprettelsestidspunkt"""
)

Expand Down
20 changes: 14 additions & 6 deletions members/tests/test_admin_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def setUp(self):
self.person_above_max_age = self.create_person_and_waiting_list_entry(
name="person_above_max_age", age=18
)
self.person_without_age = self.create_person_and_waiting_list_entry(
name="person_without_age"
)

# activity starts in two days, person has birthday two weeks after
self.person_too_young = self.create_person_and_waiting_list_entry(
Expand Down Expand Up @@ -108,6 +111,7 @@ def setUp(self):
)

def create_person_and_waiting_list_entry(self, name=None, age=None, birthday=None):
person_birthday = None
if age is not None:
person_birthday = (
datetime.now() - relativedelta(years=age) - relativedelta(weeks=1)
Expand All @@ -117,16 +121,20 @@ def create_person_and_waiting_list_entry(self, name=None, age=None, birthday=Non
person_birthday = birthday
person_name = f"Testperson født {person_birthday}"
else:
raise ValueError("Either age or birthday must be specified")
person_name = "Testperson uden fødselsdato"

if name is not None:
person_name = name

person = Person.objects.create(
name=person_name,
family=self.family,
birthday=person_birthday,
)
if person_birthday is not None:
person = Person.objects.create(
name=person_name,
family=self.family,
birthday=person_birthday,
)
else:
person = Person.objects.create(name=person_name, family=self.family)

WaitingList(
person=person,
department=self.department,
Expand Down
2 changes: 1 addition & 1 deletion members/tests/test_functional/test_account_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
def tearDown(self):
if not os.path.exists("test-screens"):
os.mkdir("test-screens")
self.browser.save_screenshot("test-screens/activities_list_final.png")
self.browser.save_screenshot("test-screens/account_login_final.png")
self.browser.quit()

def test_account_login(self):
Expand Down
2 changes: 1 addition & 1 deletion members/tests/test_functional/test_entry_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
def tearDown(self):
if not os.path.exists("test-screens"):
os.mkdir("test-screens")
self.browser.save_screenshot("test-screens/activities_list_final.png")
self.browser.save_screenshot("test-screens/entry_page_final.png")
self.browser.quit()

def test_entry_page_as_person(self):
Expand Down
21 changes: 15 additions & 6 deletions members/utils/age_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@


def check_is_person_too_young(activity, person):
# Check for two things:
# 1. if we are before start of activity: is person too young when activity starts ?
# 2. if we are at or after activity starts: is person too young now ?
# Check for three things:
# 1. Does the person have a birthday set (if none, then return false)
# 2. if we are before start of activity: is person too young when activity starts ?
# 3. if we are at or after activity starts: is person too young now ?

if person.birthday is None:
return True

if timezone.now().date() <= activity.start_date:
return (
person.birthday + relativedelta(years=activity.min_age)
Expand All @@ -19,9 +24,13 @@ def check_is_person_too_young(activity, person):


def check_is_person_too_old(activity, person):
# Check for two things:
# 1. if we are before start of activity: is person too old when activity starts ?
# 2. if we are at or after activity starts: is person too old now ?
# Check for three things:
# 1. Does the person have a birthday set (if none, then return false)
# 2. if we are before start of activity: is person too old when activity starts ?
# 3. if we are at or after activity starts: is person too old now ?

if person.birthday is None:
return True

if timezone.now().date() <= activity.start_date:
return (
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a08198f

Please sign in to comment.