-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from City-of-Turku/feature/initial-project
Feature/initial project
- Loading branch information
Showing
88 changed files
with
5,264 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
**/__pycache__ | ||
**/.venv | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md | ||
/postgres-data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,9 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# static files | ||
static/ | ||
|
||
# Django project | ||
.django_secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
# mpbackend | ||
Mobility Profile Backend | ||
# Mobility Profile Backend | ||
This is the backend for the Mobility Profile | ||
|
||
## Installation with Docker Compose | ||
First configure development environment settings as stated in `config_dev.env.example`. | ||
|
||
### Running the application | ||
Run application with `docker-compose up` | ||
This will startup and bind local postgres and mobilityprofile backend. | ||
|
||
### Runnig the application in production | ||
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up | ||
|
||
### Importing questions | ||
To import questions run: `docker-compose run mpbackend import_questions` | ||
|
||
|
||
## Installation without Docker | ||
1. | ||
First, install the necessary Debian packages. | ||
TODO, add packages. | ||
|
||
2. Clone the repository. | ||
``` | ||
git clone https://github.com/City-of-Turku/mpbackend.git | ||
``` | ||
3. Install python 3.10 and pip requiremends | ||
Be sure to load the **environment** before installing the requirements. | ||
``` | ||
pip install pip-tools | ||
pip install -r requirements.txt | ||
``` | ||
4. Setup the PostGIS database. | ||
|
||
Please note, we recommend PostgreSQL version 13 or higher. | ||
Local setup: | ||
|
||
``` | ||
sudo su postgres | ||
psql template1 -c 'CREATE EXTENSION IF NOT EXISTS postgis;' | ||
createuser -RSPd mobilityprofile | ||
createdb -O mobilityprofile -T template1 -l fi_FI.UTF-8 -E utf8 mobilityprofile | ||
``` | ||
|
||
5. Create database tables. | ||
``` | ||
./manage.py migrate | ||
``` | ||
|
||
6. Import questions | ||
``` | ||
./manage.py import_questions | ||
``` | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django import forms | ||
from django.contrib import admin | ||
|
||
from .models import MailingList, Profile, User | ||
|
||
admin.site.register(User) | ||
|
||
|
||
class ProfileAdmin(admin.ModelAdmin): | ||
list_display = ("user", "result") | ||
|
||
def result(self, obj): | ||
if obj.user.result: | ||
return obj.user.result.value | ||
else: | ||
return None | ||
|
||
|
||
class MailingListAdminForm(forms.ModelForm): | ||
csv_emails = forms.CharField(widget=forms.Textarea(attrs={"rows": 20, "cols": 120})) | ||
|
||
class Meta: | ||
model = MailingList | ||
fields = ["result"] | ||
|
||
|
||
class MailingListAdmin(admin.ModelAdmin): | ||
list_display = ("result", "csv_emails") | ||
|
||
readonly_fields = ("result",) | ||
form = MailingListAdminForm | ||
|
||
def csv_emails(self, obj): | ||
return obj.csv_emails | ||
|
||
def get_form(self, request, obj=None, **kwargs): | ||
form = super().get_form(request, obj, **kwargs) | ||
form.base_fields["csv_emails"].initial = self.csv_emails(obj) | ||
return form | ||
|
||
def change_view(self, request, object_id, form_url="", extra_context=None): | ||
extra_context = extra_context or {} | ||
extra_context["show_save_and_add_another"] = False | ||
extra_context["show_save_and_continue"] = False | ||
return super().change_view( | ||
request, object_id, form_url, extra_context=extra_context | ||
) | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
return False | ||
|
||
|
||
admin.site.register(Profile, ProfileAdmin) | ||
admin.site.register(MailingList, MailingListAdmin) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.contrib.auth import get_user_model | ||
from rest_framework import serializers | ||
|
||
from account.models import MailingListEmail, Profile | ||
|
||
|
||
class SubscribeSerializer(serializers.Serializer): | ||
email = serializers.CharField() | ||
result = serializers.IntegerField() | ||
|
||
|
||
class UnSubscribeSerializer(serializers.Serializer): | ||
email = serializers.CharField() | ||
|
||
|
||
class PublicUserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = get_user_model() | ||
fields = ["id"] | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = get_user_model() | ||
fields = [ | ||
"id", | ||
"username", | ||
"email", | ||
"first_name", | ||
"last_name", | ||
"last_login", | ||
"date_joined", | ||
"is_staff", | ||
"is_active", | ||
"email_verified", | ||
] | ||
|
||
|
||
class ProfileSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = Profile | ||
fields = [ | ||
"id", | ||
"year_of_birth", | ||
"postal_code", | ||
"optional_postal_code", | ||
"is_filled_for_fun", | ||
"result_can_be_used", | ||
] | ||
|
||
|
||
class MailingListEmailSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = MailingListEmail | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.urls import include, path | ||
from rest_framework import routers | ||
|
||
from . import views | ||
|
||
app_name = "account" | ||
|
||
# Create a router and register our viewsets with it. | ||
router = routers.DefaultRouter() | ||
router.register("profile", views.ProfileViewSet, "profiles") | ||
|
||
# The API URLs are now determined automatically by the router. | ||
urlpatterns = [path("", include(router.urls), name="account")] |
Oops, something went wrong.