Compare commits

35 Commits

Author SHA1 Message Date
6702211c05 docs: various refactoring
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-10-27 06:43:10 +01:00
f97e682640 docs: Registrierungen 2024-10-26 08:55:31 +02:00
c1e3248cc8 feat: show all ANs to be checked, not only active ones 2024-10-26 08:52:59 +02:00
0e67b777b5 fix: adoption form 2024-10-26 08:52:38 +02:00
0435c427b3 fix: Detail Animal form 2024-10-26 08:52:23 +02:00
be2df6970a fix: search template 2024-10-26 07:43:04 +02:00
1f5e7856b1 fix: url name 2024-10-19 20:38:24 +02:00
793de1ec64 fix: Add migration 2024-10-19 20:37:32 +02:00
6844e771b5 feat: Add timestamps to instance health check 2024-10-19 19:46:11 +02:00
1282b6b201 feat: Log tasks 2024-10-19 19:45:42 +02:00
975de1a230 fix: make sure anonymous users can look at ans 2024-10-19 17:45:26 +02:00
fd3478600f feat: exchange docs picture
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-10-14 21:46:50 +02:00
4d2991ba2f feat: Add basic logs 2024-10-10 23:21:07 +02:00
5aaaf57dd4 docs: document healthchecks 2024-10-10 23:19:34 +02:00
766b19e7c2 fix: comment action 2024-10-10 23:19:17 +02:00
f660a6b49a fix: varname 2024-10-10 22:26:28 +02:00
ab0c1a5c46 refactor: make healthchekscheck hourly 2024-10-10 22:24:55 +02:00
74a6b5f2aa feat: Add healthcheck 2024-10-10 18:35:22 +02:00
e38234b736 docs: Add basics on Vermittlungen
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-10-10 17:10:17 +02:00
ce38002676 chore: bump version 2024-10-10 17:09:33 +02:00
314cdfdd7c fix: Add missing celery file 2024-10-10 17:07:58 +02:00
4504a18f60 feat: add celery task to deactivate unchecked 2024-10-10 17:07:11 +02:00
df41028e99 feat: Add unchecked AN cleanup to health check 2024-10-10 17:06:50 +02:00
f404cfa0a3 feat: Add unchecked as AN status 2024-10-10 17:06:29 +02:00
72dedb6b0c fix: Build psycopg2 from source, pin python minor version 2024-10-10 14:33:18 +02:00
17468097ec fix: Add tag 2024-10-10 07:39:53 +02:00
28331f105a feat: Use celery for location queries 2024-10-10 07:39:44 +02:00
39893c2185 feat: Add basic celery config 2024-10-09 21:54:31 +02:00
ab2b91735e feat: Set title per page 2024-10-09 20:46:50 +02:00
1b9574cca9 refactor: Reorder 2024-10-05 13:26:32 +02:00
0d52101f22 feat: Add basic redirect service 2024-10-05 11:22:10 +02:00
96c0c1218f refactor: identation 2024-10-05 11:05:50 +02:00
864c76bc21 feat: Add domain customtag 2024-10-05 11:05:33 +02:00
c3646e6334 fix: typo 2024-10-05 11:02:37 +02:00
83a219df0c refactor: Add staticmethod to get a number of texts 2024-10-05 11:02:26 +02:00
43 changed files with 746 additions and 281 deletions

View File

@@ -1,10 +1,12 @@
FROM python:3-slim
FROM python:3.11-slim
# Use 3.11 to avoid django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 or psycopg module
MAINTAINER Julian-Samuel Gebühr
ENV DOCKER_BUILD=true
RUN apt update
RUN apt install gettext -y
RUN apt install libpq-dev gcc -y
COPY . /app
WORKDIR /app
RUN mkdir /app/data

View File

@@ -106,3 +106,20 @@ Use a program like `gtranslator` or `poedit` to start translations
| Edit adoption notice | User that created, Moderator, Admin |
| Edit animal | User that created, Moderator, Admin |
| Add animal/photo to adoption notice | User that created, Moderator, Admin |
# Celery and KeyDB
Start KeyDB docker container
```zsh
docker run -d --name keydb -p 6379:6379 eqalpha/keydb
```
Start worker
```zsh
celery -A notfellchen.celery worker
```
Start beat
```zsh
celery -A notfellchen.celery beat
```

View File

@@ -4,9 +4,5 @@ Administration
:maxdepth: 2
:caption: Contents:
create_user.rst
lending.rst
returning.rst
opening_hours.rst
add_items.rst
GDPR.rst
monitoring.rst

View File

@@ -1,7 +1,7 @@
Monitoring
==========
ILMO should, like every other software, be easy to monitor. Therefore a basic metrics are exposed to `https://notfellchen.org/metrics`.
Notfellchen should, like every other software, be easy to monitor. Therefore a basic metrics are exposed to `https://notfellchen.org/metrics`.
The data is encoded in JSON format and is therefore suitable to bea read by humans and it is easy to use it as data source for further processing.
@@ -60,3 +60,12 @@ Now we can simply use the InfluxDB as data source in Grafana and configure until
beautiful plots!
.. image:: monitoring_grafana.png
Healthchecks
------------
You can configure notfellchen to give a hourly ping to a healthchecks server. If this ping is not received, you will get notified and cna check why the celery jobs are no running.
Add the following to your `notfellchen.cfg` and adjust the URL to match your check.
.. code::
[monitoring]
healthchecks_url=https://health.example.org/ping/5fa7c9b2-753a-4cb3-bcc9-f982f5bc68e8

View File

@@ -1,10 +0,0 @@
Opening hours
=============
The opening hours can be changed by selecting the page :guilabel:`Opening hours` in the navigation menu.
You can not change an entry, simply delete it and create a new one.
.. note::
It is advised to fill empty time cells with a "-".

View File

@@ -1,8 +0,0 @@
Returning
=========
To return an item either visit the page :guilabel:`All loans` and search
for the loan there or you search for the item via :guilabel:`Search`.
If you found the loan, you can simply click on the button :guilabel:`Return` and
you are finished.

View File

