Skip to content

Commit

Permalink
Merge pull request #9 from evinjaff/issue-4
Browse files Browse the repository at this point in the history
Resolve Issue 4 and others
  • Loading branch information
evinjaff authored Jun 4, 2024
2 parents bc1aec2 + 11e5de1 commit 47ad48e
Show file tree
Hide file tree
Showing 42 changed files with 17,997 additions and 56 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,7 @@ FodyWeavers.xsd
*.sln.iml

server/venv/

.DS_Store

server/egglocke/db.sqlite3
29 changes: 29 additions & 0 deletions server/egglocke/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use Python 3 as a base image
FROM python:3

# Set the working directory to /usr/src/app
WORKDIR /usr/src/app

# install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# copy the current directory contents into the container at /usr/src/app
COPY . /usr/src/app

# TODO: add production settings for Django

# run and make migrations
RUN python manage.py makemigrations
RUN python manage.py migrate

# set debug to false
ENV DEBUG=False

# run debug server
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000" ]

EXPOSE 8000
# debug, expose all ports
EXPOSE 0-65535

Binary file removed server/egglocke/db.sqlite3
Binary file not shown.
3 changes: 3 additions & 0 deletions server/egglocke/docker-command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker build -t server .

docker run -d -it -p 8000:8000 server
23 changes: 22 additions & 1 deletion server/egglocke/egglocke/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
"20.42.93.202",
"egglocke.evievi.gay",
"localhost",
"127.0.0.1"
]

CSRF_TRUSTED_ORIGINS = [
"https://polite-snails-cross.loca.lt",
"https://polite-snails-cross.loca.lt/"
]


# Application definition
Expand Down Expand Up @@ -122,3 +132,14 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Set up a Cache Backend
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}

# Custom settings
POKEMON_GENERATION = 4
26 changes: 26 additions & 0 deletions server/egglocke/egglocke/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.test import TestCase
from django.urls import reverse

from http import HTTPStatus


class RobotTxtTests(TestCase):
def test_robots_txt_view(self):
response = self.client.get("/robots.txt")

assert response.status_code == HTTPStatus.OK
assert response["content-type"] == "text/plain"

valid_user_agent_headers = [ "User-Agent", "user-agent", "USER-AGENT", "User-agent" ]
valid_header_seen = False

for header in valid_user_agent_headers:
if header in response.content.decode():
valid_header_seen = True
break

assert valid_header_seen

def test_cannot_access_robots_txt_view_with_post(self):
response = self.client.post("/robots.txt")
self.assertEqual(response.status_code, 405)
4 changes: 3 additions & 1 deletion server/egglocke/egglocke/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"""
from django.contrib import admin
from django.urls import path, include
from pokepoll.views import robots_txt_view

urlpatterns = [
path("pokepoll/", include("pokepoll.urls")),
path('admin/', admin.site.urls)
path('admin/', admin.site.urls),
path("robots.txt", robots_txt_view),
]
5 changes: 3 additions & 2 deletions server/egglocke/pokepoll/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin

# Register your models here.
from .models import Question
from .models import Pokemon, Submitter

admin.site.register(Question)
admin.site.register(Pokemon)
admin.site.register(Submitter)
53 changes: 53 additions & 0 deletions server/egglocke/pokepoll/cachedconstants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json

# Constants

ALL_POKEMON_NAMES = [
]

MAX_POKEDEX_DICT = {
1: 151,
2: 251,
3: 386,
4: 493,
5: 649,
6: 721,
7: 809,
8: 898,
}

POKEMON_NAME_TO_ID = {
}

def import_json(filepath):
with open(filepath, 'r') as f:
data = json.load(f)
return data


def main():

# Derive constant JSON files from static/pokepoll/pokemdex.json
pokedex = import_json('static/pokepoll/pokedex.json')

# file 1: all_pokemon_names.json
all_pokemon_names = []
for pokemon in pokedex:
all_pokemon_names.append(pokemon['name']["english"])

# file 2: pokemon_name_to_id.json
pokemon_name_to_id = {}
for pokemon in pokedex:
pokemon_name_to_id[pokemon['name']["english"]] = pokemon['id']

with open('static/pokepoll/pokemon_name_to_id.json', 'w') as f:
json.dump(pokemon_name_to_id, f)

with open('static/pokepoll/all_pokemon_names.json', 'w') as f:
json.dump(all_pokemon_names, f)




if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.6 on 2024-05-27 04:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('pokepoll', '0001_initial'),
]

operations = [
migrations.RenameModel(
old_name='Question',
new_name='Pokemon',
),
]
41 changes: 41 additions & 0 deletions server/egglocke/pokepoll/migrations/0003_submitter_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.0.6 on 2024-05-27 04:47

import django.db.models.deletion
import pokepoll.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pokepoll', '0002_rename_question_pokemon'),
]

operations = [
migrations.CreateModel(
name='Submitter',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('email', models.EmailField(max_length=254)),
],
),
migrations.RenameField(
model_name='pokemon',
old_name='question_text',
new_name='pokemon_nickname',
),
migrations.AddField(
model_name='pokemon',
name='pokemon_species',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='pokemon',
name='submitter',
field=models.ForeignKey(default=pokepoll.models.Submitter.get_default_parent_key, on_delete=django.db.models.deletion.CASCADE, to='pokepoll.submitter'),
),
migrations.DeleteModel(
name='Choice',
),
]
18 changes: 18 additions & 0 deletions server/egglocke/pokepoll/migrations/0004_alter_submitter_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-05-27 08:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pokepoll', '0003_submitter_and_more'),
]

operations = [
migrations.AlterField(
model_name='submitter',
name='email',
field=models.EmailField(max_length=254, unique=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generated by Django 5.0.6 on 2024-05-27 09:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pokepoll', '0004_alter_submitter_email'),
]

operations = [
migrations.AddField(
model_name='pokemon',
name='pokemon_EV',
field=models.JSONField(default=list),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_IV',
field=models.JSONField(default=list),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_OT',
field=models.CharField(default='Red', max_length=10),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_OTGender',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_ability',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_ball',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_language',
field=models.IntegerField(default=2),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_moves',
field=models.JSONField(default=list),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_movespp',
field=models.JSONField(default=list),
),
migrations.AddField(
model_name='pokemon',
name='pokemon_nature',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='pokemon',
name='upvotes',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='pokemon',
name='pokemon_nickname',
field=models.CharField(default='', max_length=10),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.6 on 2024-05-27 09:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pokepoll', '0005_pokemon_pokemon_ev_pokemon_pokemon_iv_and_more'),
]

operations = [
migrations.AlterField(
model_name='pokemon',
name='pokemon_EV',
field=models.JSONField(default=[0, 0, 0, 0, 0, 0]),
),
migrations.AlterField(
model_name='pokemon',
name='pokemon_IV',
field=models.JSONField(default=[31, 31, 31, 31, 31, 31]),
),
]
Loading

0 comments on commit 47ad48e

Please sign in to comment.