Skip to content

Commit

Permalink
Merge pull request #356 from seanmorley15/development
Browse files Browse the repository at this point in the history
AdventureLog v0.7.1
  • Loading branch information
seanmorley15 authored Nov 13, 2024
2 parents 7cd869a + c3f37b6 commit 0ea948c
Show file tree
Hide file tree
Showing 117 changed files with 5,694 additions and 253,177 deletions.
28 changes: 27 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
{
"git.ignoreLimitWarning": true
"git.ignoreLimitWarning": true,
"i18n-ally.localesPaths": [
"frontend/src/locales",
"backend/server/backend/lib/python3.12/site-packages/allauth/locale",
"backend/server/backend/lib/python3.12/site-packages/dj_rest_auth/locale",
"backend/server/backend/lib/python3.12/site-packages/rest_framework/locale",
"backend/server/backend/lib/python3.12/site-packages/rest_framework_simplejwt/locale",
"backend/server/backend/lib/python3.12/site-packages/django/conf/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/messages",
"backend/server/backend/lib/python3.12/site-packages/allauth/templates/account/messages",
"backend/server/backend/lib/python3.12/site-packages/allauth/templates/mfa/messages",
"backend/server/backend/lib/python3.12/site-packages/allauth/templates/socialaccount/messages",
"backend/server/backend/lib/python3.12/site-packages/allauth/templates/usersessions/messages",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/admindocs/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/auth/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/admin/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/contenttypes/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/flatpages/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/humanize/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/gis/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/redirects/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/postgres/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/sessions/locale",
"backend/server/backend/lib/python3.12/site-packages/django/contrib/sites/locale",
"backend/server/backend/lib/python3.12/site-packages/rest_framework/templates/rest_framework/docs/langs"
],
"i18n-ally.keystyle": "nested"
}
54 changes: 13 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,23 @@ Here is a summary of the configuration options available in the `docker-compose.
| Name | Required | Description | Default Value |
| ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `PUBLIC_SERVER_URL` | Yes | What the frontend SSR server uses to connect to the backend. | http://server:8000 |
| `ORIGIN` | Sometimes | Not needed if using HTTPS. If not, set it to the domain of what you will acess the app from. | http://localhost:8080 |
| `ORIGIN` | Sometimes | Not needed if using HTTPS. If not, set it to the domain of what you will acess the app from. | http://localhost:8015 |
| `BODY_SIZE_LIMIT` | Yes | Used to set the maximum upload size to the server. Should be changed to prevent someone from uploading too much! Custom values must be set in **kiliobytes**. | Infinity |

### Backend Container (server)

| Name | Required | Description | Default Value |
| ----------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `PGHOST` | Yes | Databse host. | db |
| `PGDATABASE` | Yes | Database. | database |
| `PGUSER` | Yes | Database user. | adventure |
| `PGPASSWORD` | Yes | Database password. | changeme123 |
| `DJANGO_ADMIN_USERNAME` | Yes | Default username. | admin |
| `DJANGO_ADMIN_PASSWORD` | Yes | Default password, change after inital login. | admin |
| `DJANGO_ADMIN_EMAIL` | Yes | Default user's email. | [email protected] |
| `PUBLIC_URL` | Yes | This is the publically accessible url to the **nginx** container. You should be able to acess nginx from this url where you access your app. | http://127.0.0.1:81 |
| `CSRF_TRUSTED_ORIGINS` | Yes | Need to be changed to the orgins where you use your backend server and frontend. These values are comma seperated. | Needs to be changed. |
| `FRONTEND_URL` | Yes | This is the publically accessible url to the **frontend** container. This link should be accessable for all users. Used for email generation. | http://localhost:3000 |

### Proxy Container (nginx) Configuration

In order to use media files in a production environment, you need to configure the `nginx` container to serve the media files. The container is already in the docker compose file but you need to do a few things to make it work.

1. Create a directory called `proxy` in the same directory as the `docker-compose.yml` file.
2. Create a file called `nginx.conf` in the `proxy` directory.
3. Add the following configuration to the `nginx.conf` file:

```nginx
server {
listen 80;
server_name localhost;
location /media/ {
alias /app/media/;
}
}
```
| Name | Required | Description | Default Value |
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| `PGHOST` | Yes | Databse host. | db |
| `PGDATABASE` | Yes | Database. | database |
| `PGUSER` | Yes | Database user. | adventure |
| `PGPASSWORD` | Yes | Database password. | changeme123 |
| `DJANGO_ADMIN_USERNAME` | Yes | Default username. | admin |
| `DJANGO_ADMIN_PASSWORD` | Yes | Default password, change after inital login. | admin |
| `DJANGO_ADMIN_EMAIL` | Yes | Default user's email. | [email protected] |
| `PUBLIC_URL` | Yes | This needs to match the outward port of the server and be accessible from where the app is used. It is used for the creation of image urls. | 'http://localhost:8016' |
| `CSRF_TRUSTED_ORIGINS` | Yes | Need to be changed to the orgins where you use your backend server and frontend. These values are comma seperated. | http://localhost:8016 |
| `FRONTEND_URL` | Yes | This is the publicly accessible url to the **frontend** container. This link should be accessible for all users. Used for email generation. | 'http://localhost:8015' |

## Running the Containers

Expand Down Expand Up @@ -119,8 +100,6 @@ View all of your adventures on a map, with the ability to filter by visit status

![Region Page](screenshots/regions.png)


# About AdventureLog

AdventureLog is a Svelte Kit and Django application that utilizes a PostgreSQL database. Users can log the adventures they have experienced, as well as plan future ones. Key features include:
Expand Down Expand Up @@ -152,10 +131,3 @@ AdventureLog is licensed under the GNU General Public License v3.0.

- Logo Design by [redtechtiger](https://github.com/redtechtiger)
- WorldTravel Dataset [dr5hn/countries-states-cities-database](https://github.com/dr5hn/countries-states-cities-database)
- [Mexico GEOJSON](https://cartographyvectors.com/map/784-mexico-with-states)
- [Japan GEOJSON](https://cartographyvectors.com/map/361-japan)
- [Ireland GEOJSON](https://cartographyvectors.com/map/1399-ireland-provinces)
- [Sweden GEOJSON](https://cartographyvectors.com/map/1521-sweden-with-regions)
- [Switzerland GEOJSON](https://cartographyvectors.com/map/1522-switzerland-with-regions)
- [Iceland GEOJSON](https://cartographyvectors.com/map/1453-iceland-with-regions)
- [Austria GEOJSON](https://github.com/codeforgermany/click_that_hood/blob/main/public/data/austria-states.geojson)
1 change: 0 additions & 1 deletion backend/AUTHORS

This file was deleted.

28 changes: 20 additions & 8 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Dockerfile

# Use the official Python slim image as the base image
FROM python:3.10-slim

LABEL Developers="Sean Morley"
Expand All @@ -11,23 +10,36 @@ ENV PYTHONUNBUFFERED 1
# Set the working directory
WORKDIR /code

# Install system dependencies
# Install system dependencies (Nginx included)
RUN apt-get update \
&& apt-get install -y git postgresql-client gdal-bin libgdal-dev \
&& apt-get clean
&& apt-get install -y git postgresql-client gdal-bin libgdal-dev nginx \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY ./server/requirements.txt /code/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install --upgrade pip \
&& pip install -r requirements.txt

# Create necessary directories
RUN mkdir -p /code/static /code/media
# RUN mkdir -p /code/staticfiles /code/media

# Copy the Django project code into the Docker image
COPY ./server /code/

# Copy Nginx configuration
COPY ./nginx.conf /etc/nginx/nginx.conf

# Collect static files
RUN python3 manage.py collectstatic --noinput --verbosity 2

# Set the entrypoint script
COPY ./entrypoint.sh /code/entrypoint.sh
RUN chmod +x /code/entrypoint.sh
ENTRYPOINT ["/code/entrypoint.sh"]

# Expose ports for NGINX and Gunicorn
EXPOSE 80 8000

# Command to start Nginx and Gunicorn
CMD ["bash", "-c", "service nginx start && /code/entrypoint.sh"]
8 changes: 7 additions & 1 deletion backend/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
The MIT License (MIT)
# Preface

AdventureLog uses DjRestAuth, a Django REST Framework authentication backend for Django Rest Framework. DjRestAuth is licensed under the MIT License.

---

## The MIT License (MIT)

Copyright (c) 2014 iMerica https://github.com/iMerica/

Expand Down
5 changes: 0 additions & 5 deletions backend/MANIFEST.in

This file was deleted.

6 changes: 4 additions & 2 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ fi
# Sync the countries and world travel regions
python manage.py download-countries

# Start Django server
python manage.py runserver 0.0.0.0:8000
cat /code/adventurelog.txt

# Start gunicorn
gunicorn main.wsgi:application --bind 0.0.0.0:8000
38 changes: 38 additions & 0 deletions backend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
worker_processes 1;
events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

upstream django {
server server:8000; # Use the internal Docker networking
}

server {
listen 80; # NGINX always listens on port 80 inside the container
server_name localhost;

location / {
proxy_pass http://server:8000; # Explicitly forward to Django service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}


location /static/ {
alias /code/staticfiles/; # Serve static files directly
}

location /media/ {
alias /code/media/; # Serve media files directly
}
}
}
7 changes: 7 additions & 0 deletions backend/server/adventurelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
█████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗████████╗██╗ ██╗██████╗ ███████╗██╗ ██████╗ ██████╗
██╔══██╗██╔══██╗██║ ██║██╔════╝████╗ ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██║ ██╔═══██╗██╔════╝
███████║██║ ██║██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ██║██████╔╝█████╗ ██║ ██║ ██║██║ ███╗
██╔══██║██║ ██║╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██╔══██╗██╔══╝ ██║ ██║ ██║██║ ██║
██║ ██║██████╔╝ ╚████╔╝ ███████╗██║ ╚████║ ██║ ╚██████╔╝██║ ██║███████╗███████╗╚██████╔╝╚██████╔╝
╚═╝ ╚═╝╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝
“The world is full of wonderful things you haven't seen yet. Don't ever give up on the chance of seeing them.” - J.K. Rowling
4 changes: 0 additions & 4 deletions backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ class Adventure(models.Model):
# end_date = models.DateField(blank=True, null=True)

def clean(self):
if self.date and self.end_date and self.date > self.end_date:
raise ValidationError('The start date must be before the end date. Start date: ' + str(self.date) + ' End date: ' + str(self.end_date))
if self.end_date and not self.date:
raise ValidationError('Adventures must have an end date. Adventure: ' + self.name)
if self.collection:
if self.collection.is_public and not self.is_public:
raise ValidationError('Adventures associated with a public collection must be public. Collection: ' + self.trip.name + ' Adventure: ' + self.name)
Expand Down
22 changes: 18 additions & 4 deletions backend/server/adventures/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils import timezone
import os
from .models import Adventure, AdventureImage, ChecklistItem, Collection, Note, Transportation, Checklist, Visit
from rest_framework import serializers
Expand All @@ -19,18 +20,30 @@ def to_representation(self, instance):
return representation

class VisitSerializer(serializers.ModelSerializer):

class Meta:
model = Visit
fields = ['id', 'start_date', 'end_date', 'notes']
read_only_fields = ['id']

class AdventureSerializer(serializers.ModelSerializer):
images = AdventureImageSerializer(many=True, read_only=True)
visits = VisitSerializer(many=True, read_only=False)
is_visited = serializers.SerializerMethodField()
class Meta:
model = Adventure
fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude', 'visits']
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']
fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude', 'visits', 'is_visited']
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id', 'is_visited']

def get_is_visited(self, obj):
current_date = timezone.now().date()
for visit in obj.visits.all():
if visit.start_date and visit.end_date and (visit.start_date <= current_date):
return True
elif visit.start_date and not visit.end_date and (visit.start_date <= current_date):
return True
return False


def to_representation(self, instance):
representation = super().to_representation(instance)
Expand Down Expand Up @@ -186,4 +199,5 @@ def to_representation(self, instance):
for user in instance.shared_with.all():
shared_uuids.append(str(user.uuid))
representation['shared_with'] = shared_uuids
return representation
return representation

3 changes: 2 additions & 1 deletion backend/server/adventures/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import include, path
from rest_framework.routers import DefaultRouter
from .views import AdventureViewSet, ChecklistViewSet, CollectionViewSet, NoteViewSet, StatsViewSet, GenerateDescription, ActivityTypesView, TransportationViewSet, AdventureImageViewSet
from .views import AdventureViewSet, ChecklistViewSet, CollectionViewSet, NoteViewSet, StatsViewSet, GenerateDescription, ActivityTypesView, TransportationViewSet, AdventureImageViewSet, ReverseGeocodeViewSet

router = DefaultRouter()
router.register(r'adventures', AdventureViewSet, basename='adventures')
Expand All @@ -12,6 +12,7 @@
router.register(r'notes', NoteViewSet, basename='notes')
router.register(r'checklists', ChecklistViewSet, basename='checklists')
router.register(r'images', AdventureImageViewSet, basename='images')
router.register(r'reverse-geocode', ReverseGeocodeViewSet, basename='reverse-geocode')


urlpatterns = [
Expand Down
Loading

0 comments on commit 0ea948c

Please sign in to comment.