@@ -4,16 +4,16 @@
Deployment
**********
There are different ways to deploy ILMO. We support an ansible+docker based deployment and manual installation.
There are different ways to deploy Notfellchen. We support an ansible+docker based deployment and manual installation.
Ansible deployment
==================
ILMO can be deployed with the `ilmo-ansible-role <https://github.com/moan0s/ansible-role-ilmo>`_ that is based on the
official ILMO docker image. This role will only install ilmo itself. If you want a complete setup that includes a
Notfellchen can be deployed with the `notfellchen-ansible-role <https://github.com/moan0s/ansible-role-notfellchen>`_ that is based on the
official Notfellchen docker image. This role will only install notfellchen itself. If you want a complete setup that includes a
database and a webserver with minimal configuration you can use the
`mash-playbook <https://github.com/mother-of-all-self-hosting/mash-playbook>`_ by following `it's documentation
on ILMO <https://github.com/mother-of-all-self-hosting/mash-playbook/blob/main/docs/services/ilmo.md>`_.
on Notfellchen <https://github.com/mother-of-all-self-hosting/mash-playbook/blob/main/docs/services/notfellchen.md>`_.
@@ -21,10 +21,10 @@ Manual Deployment
=================
This guide describes the installation of a installation of ILMO from source. It is inspired by this great guide from
This guide describes the installation of a installation of Notfellchen from source. It is inspired by this great guide from
pretix_.
.. warning:: Even though this guide tries to make it as straightforward to run ILMO, it still requires some Linux experience to
.. warning:: Even though this guide tries to make it as straightforward to run Notfellchen, it still requires some Linux experience to
get it right. If you're not feeling comfortable managing a Linux server, check out a managed service_.
This guide is tested on **Ubuntu20.04** but it should work very similar on other modern systemd based distributions.
@@ -39,18 +39,18 @@ installation guides):
* A HTTP reverse proxy, e.g. `nginx`_ or Traefik to allow HTTPS connections
* A `PostgreSQL`_ database server
Also recommended is, that you use a firewall, although this is not a ILMO-specific recommendation. If you're new to
Also recommended is, that you use a firewall, although this is not a Notfellchen-specific recommendation. If you're new to
Linux and firewalls, it is recommended that you start with `ufw`_.
.. note:: Please, do not run ILMO without HTTPS encryption. You'll handle user data and thanks to `Let's Encrypt`_
.. note:: Please, do not run Notfellchen without HTTPS encryption. You'll handle user data and thanks to `Let's Encrypt`_
SSL certificates can be obtained for free these days.
Unix user
---------
As we do not want to run ilmo as root, we first create a new unprivileged user::
As we do not want to run notfellchen as root, we first create a new unprivileged user::
# adduser ilmo --disabled-password --home /var/ilmo
# adduser notfellchen --disabled-password --home /var/notfellchen
In this guide, all code lines prepended with a ``#`` symbol are commands that you need to execute on your server as
``root`` user (e.g. using ``sudo``); all lines prepended with a ``$`` symbol should be run by the unprivileged user.
@@ -66,16 +66,16 @@ best compatibility. You can check this with the following command::
For PostgreSQL database creation, we would do::
# sudo -u postgres createuser ilmo
# sudo -u postgres createdb -O ilmo ilmo
# su ilmo
# sudo -u postgres createuser notfellchen
# sudo -u postgres createdb -O notfellchen notfellchen
# su notfellchen
$ psql
> ALTER USER ilmo PASSWORD 'strong_password';
> ALTER USER notfellchen PASSWORD 'strong_password';
Package dependencies
--------------------
To build and run ilmo, you will need the following debian packages::
To build and run notfellchen, you will need the following debian packages::
# apt-get install git build-essential python-dev python3-venv python3 python3-pip \
python3-dev
@@ -83,32 +83,32 @@ To build and run ilmo, you will need the following debian packages::
Config file
-----------
We now create a config directory and config file for ilmo::
We now create a config directory and config file for notfellchen::
# mkdir /etc/ilmo
# touch /etc/ilmo/ilmo.cfg
# chown -R ilmo:ilmo /etc/ilmo/
# chmod 0600 /etc/ilmo/ilmo.cfg
# mkdir /etc/notfellchen
# touch /etc/notfellchen/notfellchen.cfg
# chown -R notfellchen:notfellchen /etc/notfellchen/
# chmod 0600 /etc/notfellchen/notfellchen.cfg
Fill the configuration file ``/etc/ilmo/ilmo.cfg`` with the following content (adjusted to your environment)::
Fill the configuration file ``/etc/notfellchen/notfellchen.cfg`` with the following content (adjusted to your environment)::
[ilmo]
[notfellchen]
instance_name=My library
url=https://ilmo.example.com
url=https://notfellchen.example.com
[database]
backend=postgresql
name=ilmo
user=ilmo
name=notfellchen
user=notfellchen
[locations]
static=/var/ilmo/static
static=/var/notfellchen/static
[mail]
; See config file documentation for more options
; from=ilmo@example.com
; from=notfellchen@example.com
; host=127.0.0.1
; user=ilmo
; user=notfellchen
; password=foobar
; port=587
@@ -121,21 +121,21 @@ Fill the configuration file ``/etc/ilmo/ilmo.cfg`` with the following content (a
;Scope=
;Policy=
Install ilmo as package
Install notfellchen as package
------------------------
Now we will install ilmo itself. The following steps are to be executed as the ``ilmo`` user. Before we
actually install ilmo, we will create a virtual environment to isolate the python packages from your global
Now we will install notfellchen itself. The following steps are to be executed as the ``notfellchen`` user. Before we
actually install notfellchen, we will create a virtual environment to isolate the python packages from your global
python installation::
$ python3 -m venv /var/ilmo/venv
$ source /var/ilmo/venv/bin/activate
$ python3 -m venv /var/notfellchen/venv
$ source /var/notfellchen/venv/bin/activate
(venv)$ pip3 install -U pip setuptools wheel
We now clone and install ilmo, its direct dependencies and gunicorn::
We now clone and install notfellchen, its direct dependencies and gunicorn::
(venv)$ git clone https://github.com/moan0s/ILMO2
(venv)$ cd ILMO2/src/
(venv)$ git clone https://github.com/moan0s/Notfellchen2
(venv)$ cd Notfellchen2/src/
(venv)$ pip3 install -r requirements.txt
(venv)$ pip3 install -e .
@@ -148,26 +148,26 @@ Finally, we compile static files and create the database structure::
(venv)$ django-admin compilemessages --ignore venv
Start ilmo as a service
Start notfellchen as a service
-------------------------
You should start ilmo using systemd to automatically start it after a reboot. Create a file
named ``/etc/systemd/system/ilmo-web.service`` with the following content::
You should start notfellchen using systemd to automatically start it after a reboot. Create a file
named ``/etc/systemd/system/notfellchen-web.service`` with the following content::
[Unit]
Description=ilmo web service
Description=notfellchen web service
After=network.target
[Service]
User=ilmo
Group=ilmo
Environment="VIRTUAL_ENV=/var/ilmo/venv"
Environment="PATH=/var/ilmo/venv/bin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/var/ilmo/venv/bin/gunicorn ilmo.wsgi \
--name ilmo --workers 5 \
User=notfellchen
Group=notfellchen
Environment="VIRTUAL_ENV=/var/notfellchen/venv"
Environment="PATH=/var/notfellchen/venv/bin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/var/notfellchen/venv/bin/gunicorn notfellchen.wsgi \
--name notfellchen --workers 5 \
--max-requests 1200 --max-requests-jitter 50 \
--log-level=info --bind=127.0.0.1:8345
WorkingDirectory=/var/ilmo
WorkingDirectory=/var/notfellchen
Restart=on-failure
[Install]
@@ -176,14 +176,14 @@ named ``/etc/systemd/system/ilmo-web.service`` with the following content::
You can now run the following commands to enable and start the services::
# systemctl daemon-reload
# systemctl enable ilmo-web
# systemctl start ilmo-web
# systemctl enable notfellchen-web
# systemctl start notfellchen-web
SSL
---
The following snippet is an example on how to configure a nginx proxy for ilmo::
The following snippet is an example on how to configure a nginx proxy for notfellchen::
server {
listen 80;
@@ -196,8 +196,8 @@ The following snippet is an example on how to configure a nginx proxy for ilmo::
#
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/letsencrypt/live/ilmo.example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/ilmo.example.com/privkey.pem;
ssl_certificate /etc/letsencrypt/live/notfellchen.example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/notfellchen.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
@@ -208,7 +208,7 @@ The following snippet is an example on how to configure a nginx proxy for ilmo::
add_header Referrer-Policy same-origin;
add_header X-Content-Type-Options nosniff;
server_name ilmo.example.com;
server_name notfellchen.example.com;
location / {
proxy_pass http://localhost:8345;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -217,7 +217,7 @@ The following snippet is an example on how to configure a nginx proxy for ilmo::
}
location /static/ {
alias /var/ilmo/static/;
alias /var/notfellchen/static/;
access_log off;
expires 365d;
add_header Cache-Control "public";
@@ -230,22 +230,22 @@ We recommend reading about setting `strong encryption settings`_ for your web se
Next steps
----------
Yay, you are done! You should now be able to reach ilmo at https://ilmo.example.com/
Yay, you are done! You should now be able to reach notfellchen at https://notfellchen.example.com/
Updates
-------
.. warning:: While we try hard not to break things, **please perform a backup before every upgrade**.
To upgrade to a new ilmo release, pull the latest code changes and run the following commands::
To upgrade to a new notfellchen release, pull the latest code changes and run the following commands::
$ source /var/ilmo/venv/bin/activate
$ source /var/notfellchen/venv/bin/activate
(venv)$ git pull
(venv)$ pg_dump ilmo > ilmo.psql
(venv)$ pg_dump notfellchen > notfellchen.psql
(venv)$ python manage.py migrate
(venv)$ django-admin compilemessages --ignore venv
# systemctl restart ilmo-web
# systemctl restart notfellchen-web
.. _Postfix: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04

View File

@@ -12,10 +12,7 @@ Notfellchen Plattform Dokumentation
API/index.rst
.. image:: rtfm.png
:name: RTFM by Elektroll
:scale: 50 %
:alt: Soviet style image of workers holding a sign with a gear and a screwdriver. Below is says "Read the manual"
:name: Ratte lesend
:alt: Zeichnung einer lesenden Ratte
:align: center
Read the manual, Image by `Mike Powell (CC-BY) <https://elektroll.art/>`_.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 815 KiB

After

Width:  |  Height:  |  Size: 485 KiB

BIN
docs/user/abonnieren.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -1,9 +1,18 @@
Benachrichtigungen
==================
Jede Vermittlung kann abonniert werden. Dafür klickst du auf die Glocke neben dem Titel der Vermittlung.
.. image:: abonnieren.png
Auf der Website
+++++++++++++++
E-Mail
++++++
Mit während deiner :doc:`registrierung` gibst du eine E-Mail Addresse an.
Wir senden dir Benachrichtigungen an diese E-Mail. Du kannst das in deinen Profileinstellungen anpassen.
Benachrichtigungen senden wir per Mail - du kannst das jederzeit in den Einstellungen deaktivieren.

View File

@@ -7,5 +7,4 @@ Users guide
registrierung.rst
benachrichtigungen.rst
login.rst
email.rst
vermittlungen.rst

View File

@@ -1,5 +1,10 @@
Registration
Registrierung
================================
To register you have to visit the library. An librarian will then set up an account for you.
You will need to provide an valid E-Mail Address and a password.
Du kannst dich jederzeit selbst registrieren. Das geht unter https://notfellchen.org/accounts/register/
Ein Account ermöglicht es dir
* Kommentare zu hinterlassen
* Vermittlungen hinzuzufügen
* Vermittlungen zu abonnieren

View File

@@ -1,3 +1,17 @@
Vermittlungen
=============
Vermittlungen können von allen Nutzer*innen mit Account erstellt werden. Vermittlungen normaler Nutzer*innen kommen dann in eine Warteschlange und werden vom Admin & Modertionsteam geprüft und sichtbar geschaltet.
Tierheime und Pflegestellen können auf Anfrage einen Koordinations-Status bekommen, wodurch sie Vermittlungsanzeigen erstellen können die direkt öffentlich sichtbar sind.
Jede Vermittlung hat ein "Zuletzt-geprüft" Datum, das anzeigt, wann ein Mensch zuletzt überprüft hat, ob die Anzeige noch aktuell ist.
Nach 3 Wochen ohne Prüfung werden Anzeigen automatisch von der Seite entfernt und nur dann wieder freigeschaltet, wenn eine manuelle Prüfung erfolgt.
Darüber hinaus werden einmal täglich die verlinkten Seiten automatisiert geprüft. Wenn eine Vermittlungs-Seite bei einem Tierheim oder einer Pflegestelle entfernt wurde, wird die Anzeige ebenfalls deaktiviert.
Vermittlungen können von allen Menschen, auch ohne Account gemeldet werden. Grund dafür kann sein, dass Informationen veraltet sind oder ein Verdacht von Tierwohlgefärdung. Gemeldete Vermittlungen werden vom Moderationsteam geprüft und ggf. entfernt.
Die Kommentarfunktion von Vermittlungen ermöglicht es angemeldeten Nutzer*innen zusätzliche Informationen hinzuzufügen oder Fragen zu stellen.
Ersteller*innen von Vermittlungen werden über neue Kommentare per Mail benachrichtigt, ebenso alle die die Vermittlung abonniert haben.
Kommentare können, wie Vermittlungen, gemeldet werden.

View File

@@ -35,10 +35,11 @@ dependencies = [
"markdown",
"Pillow",
"django-registration",
"psycopg2-binary",
"psycopg2",
"django-crispy-forms",
"crispy-bootstrap4",
"djangorestframework"
"djangorestframework",
"celery[redis]"
]
dynamic = ["version", "readme"]

View File

@@ -2,7 +2,7 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib import admin
from django.utils.html import format_html
from .models import User, Language, Text, ReportComment, ReportAdoptionNotice
from .models import User, Language, Text, ReportComment, ReportAdoptionNotice, Log
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
Comment, Report, Announcement, AdoptionNoticeStatus, User, Subscriptions
@@ -62,3 +62,4 @@ admin.site.register(Text)
admin.site.register(Announcement)
admin.site.register(AdoptionNoticeStatus)
admin.site.register(Subscriptions)
admin.site.register(Log)

View File

@@ -6,7 +6,7 @@ from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportC
Comment
from django_registration.forms import RegistrationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
from django.utils.translation import gettext_lazy as _
from notfellchen.settings import MEDIA_URL
@@ -142,8 +142,8 @@ class CommentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_action = "comment"
self.helper.form_class = 'form-comments'
self.helper.add_input(Hidden('action', 'comment'))
self.helper.add_input(Submit('submit', _('Kommentieren'), css_class="btn2"))
class Meta:

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2024-10-10 14:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0007_alter_adoptionnotice_last_checked'),
]
operations = [
migrations.AlterField(
model_name='adoptionnoticestatus',
name='minor_status',
field=models.CharField(choices=[('searching', 'searching'), ('interested', 'interested'), ('waiting_for_review', 'waiting_for_review'), ('needs_additional_info', 'needs_additional_info'), ('successful_with_notfellchen', 'successful_with_notfellchen'), ('successful_without_notfellchen', 'successful_without_notfellchen'), ('animal_died', 'animal_died'), ('closed_for_other_adoption_notice', 'closed_for_other_adoption_notice'), ('not_open_for_adoption_anymore', 'not_open_for_adoption_anymore'), ('other', 'other'), ('against_the_rules', 'against_the_rules'), ('missing_information', 'missing_information'), ('technical_error', 'technical_error'), ('unchecked', 'unchecked')], max_length=200),
),
migrations.AlterField(
model_name='announcement',
name='publish_start_time',
field=models.DateTimeField(verbose_name='Veröffentlichungszeitpunkt'),
),
]

View File

@@ -0,0 +1,25 @@
# Generated by Django 5.1.1 on 2024-10-10 21:00
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0008_alter_adoptionnoticestatus_minor_status_and_more'),
]
operations = [
migrations.CreateModel(
name='Log',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('action', models.CharField(max_length=255, verbose_name='Aktion')),
('text', models.CharField(max_length=1000, verbose_name='Log text')),
('created_at', models.DateTimeField(auto_now_add=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Nutzer*in')),
],
),
]

View File

@@ -0,0 +1,21 @@
# Generated by Django 5.1.1 on 2024-10-19 18:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0009_log'),
]
operations = [
migrations.CreateModel(
name='Timestamp',
fields=[
('key', models.CharField(max_length=255, primary_key=True, serialize=False, verbose_name='Schlüssel')),
('timestamp', models.DateTimeField(auto_now_add=True, verbose_name='Zeitstempel')),
('data', models.CharField(blank=True, max_length=2000, null=True)),
],
),
]

View File

@@ -72,7 +72,7 @@ class User(AbstractUser):
return self.get_absolute_url()
def get_num_unread_notifications(self):
return BaseNotification.objects.filter(user=self,read=False).count()
return BaseNotification.objects.filter(user=self, read=False).count()
@property
def owner(self):
@@ -134,6 +134,13 @@ class Location(models.Model):
)
return location
@staticmethod
def add_location_to_object(instance):
"""Search the location given in the location string and add it to the object"""
location = Location.get_location_from_string(instance.location_string)
instance.location = location
instance.save()
class RescueOrganization(models.Model):
def __str__(self):
@@ -155,7 +162,10 @@ class RescueOrganization(models.Model):
name = models.CharField(max_length=200)
trusted = models.BooleanField(default=False, verbose_name=_('Vertrauenswürdig'))
allows_using_materials = models.CharField(max_length=200,default=ALLOW_USE_MATERIALS_CHOICE[USE_MATERIALS_NOT_ASKED], choices=ALLOW_USE_MATERIALS_CHOICE, verbose_name=_('Erlaubt Nutzung von Inhalten'))
allows_using_materials = models.CharField(max_length=200,
default=ALLOW_USE_MATERIALS_CHOICE[USE_MATERIALS_NOT_ASKED],
choices=ALLOW_USE_MATERIALS_CHOICE,
verbose_name=_('Erlaubt Nutzung von Inhalten'))
location_string = models.CharField(max_length=200, verbose_name=_("Ort der Organisation"))
location = models.ForeignKey(Location, on_delete=models.PROTECT, blank=True, null=True)
instagram = models.URLField(null=True, blank=True, verbose_name=_('Instagram Profil'))
@@ -276,11 +286,17 @@ class AdoptionNotice(models.Model):
if not hasattr(self, 'adoptionnoticestatus'):
return False
return self.adoptionnoticestatus.is_active
@property
def is_to_be_checked(self, include_active=False):
if not hasattr(self, 'adoptionnoticestatus'):
return False
return self.adoptionnoticestatus.is_to_be_checked or (include_active and self.adoptionnoticestatus.is_active)
def set_checked(self):
self.last_checked = datetime.now()
self.save()
def set_closed(self):
self.last_checked = datetime.now()
self.adoptionnoticestatus.set_closed()
@@ -324,6 +340,7 @@ class AdoptionNoticeStatus(models.Model):
"against_the_rules": "against_the_rules",
"missing_information": "missing_information",
"technical_error": "technical_error",
"unchecked": "unchecked",
"other": "other"
}
}
@@ -342,6 +359,10 @@ class AdoptionNoticeStatus(models.Model):
def is_active(self):
return self.major_status == self.ACTIVE
@property
def is_to_be_checked(self):
return self.major_status == self.DISABLED and self.minor_status == "unchecked"
@staticmethod
def get_minor_choices(major_status):
return AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status]
@@ -351,6 +372,11 @@ class AdoptionNoticeStatus(models.Model):
self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED]["other"]
self.save()
def deactivate_unchecked(self):
self.major_status = self.MAJOR_STATUS_CHOICES[self.DISABLED]
self.minor_status = self.MINOR_STATUS_CHOICES[self.DISABLED]["unchecked"]
self.save()
class Animal(models.Model):
MALE_NEUTERED = "M_N"
@@ -516,6 +542,17 @@ class Text(models.Model):
def __str__(self):
return f"{self.title} ({self.language})"
@staticmethod
def get_texts(text_codes, language, expandable_dict=None):
if expandable_dict is None:
expandable_dict = {}
for text_code in text_codes:
try:
expandable_dict[text_code] = Text.objects.get(text_code=text_code, language=language, )
except Text.DoesNotExist:
expandable_dict[text_code] = None
return expandable_dict
class Announcement(Text):
"""
@@ -523,7 +560,7 @@ class Announcement(Text):
"""
logged_in_only = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
publish_start_time = models.DateTimeField(verbose_name="Veröffentlichungszeitpunk")
publish_start_time = models.DateTimeField(verbose_name="Veröffentlichungszeitpunkt")
publish_end_time = models.DateTimeField(verbose_name="Veröffentlichungsende")
IMPORTANT = "important"
WARNING = "warning"
@@ -615,4 +652,29 @@ class Subscriptions(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.owner} - { self.adoption_notice }"
return f"{self.owner} - {self.adoption_notice}"
class Log(models.Model):
"""
Basic class that allows logging random entries for later inspection
"""
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("Nutzer*in"))
action = models.CharField(max_length=255, verbose_name=_("Aktion"))
text = models.CharField(max_length=1000, verbose_name=_("Log text"))
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"[{self.action}] - {self.user} - {self.created_at.strftime('%H:%M:%S %d-%m-%Y ')}"
class Timestamp(models.Model):
"""
Class to store timestamps based on keys
"""
key = models.CharField(max_length=255, verbose_name=_("Schlüssel"), primary_key=True)
timestamp = models.DateTimeField(auto_now_add=True, verbose_name=_("Zeitstempel"))
data = models.CharField(max_length=2000, blank=True, null=True)
def ___str__(self):
return f"[{self.key}] - {self.timestamp.strftime('%H:%M:%S %d-%m-%Y ')} - {self.data}"

View File

@@ -1,3 +1,7 @@
/***************/
/* MAIN COLORS */
/***************/
:root {
--primary-light-one: #5daa68;
--primary-light-two: #4a9455;
@@ -18,7 +22,9 @@
--text-three: var(--primary-light-one);
--shadow-three: var(--primary-dark-one);
}
/**************************/
/* TAG SETTINGS (GENERAL) */
/**************************/
html, body {
margin: 0;
height: 100%;
@@ -30,10 +36,6 @@ body {
}
.content-box {
margin: 20px;
}
table {
width: 100%;
}
@@ -79,6 +81,127 @@ h1, h2 {
box-sizing: border-box;
}
textarea {
border-radius: 10px;
width: 100%;
margin: 5px;
}
/**************/
/* CONTAINERS */
/**************/
.container-cards {
display: flex;
flex-wrap: wrap;
}
.card {
flex: 1 25%;
margin: 10px;
border-radius: 8px;
padding: 5px;
background: var(--background-three);
color: var(--text-two);
}
.container-edit-buttons {
display: flex;
flex-wrap: wrap;
.btn {
margin: 5px;
}
}
/*******************************/
/* PARTIAL SPECIFIC CONTAINERS */
/*******************************/
.detail-animal-header {
border-radius: 5px;
display: flex;
align-items: center;
justify-content: space-between;
}
@media screen and (max-width: 800px) {
.detail-animal-header {
display: block;
}
}
.profile-card {
display: flex;
border-radius: 0px 0px 8px 8px;
background-color: var(--highlight-two);
color: var(--highlight-one-text);
.btn2 {
height: 40px;
}
.button_darken:hover {
background-color: var(--highlight-one);
color: var(--highlight-one-text);
}
button {
background: inherit;
color: inherit;
}
}
.container-comment-form {
width: 80%;
color: var(--text-one);
b {
text-shadow: 2px 2px var(--shadow-one);
}
}
/***********/
/* BUTTONS */
/***********/
select, .button {
width: 100%;
border: none;
border-radius: 4px;
opacity: 1;
background-color: var(--secondary-light-one);
}
.btn {
background-color: var(--primary-light-one);
color: var(--secondary-light-one);
padding: 16px;
border-radius: 8px;
border: none;
font-weight: bold;
}
.btn2 {
background-color: var(--secondary-light-one);
color: var(--primary-dark-one);
padding: 8px;
border-radius: 4px;
border: none;
margin: 5px;
}
/*********************/
/* UNIQUE COMPONENTS */
/*********************/
.content-box {
margin: 20px;
}
.header {
overflow: hidden;
background-color: var(--background-two);
@@ -110,14 +233,7 @@ h1, h2 {
color: white;
}
select, .button {
width: 100%;
border: none;
border-radius: 4px;
opacity: 1;
background-color: var(--secondary-light-one);
}
.header-right select.option {
color: #000;
@@ -135,26 +251,6 @@ select, .button {
height: 67px;
}
.profile-card {
display: flex;
border-radius: 0px 0px 8px 8px;
background-color: var(--highlight-two);
color: var(--highlight-one-text);
.btn2 {
height: 40px;
}
.button_darken:hover {
background-color: var(--highlight-one);
color: var(--highlight-one-text);
}
button {
background: inherit;
color: inherit;
}
}
@media screen and (max-width: 500px) {
.header a {
@@ -172,25 +268,6 @@ select, .button {
height: 40px;
}
.btn {
background-color: var(--primary-light-one);
color: var(--secondary-light-one);
padding: 16px;
border-radius: 8px;
border: none;
font-weight: bold;
}
.btn2 {
background-color: var(--secondary-light-one);
color: var(--primary-dark-one);
padding: 8px;
border-radius: 4px;
border: none;
margin: 5px;
}
.form-button, .link-button a:link, .link-button a:visited {
background-color: #4ba3cd;
color: white;
@@ -203,14 +280,6 @@ select, .button {
border: none;
}
.container-edit-buttons {
display: flex;
flex-wrap: wrap;
.btn {
margin: 5px;
}
}
.form-button:hover, .link-button a:hover, .link-button a:active {
background-color: #4090b6;
@@ -326,18 +395,6 @@ select, .button {
}
}
.detail-animal-header {
border-radius: 5px;
display: flex;
align-items: center;
justify-content: space-between;
}
@media screen and (max-width: 800px) {
.detail-animal-header {
display: block;
}
}
.tag {
border: black 1px solid;
@@ -355,10 +412,7 @@ select, .button {
}
.container-cards {
display: flex;
flex-wrap: wrap;
}
.photos {
@@ -376,14 +430,6 @@ select, .button {
border-radius: 10%;
}
.card {
flex: 1 25%;
margin: 10px;
border-radius: 8px;
padding: 5px;
background: var(--background-three);
color: var(--text-two);
}
.card h1 {
color: var(--text-three);
@@ -514,20 +560,7 @@ select, .button {
color: var(--text-two);
}
.container-comment-form {
width: 80%;
color: var(--text-one);
b {
text-shadow: 2px 2px var(--shadow-one);
}
}
textarea {
border-radius: 10px;
width: 100%;
margin: 5px;
}
.form-comments {
.btn {
@@ -552,6 +585,21 @@ textarea {
}
}
.form-search {
select, input {
background-color: var(--primary-light-one);
color: var(--text-one);
border-radius: 3px;
border: none;
}
}
/************************/
/* GENERAL HIGHLIGHTING */
/************************/
.important {
border: #e01137 4px solid;
}
@@ -564,15 +612,10 @@ textarea {
border: rgba(17, 58, 224, 0.51) 4px solid;
}
.form-search {
select, input {
background-color: var(--primary-light-one);
color: var(--text-one);
border-radius: 3px;
border: none;
}
}
/*******/
/* MAP */
/*******/
.marker {
background-image: url('../img/logo_transparent.png');
@@ -594,4 +637,4 @@ textarea {
.map-in-content #map {
height: 500px;
width: 90%;
}
}

View File

@@ -0,0 +1,38 @@
from datetime import datetime
from notfellchen.celery import app as celery_app
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices
from .tools.misc import healthcheck_ok
from .models import Location, AdoptionNotice, Timestamp
def set_timestamp(key: str):
try:
ts = Timestamp.objects.get(key=key)
ts.timestamp = datetime.now()
except Timestamp.DoesNotExist:
Timestamp.objects.create(key=key, timestamp=datetime.now())
@celery_app.task(name="admin.clean_locations")
def task_clean_locations():
clean_locations()
set_timestamp("task_clean_locations")
@celery_app.task(name="admin.deactivate_unchecked")
def task_deactivate_unchecked():
deactivate_unchecked_adoption_notices()
set_timestamp("task_deactivate_unchecked")
@celery_app.task(name="commit.add_location")
def add_adoption_notice_location(pk):
instance = AdoptionNotice.objects.get(pk=pk)
Location.add_location_to_object(instance)
set_timestamp("add_adoption_notice_location")
@celery_app.task(name="tools.healthcheck")
def task_healthcheck():
healthcheck_ok()
set_timestamp("task_healthcheck")

View File

@@ -2,6 +2,8 @@
{% load i18n %}
{% load custom_tags %}
{% block title %}<title>{% translate "Über uns und Regeln" %}</title> %}{% endblock %}
{% block content %}
<h1>{% translate "Regeln" %}</h1>
{% include "fellchensammlung/lists/list-rules.html" %}

View File

@@ -1,10 +1,12 @@
{% load custom_tags %}
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
{% block title %}<title>Notfellchen</title>{% endblock %}
{% block title %}{% endblock %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{% translate "Farbratten aus dem Tierschutz finden und adoptieren" %}">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'fellchensammlung/css/styles.css' %}">

View File

@@ -2,23 +2,25 @@
{% load custom_tags %}
{% load i18n %}
{% block title %}<title>{{adoption_notice.name }}</title>{% endblock %}
{% block content %}
<div class="detail-adoption-notice-header">
<h1 class="detail-adoption-notice-header">{{ adoption_notice.name }}
{% if not is_subscribed %}
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="subscribe">
<input type="hidden" name="adoption_notice_id" value="{{ adoption_notice.pk }}">
<button class="btn2" type="submit" id="submit"><i class="fa-solid fa-bell"></i></button>
</form>
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="subscribe">
<input type="hidden" name="adoption_notice_id" value="{{ adoption_notice.pk }}">
<button class="btn2" type="submit" id="submit"><i class="fa-solid fa-bell"></i></button>
</form>
{% else %}
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="unsubscribe">
<input type="hidden" name="adoption_notice_id" value="{{ adoption_notice.pk }}">
<button class="btn2" type="submit" id="submit"><i class="fa-solid fa-bell-slash"></i></button>
</form>
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="unsubscribe">
<input type="hidden" name="adoption_notice_id" value="{{ adoption_notice.pk }}">
<button class="btn2" type="submit" id="submit"><i class="fa-solid fa-bell-slash"></i></button>
</form>
{% endif %}
</h1>
{% if has_edit_permission %}
@@ -48,7 +50,14 @@
<td>{{ adoption_notice.searching_since }}</td>
<td>{{ adoption_notice.last_checked | date:'d. F Y' }}</td>
{% if adoption_notice.further_information %}
<td>{{ adoption_notice.link_to_more_information | safe }}</td>
<td>
<form method="get" action="{% url 'external-site' %}">
<input type="hidden" name="url" value="{{ adoption_notice.further_information }}">
<button class="btn" type="submit" id="submit">
{{ adoption_notice.further_information | domain }} <i class="fa-solid fa-arrow-up-right-from-square"></i>
</button>
</form>
</td>
{% else %}
<td>-</td>
{% endif %}

View File

@@ -2,6 +2,8 @@
{% load custom_tags %}
{% load i18n %}
{% block title %}<title>{{ animal.name }}</title>{% endblock %}
{% block content %}
{% include "fellchensammlung/details/detail-animal-partial.html" %}
{% endblock %}

View File

@@ -0,0 +1,10 @@
{% extends "fellchensammlung/base_generic.html" %}
{% load i18n %}
{% block content %}
<div class="card">
{% blocktranslate %}
<p>Achtung du verlässt notfellchen.org</p>
{% endblocktranslate %}
<a href="{{ url }}" class="btn" >{% translate "Weiter" %}</a>
</div>
{% endblock content %}

View File

@@ -2,6 +2,8 @@
{% load i18n %}
{% load crispy_forms_tags %}
{% block title %}<title>{% translate "Vermittlung hinzufügen" %}</title>{% endblock %}
{% block content %}
<h1>{% translate "Vermitteln" %}</h1>
<p>

View File

@@ -2,6 +2,8 @@
{% load i18n %}
{% load custom_tags %}
{% block title %}<title>{% translate "Notfellchen - Farbratten aus dem Tierschutz adoptieren" %}</title>{% endblock %}
{% block content %}
{% for announcement in announcements %}
{% include "fellchensammlung/partials/partial-announcement.html" %}

View File

@@ -1,28 +1,51 @@
{% extends "fellchensammlung/base_generic.html" %}
{% load i18n %}
{% block title %}<title>{% translate "Instanz-Check" %}</title> {% endblock %}
{% block content %}
<div class="card">
<h1>{% translate "Instanz-Check" %}</h1>
{% if missing_texts|length > 0 %}
<h2>{% trans "Fehlende Texte" %}</h2>
<p>
<table>
<table>
<tr>
<th>{% translate "Text Code" %}</th>
<th>{% translate "Sprache" %}</th>
</tr>
{% for missing_text in missing_texts %}
<tr>
<th>{% translate "Text Code" %}</th>
<th>{% translate "Sprache" %}</th>
<td>{{ missing_text.0 }}</td>
<td>{{ missing_text.1 }}</td>
</tr>
{% for missing_text in missing_texts %}
<tr>
<td>{{ missing_text.0 }}</td>
<td>{{ missing_text.1 }}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
</table>
</p>
{% else %}
<p>{% translate "Texte scheinen vollständig" %}</p>
{% endif %}
<h2>{% trans "Zeitstempel" %}</h2>
{% if timestamps|length > 0 %}
<p>
<table>
<tr>
<th>{% translate "Key" %}</th>
<th>{% translate "Zeitstempel" %}</th>
<th>{% translate "Daten" %}</th>
</tr>
{% for timestamp in timestamps %}
<tr>
<td>{{ timestamp.key }}</td>
<td>{{ timestamp.timestamp }}</td>
<td>{{ timestamp.data }}</td>
</tr>
{% endfor %}
</table>
</p>
{% else %}
<p>{% translate "Keine Zeitstempel geloggt." %}</p>
{% endif %}
<h2>{% translate "Nicht-lokalisierte Vermittlungen" %}</h2>
{% if number_not_geocoded_adoption_notices > 0 %}
<details>
@@ -55,6 +78,22 @@
<p>{{ number_not_geocoded_rescue_orgs }}/{{ number_of_rescue_orgs }}</p>
{% endif %}
<h2>{% translate "Nicht-geprüfte Vermittlungen" %}</h2>
{% if number_unchecked_ans > 0 %}
<details>
<summary>{{ number_unchecked_ans }}</summary>
<ul>
{% for unchecked_an in unchecked_ans %}
<li>
<a href="{{ unchecked_an.get_absolute_url }}">{{ unchecked_an.name }}</a>
</li>
{% endfor %}
</ul>
</details>
{% else %}
<p>{{ number_unchecked_ans }}</p>
{% endif %}
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="clean_locations">
@@ -62,5 +101,13 @@
<i class="fa-solid fa-broom"></i> {% translate "Erneut lokalisieren" %}
</button>
</form>
<form class="notification-card-mark-read" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="deactivate_unchecked_adoption_notices">
<button class="btn" type="submit" id="submit">
<i class="fa-solid fa-broom"></i> {% translate "Deaktivire ungeprüfte Vermittlungen" %}
</button>
</form>
</div>
{% endblock content %}

View File

@@ -1,5 +1,6 @@
{% extends "fellchensammlung/base_generic.html" %}
{% load i18n %}
{% block title %}<title>{% translate "Karte" %}</title> %}
{% block content %}
<div class="card">

View File

@@ -1,5 +1,6 @@
{% extends "fellchensammlung/base_generic.html" %}
{% load i18n %}
{% block title %}<title>{% translate "Modqueue" %}</title> %}{% endblock %}
{% block content %}
<h1>{% translate "Modqueue" %}</h1>

View File

@@ -1,5 +1,8 @@
{% extends "fellchensammlung/base_generic.html" %}
{% load i18n %}
{% block title %}<title>{% translate "Suche" %}</title>{% endblock %}
{% block content %}
<form class="form-search card" method="post">
{% csrf_token %}

View File

@@ -4,6 +4,7 @@ from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from notfellchen import settings
from urllib.parse import urlparse
register = template.Library()
@@ -56,6 +57,17 @@ def pointdecimal(value):
except ValueError:
return value
@register.filter
@stringfilter
def domain(url):
try:
domain = urlparse(url).netloc
if domain.startswith("www."):
return domain[4:]
return domain
except ValueError:
return url
@register.simple_tag
def settings_value(name):
return getattr(settings, name)

View File

@@ -1,4 +1,8 @@
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization
from django.utils import timezone
from datetime import timedelta
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus
def clean_locations(quiet=True):
# ADOPTION NOTICES
@@ -7,7 +11,7 @@ def clean_locations(quiet=True):
num_without_location = adoption_notices_without_location.count()
if not quiet:
print(f"From {num_of_all} there are {num_without_location} adoption notices without location "
f"({num_without_location/num_of_all*100:.2f}%)")
f"({num_without_location / num_of_all * 100:.2f}%)")
for adoption_notice in adoption_notices_without_location:
if not quiet:
print(f"Searching {adoption_notice.location_string} in Nominatim")
@@ -28,7 +32,7 @@ def clean_locations(quiet=True):
num_without_location = rescue_orgs_without_location.count()
if not quiet:
print(f"From {num_of_all} there are {num_without_location} adoption notices without location "
f"({num_without_location/num_of_all*100:.2f}%)")
f"({num_without_location / num_of_all * 100:.2f}%)")
for rescue_org in rescue_orgs_without_location:
if not quiet:
print(f"Searching {rescue_org.location_string} in Nominatim")
@@ -41,4 +45,21 @@ def clean_locations(quiet=True):
num_without_location_new = rescue_orgs_without_location_new.count()
num_new = num_without_location - num_without_location_new
if not quiet:
print(f"Added {num_new} new locations")
print(f"Added {num_new} new locations")
def get_unchecked_adoption_notices(weeks=3):
now = timezone.now()
three_weeks_ago = now - timedelta(weeks=weeks)
# Query for active adoption notices that were checked in the last three weeks
unchecked_adoptions = AdoptionNotice.objects.filter(
last_checked__gte=three_weeks_ago
)
active_unchecked_adoptions = [adoption for adoption in unchecked_adoptions if adoption.is_active]
return active_unchecked_adoptions
def deactivate_unchecked_adoption_notices():
for adoption_notice in get_unchecked_adoption_notices(weeks=3):
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).deactivate_unchecked()

View File

@@ -7,7 +7,6 @@ from notfellchen import __version__ as nf_version
from notfellchen import settings
def calculate_distance_between_coordinates(position1, position2):
"""
Calculate the distance between two points identified by coordinates
@@ -65,7 +64,8 @@ class GeoAPI:
def get_coordinates_from_query(self, location_string):
try:
result = self.requests.get(self.api_url, {"q": location_string, "format": "jsonv2"}, headers=self.headers).json()[0]
result = \
self.requests.get(self.api_url, {"q": location_string, "format": "jsonv2"}, headers=self.headers).json()[0]
except IndexError:
return None
return result["lat"], result["lon"]
@@ -77,9 +77,9 @@ class GeoAPI:
def get_geojson_for_query(self, location_string):
try:
result = self.requests.get(self.api_url,
{"q": location_string,
"format": "jsonv2"},
headers=self.headers).json()
{"q": location_string,
"format": "jsonv2"},
headers=self.headers).json()
except Exception as e:
logging.warning(f"Exception {e} when querying Nominatim")
return None

View File

@@ -1,4 +1,8 @@
import datetime as datetime
import logging
from notfellchen import settings
import requests
def pluralize(number, letter="e"):
@@ -11,11 +15,11 @@ def pluralize(number, letter="e"):
def age_as_hr_string(age: datetime.timedelta) -> str:
days = age.days
weeks = age.days/7
months = age.days/30
years = age.days/365
weeks = age.days / 7
months = age.days / 30
years = age.days / 365
if years >= 1:
months = months - 12*years
months = months - 12 * years
return f'{years:.0f} Jahr{pluralize(years)} und {months:.0f} Monat{pluralize(months)}'
elif months >= 3:
return f'{months:.0f} Monat{pluralize(months)}'
@@ -23,3 +27,10 @@ def age_as_hr_string(age: datetime.timedelta) -> str:
return f'{weeks:.0f} Woche{pluralize(weeks, "n")}'
else:
return f'{days:.0f} Tag{pluralize(days)}'
def healthcheck_ok():
try:
requests.get(settings.HEALTHCHECKS_URL, timeout=10)
except requests.RequestException as e:
logging.error("Ping to healthcheck-server failed: %s" % e)

View File

@@ -79,5 +79,9 @@ urlpatterns = [
#########
path('api/', include('fellchensammlung.api.urls')),
###################
## External Site ##
###################
path('external-site/', views.external_site_warning, name="external-site"),
]

View File

@@ -13,14 +13,16 @@ from notfellchen import settings
from fellchensammlung import logger
from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
User, Location, AdoptionNoticeStatus, Subscriptions, CommentNotification, BaseNotification, RescueOrganization, Species
User, Location, AdoptionNoticeStatus, Subscriptions, CommentNotification, BaseNotification, RescueOrganization, \
Species, Log, Timestamp
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
CommentForm, ReportCommentForm, AnimalForm, \
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
from .models import Language, Announcement
from .tools.geo import GeoAPI
from .tools.metrics import gather_metrics_data
from .tools.admin import clean_locations
from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices
from .tasks import add_adoption_notice_location
def user_is_trust_level_or_above(user, trust_level=User.MODERATOR):
@@ -46,12 +48,9 @@ def index(request):
lang = Language.objects.get(languagecode=language_code)
active_announcements = Announcement.get_active_announcements(lang)
context = {"adoption_notices": active_adoptions[:5], "adoption_notices_map": active_adoptions, "announcements": active_announcements}
for text_code in ["how_to", "introduction"]:
try:
context[text_code] = Text.objects.get(text_code=text_code, language=lang, )
except Text.DoesNotExist:
context[text_code] = None
context = {"adoption_notices": active_adoptions[:5], "adoption_notices_map": active_adoptions,
"announcements": active_announcements}
Text.get_texts(["how_to", "introduction"], lang, context)
return render(request, 'fellchensammlung/index.html', context=context)
@@ -76,11 +75,13 @@ def change_language(request):
def adoption_notice_detail(request, adoption_notice_id):
adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id)
if request.user.is_authenticated:
try:
try:
subscription = Subscriptions.objects.get(owner=request.user, adoption_notice=adoption_notice)
is_subscribed = True
except Subscriptions.DoesNotExist:
is_subscribed = False
else:
is_subscribed = False
has_edit_permission = user_is_owner_or_trust_level(request.user, adoption_notice)
if request.method == 'POST':
action = request.POST.get("action")
@@ -94,6 +95,10 @@ def adoption_notice_detail(request, adoption_notice_id):
comment_instance.user = request.user
comment_instance.save()
"""Log"""
Log.objects.create(user=request.user, action="comment",
text=f"{request.user} hat Kommentar {comment_instance.pk} zur Vermittlung {adoption_notice_id} hinzugefügt")
# Auto-subscribe user to adoption notice
subscription, created = Subscriptions.objects.get_or_create(adoption_notice=adoption_notice,
owner=request.user)
@@ -104,9 +109,9 @@ def adoption_notice_detail(request, adoption_notice_id):
# Create a notification but only if the user is not the one that posted the comment
if subscription.owner != request.user:
notification = CommentNotification(user=subscription.owner,
title=f"{adoption_notice.name} - Neuer Kommentar",
text=f"{request.user}: {comment_instance.text}",
comment=comment_instance)
title=f"{adoption_notice.name} - Neuer Kommentar",
text=f"{request.user}: {comment_instance.text}",
comment=comment_instance)
notification.save()
else:
comment_form = CommentForm(instance=adoption_notice)
@@ -114,13 +119,13 @@ def adoption_notice_detail(request, adoption_notice_id):
Subscriptions.objects.create(owner=request.user, adoption_notice=adoption_notice)
is_subscribed = True
if action == "unsubscribe":
subscription.delete()
is_subscribed = False
subscription.delete()
is_subscribed = False
else:
raise PermissionDenied
else:
comment_form = CommentForm(instance=adoption_notice)
context = {"adoption_notice": adoption_notice,"comment_form": comment_form, "user": request.user,
context = {"adoption_notice": adoption_notice, "comment_form": comment_form, "user": request.user,
"has_edit_permission": has_edit_permission, "is_subscribed": is_subscribed}
return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)
@@ -141,6 +146,9 @@ def adoption_notice_edit(request, adoption_notice_id):
location = Location.get_location_from_string(adoption_notice_instance.location_string)
adoption_notice_instance.location = location
adoption_notice_instance.save()
"""Log"""
Log.objects.create(user=request.user, action="adoption_notice_edit", text=f"{request.user} hat Vermittlung {adoption_notice.pk} geändert")
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_instance.pk], ))
else:
form = AdoptionNoticeForm(instance=adoption_notice)
@@ -170,8 +178,9 @@ def search(request):
adoption_notices_in_distance = active_adoptions
else:
adoption_notices_in_distance = [a for a in active_adoptions if a.in_distance(search_position, max_distance)]
context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form, "place_not_found": place_not_found}
context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form,
"place_not_found": place_not_found}
else:
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")
active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active]
@@ -183,36 +192,43 @@ def search(request):
@login_required
def add_adoption_notice(request):
if request.method == 'POST':
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(request.POST, request.FILES, in_adoption_notice_creation_flow=True)
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(request.POST, request.FILES,
in_adoption_notice_creation_flow=True)
if form.is_valid():
instance = form.save(commit=False)
instance.owner = request.user
"""Search the location given in the location string and add it to the adoption notice"""
location = Location.get_location_from_string(instance.location_string)
instance.location = location
instance.save()
"""Spin up a task that adds the location"""
add_adoption_notice_location.delay_on_commit(instance.pk)
# Set correct status
if request.user.trust_level >= User.TRUST_LEVEL[User.COORDINATOR]:
major_status = AdoptionNoticeStatus.ACTIVE
minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.ACTIVE]["searching"]
else:
major_status=AdoptionNoticeStatus.AWAITING_ACTION
minor_status=AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION]["waiting_for_review"]
major_status = AdoptionNoticeStatus.AWAITING_ACTION
minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION][
"waiting_for_review"]
status = AdoptionNoticeStatus.objects.create(major_status=major_status,
minor_status=minor_status,
adoption_notice=instance)
minor_status=minor_status,
adoption_notice=instance)
status.save()
# Get the species and number of animals from the form
# Get the species and number of animals from the form
species = form.cleaned_data["species"]
sex = form.cleaned_data["sex"]
num_animals = form.cleaned_data["num_animals"]
date_of_birth = form.cleaned_data["date_of_birth"]
for i in range(0, num_animals):
Animal.objects.create(owner=request.user,
name=f"{species} {i+1}", adoption_notice=instance, species=species, sex=sex, date_of_birth=date_of_birth)
name=f"{species} {i + 1}", adoption_notice=instance, species=species, sex=sex,
date_of_birth=date_of_birth)
"""Log"""
Log.objects.create(user=request.user, action="add_adoption_notice",
text=f"{request.user} hat Vermittlung {instance.pk} hinzugefügt")
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
else:
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
@@ -257,6 +273,11 @@ def add_photo_to_animal(request, animal_id):
instance.save()
animal.photos.add(instance)
"""Log"""
Log.objects.create(user=request.user, action="add_photo_to_animal",
text=f"{request.user} hat Foto {instance.pk} zum Tier {animal.pk} hinzugefügt")
if "save-and-add-another" in request.POST:
form = ImageForm(in_flow=True)
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
@@ -280,6 +301,9 @@ def add_photo_to_adoption_notice(request, adoption_notice_id):
instance.owner = request.user
instance.save()
adoption_notice.photos.add(instance)
"""Log"""
Log.objects.create(user=request.user, action="add_photo_to_animal",
text=f"{request.user} hat Foto {instance.pk} zur Vermittlung {adoption_notice.pk} hinzugefügt")
if "save-and-add-another" in request.POST:
form = ImageForm(in_flow=True)
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
@@ -306,6 +330,10 @@ def animal_edit(request, animal_id):
if form.is_valid():
animal = form.save()
"""Log"""
Log.objects.create(user=request.user, action="add_photo_to_animal",
text=f"{request.user} hat Tier {animal.pk} zum Tier geändert")
return redirect(reverse("animal-detail", args=[animal.pk], ))
else:
form = AnimalForm(instance=animal)
@@ -423,8 +451,10 @@ def modqueue(request):
context = {"reports": open_reports}
return render(request, 'fellchensammlung/modqueue.html', context=context)
@login_required
def updatequeue(request):
#TODO: Make sure update can only be done for instances with permission
if request.method == "POST":
print(request.POST.get("adoption_notice_id"))
adoption_notice = AdoptionNotice.objects.get(id=request.POST.get("adoption_notice_id"))
@@ -440,14 +470,14 @@ def updatequeue(request):
last_checked_adoption_list = AdoptionNotice.objects.order_by("last_checked")
else:
last_checked_adoption_list = AdoptionNotice.objects.filter(owner=request.user).order_by("last_checked")
adoption_notices = [adoption for adoption in last_checked_adoption_list if adoption.is_active]
adoption_notices = [adoption for adoption in last_checked_adoption_list if adoption.is_active or adoption.is_to_be_checked]
context = {"adoption_notices": adoption_notices}
return render(request, 'fellchensammlung/updatequeue.html', context=context)
def map(request):
adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active
adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active
context = {"adoption_notices_map": adoption_notices}
return render(request, 'fellchensammlung/map.html', context=context)
@@ -456,6 +486,7 @@ def metrics(request):
data = gather_metrics_data()
return JsonResponse(data)
@login_required
def instance_health_check(request):
"""
@@ -465,16 +496,20 @@ def instance_health_check(request):
action = request.POST.get("action")
if action == "clean_locations":
clean_locations(quiet=False)
elif action == "deactivate_unchecked_adoption_notices":
deactivate_unchecked_adoption_notices()
number_of_adoption_notices = AdoptionNotice.objects.all().count()
none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
number_not_geocoded_adoption_notices = len(none_geocoded_adoption_notices)
number_of_rescue_orgs = RescueOrganization.objects.all().count()
none_geocoded_rescue_orgs = RescueOrganization.objects.filter(location__isnull=True)
number_not_geocoded_rescue_orgs = len(none_geocoded_rescue_orgs)
unchecked_ans = get_unchecked_adoption_notices()
number_unchecked_ans = len(unchecked_ans)
# CHECK FOR MISSING TEXTS
languages = Language.objects.all()
texts = Text.objects.all()
@@ -487,6 +522,9 @@ def instance_health_check(request):
except Text.DoesNotExist:
missing_texts.append((text_code, language))
# Timestamps
timestamps = Timestamp.objects.all()
context = {
"number_of_adoption_notices": number_of_adoption_notices,
"number_not_geocoded_adoption_notices": number_not_geocoded_adoption_notices,
@@ -494,10 +532,20 @@ def instance_health_check(request):
"number_of_rescue_orgs": number_of_rescue_orgs,
"number_not_geocoded_rescue_orgs": number_not_geocoded_rescue_orgs,
"none_geocoded_rescue_orgs": none_geocoded_rescue_orgs,
"missing_texts": missing_texts
"missing_texts": missing_texts,
"number_unchecked_ans": number_unchecked_ans,
"unchecked_ans": unchecked_ans,
"timestamps": timestamps
}
return render(request, 'fellchensammlung/instance-health-check.html', context=context)
def external_site_warning(request):
url = request.GET.get("url")
context = {"url": url}
language_code = translation.get_language()
lang = Language.objects.get(languagecode=language_code)
Text.get_texts(["external_site_warning", "good_adoption_practices"], language=lang)
return render(request, 'fellchensammlung/external_site_warning.html', context=context)

View File

@@ -1 +1,8 @@
__version__ = "0.2.0"
__version__ = "0.3.0"
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)

29
src/notfellchen/celery.py Normal file
View File

@@ -0,0 +1,29 @@
import os
from celery import Celery
from celery.schedules import crontab
from notfellchen import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'notfellchen.settings')
app = Celery('notfellchen')
# Load task modules from all registered Django app configs.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
app.conf.beat_schedule = {
'daily-cleanup': {
'task': 'admin.clean_locations',
'schedule': crontab(hour=2),
},
'daily-deactivation': {
'task': 'admin.deactivate_unchecked',
'schedule': crontab(hour=1),
},
}
if settings.HEALTHCHECKS_URL is not None and settings.HEALTHCHECKS_URL != "":
# If a healthcheck is configured, this will send an hourly ping to the healthchecks server
app.conf.beat_schedule['hourly-healthcheck'] = {'task': 'tools.healthcheck',
'schedule': crontab(minute=43),
}

View File

@@ -14,6 +14,7 @@ from pathlib import Path
import os
import configparser
from django.utils.translation import gettext_lazy as _
from celery import Celery
"""CONFIG PARSER """
config = configparser.RawConfigParser()
@@ -79,6 +80,13 @@ DB_HOST = config.get("database", "host", fallback='')
BASE_DIR = Path(__file__).resolve().parent.parent
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
""" CELERY + KEYDB """
CELERY_BROKER_URL = config.get("celery", "broker", fallback="redis://localhost:6379/0")
CELERY_RESULT_BACKEND = config.get("celery", "backend", fallback="redis://localhost:6379/0")
""" MONITORING """
HEALTHCHECKS_URL = config.get("monitoring", "healthchecks_url", fallback=None)
""" GEOCODING """
GEOCODING_API_URL = config.get("geocoding", "api_url", fallback="https://nominatim.hyteck.de/search")
""" Tile Server """