diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bfd854c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +venv/ +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e82f82 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Python runtime as the base image +FROM python:3.10-alpine + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set the working directory in the container +WORKDIR /women_blog_site + +# Copy the requirements file and install dependencies +COPY requirements.txt /women_blog_site/ +RUN pip install --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the project code into the container +COPY . /women_blog_site/ + +# Expose the port that the Django development server will be listening on +EXPOSE 8000 + +# Run the Django development server +CMD ["python", "coolsite/manage.py", "runserver", "0.0.0.0:8000"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7b7fe71 --- /dev/null +++ b/Makefile @@ -0,0 +1,90 @@ +.PHONY: help\ + run \ + shell \ + mdb \ + db \ + web.up\ + web.stop\ + web.down\ + web.shell\ + web.db.shell\ + web.logs\ + web.db\ + web.fill_db\ + web.flush\ + web.user\ + web.def_user\ + web.install\ + + +PIP_VERSION = 22.0.4 + +help: ## Show available make targets and their descriptions + @echo "Available make targets:" + @echo "" + @awk 'BEGIN {FS = ":.*?## "}; /^[\$$\(\)\/\.0-9A-Za-z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +requirements: venv/bin/activate ## install requirements + /venv/bin/activate; pip install -r requirements.txt + +run: venv/bin/activate ## Local Run + . venv/bin/activate; python coolsite/manage.py runserver + +shell: venv/bin/activate ## Run django shell + . venv/bin/activate; python coolsite/manage.py shell + +mdb: venv/bin/activate ## Make migrations + . venv/bin/activate; python coolsite/manage.py makemigrations + +db: venv/bin/activate ## Migrate to database + . venv/bin/activate; python coolsite/manage.py migrate + +web.up: venv/bin/activate ## create and run docker-compose container + . venv/bin/activate; docker-compose up + +web.stop: venv/bin/activate ## stop docker-compose services + . venv/bin/activate; docker-compose stop web && \ + . venv/bin/activate; docker-compose stop db + +web.down: venv/bin/activate ## down docker-compose container + . venv/bin/activate; docker-compose down + +web.shell: venv/bin/activate ## enter docker-compose Django app service shell + . venv/bin/activate && docker-compose exec web /bin/sh + +web.db.shell: venv/bin/activate ## enter docker-compose psql database shell shell + . venv/bin/activate; docker-compose exec db psql -U my_user -d my_database + # Get all tables names: + # SELECT table_name FROM information_schema.tables WHERE table_schema='public'; + +web.logs: venv/bin/activate ## enter docker-compose web service logs + . venv/bin/activate && docker-compose logs -f web + +web.db: venv/bin/activate ## migrate changes to db container + . venv/bin/activate; docker-compose exec web python coolsite/manage.py migrate + +web.fill_db: venv/bin/activate ## add test data to database in docker-compose service "psql" + . venv/bin/activate; docker-compose exec web python coolsite/manage.py fill_db + +web.flush: venv/bin/activate ## clear database in docker-compose service "psql" + . venv/bin/activate; docker-compose exec web python coolsite/manage.py flush --noinput + +web.user: venv/bin/activate ## create custom superuser in django app docker-compose service + . venv/bin/activate; docker-compose exec web python coolsite/manage.py createsuperuser + +web.def_user: venv/bin/activate ## create default superuser in django app docker-compose service + @echo "Now you can create a superuser and access the admin panel" + @read -p "Username: " username && \ + read -p "Email: " email && \ + read -s -p "Password: " password && \ + docker-compose exec web python coolsite/manage.py createsuperuser --noinput --username $$username --email $$email && \ + docker-compose exec web python coolsite/manage.py shell -c "from django.contrib.auth import get_user_model;\ + User = get_user_model(); user = User.objects.get(username='$$username'); \ + user.set_password('$$password'); user.save()" + +web.install: venv/bin/activate ## one-click installation (create and run container, add test data to db) + . venv/bin/activate; docker-compose up -d && \ + make web.db && \ + make web.fill_db && \ + make web.def_user && \ + make web.logs diff --git a/README.md b/README.md index eca1c27..6212d30 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Tools used during development: black, flake8 + git@github.com:KyryloKireiev/women_blog_site.git + All commands are in the Makefile + Django app in master branch using sqlite3 database ++ Detail installation instruction you can found in ```SETUP.md``` file ## One-clik installation diff --git a/coolsite/.DS_Store b/coolsite/.DS_Store index 8f0c87b..6329805 100644 Binary files a/coolsite/.DS_Store and b/coolsite/.DS_Store differ diff --git a/coolsite/Makefile b/coolsite/Makefile deleted file mode 100644 index 78dee2e..0000000 --- a/coolsite/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -.PHONY: run \ - shell \ - mdb \ - db \ - - -PIP_VERSION = 22.0.4 - - -run: ../venv/bin/activate ## Local Run - ../venv/bin/activate; python manage.py runserver - -shell: ../venv/bin/activate ## Run django shell - ../venv/bin/activate; python manage.py shell - - -mdb: ../venv/bin/activate ## Make migrations - ../venv/bin/activate; python manage.py makemigrations - - -db: ../venv/bin/activate ## Migrate to database - ../venv/bin/activate; python manage.py migrate - diff --git a/coolsite/__init__.py b/coolsite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coolsite/coolsite/settings.py b/coolsite/coolsite/settings.py index 64f88c2..a292571 100644 --- a/coolsite/coolsite/settings.py +++ b/coolsite/coolsite/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['localhost', '127.0.0.1', '0.0.0.0'] # Application definition @@ -82,8 +82,12 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'my_database', + 'USER': 'my_user', + 'PASSWORD': 'my_password', + 'HOST': "psql", + 'PORT': '5432', } } @@ -136,4 +140,6 @@ INTERNAL_IPS = [ "127.0.0.1", + "localhost", + "0.0.0.0", ] diff --git a/coolsite/media/photos/2022/04/$d/274px-Matrix_Trinity.jpeg b/coolsite/media/photos/2022/04/$d/274px-Matrix_Trinity.jpeg deleted file mode 100644 index 977d30b..0000000 Binary files a/coolsite/media/photos/2022/04/$d/274px-Matrix_Trinity.jpeg and /dev/null differ diff --git a/coolsite/media/photos/2022/04/$d/Sarah_Connor_-_Terminator_2.jpeg b/coolsite/media/photos/2022/04/$d/Sarah_Connor_-_Terminator_2.jpeg deleted file mode 100644 index 70cbd8f..0000000 Binary files a/coolsite/media/photos/2022/04/$d/Sarah_Connor_-_Terminator_2.jpeg and /dev/null differ diff --git a/coolsite/media/photos/2022/04/$d/andjelina-joli.jpg b/coolsite/media/photos/2022/04/$d/andjelina-joli.jpg deleted file mode 100644 index d333f1c..0000000 Binary files a/coolsite/media/photos/2022/04/$d/andjelina-joli.jpg and /dev/null differ diff --git a/coolsite/media/photos/2022/04/$d/lesya_ukrainka_portrait_public_domain.jpeg b/coolsite/media/photos/2022/04/$d/lesya_ukrainka_portrait_public_domain.jpeg deleted file mode 100644 index c10ed4d..0000000 Binary files a/coolsite/media/photos/2022/04/$d/lesya_ukrainka_portrait_public_domain.jpeg and /dev/null differ diff --git a/coolsite/women/constants.py b/coolsite/women/constants.py new file mode 100644 index 0000000..40219b8 --- /dev/null +++ b/coolsite/women/constants.py @@ -0,0 +1,46 @@ +WOMEN_CONTENT = { + "Trinity": """Trinity is a fictional character in the Matrix franchise.[1] She is portrayed by + Carrie-Anne Moss in the films. In the gameplay segments of Path of Neo, she is voiced + by Jennifer Hale. Trinity first appears in the 1999 film The Matrix.""", + "Sarah Conor": """Sarah Connor (born Sarah Marianne Corina Lewe; 13 June 1980) is a German pop singer. + She rose to prominence after she signed with X-Cell Records in 2000 and released her + debut album Green Eyed Soul (2001) the following year. She followed it with a + series of successful albums, including Unbelievable (2002), Key to My Soul (2003), + Naughty but Nice (2005), Christmas in My Heart (2005), Soulicious (2007), Sexy as Hell + (2008) and Real Love (2010). Several songs from these albums became hit singles on the + pop record charts, including the number-one hits "From Sarah with Love", "Music is the Key", + "Just One Last Dance", "Living to Love You" and "From Zero to Hero". In 2015, Connor's first + German language project Muttersprache became her second chart-topper after a decade.""", + "Angelina Jolie": """Angelina Jolie[3] DCMG (/dʒoʊˈliː/; born Angelina Jolie Voight;[4] June 4, 1975) + is an American actress, filmmaker, and humanitarian. The recipient of numerous accolades, + including an Academy Award and three Golden Globe Awards, she has been named Hollywood's + highest-paid actress multiple times. + + Jolie made her screen debut as a child alongside her father, Jon Voight, + in Lookin' to Get Out (1982), and her film career began in earnest a decade + later with the low-budget production Cyborg 2 (1993), followed by her first + leading role in a major film in Hackers (1995). She starred in the biographical + television films George Wallace (1997) and Gia (1998) and won the Academy Award + for Best Supporting Actress for her performance in the 1999 drama Girl, Interrupted. + Her starring role as the titular video game heroine in Lara Croft: Tomb Raider (2001) + established her as a leading Hollywood actress. She continued her action-star career + with Mr. & Mrs. Smith (2005), Wanted (2008), Salt (2010), and The Tourist (2010), + and received critical acclaim for her performances in the dramas A Mighty Heart + (2007) and Changeling (2008); the latter earned her a nomination for the Academy + Award for Best Actress. Her biggest commercial successes include the fantasy picture + Maleficent (2014), its 2019 sequel, and the superhero film Eternals (2021). + She has performed a voice role in the animation film series Kung Fu Panda since 2008. + Jolie has also directed and written the war dramas In the Land of Blood and Honey (2011), + Unbroken (2014), and First They Killed My Father (2017).""", + "Lesya Ukrainka": """Lesya Ukrainka[1] (Ukrainian: Леся Українка Ukrainian + pronunciation: [ˈlɛsʲɐ ʊkrɐˈjinkɐ]; born Larysa Petrivna Kosach, + Ukrainian: Лариса Петрівна Косач; 25 February [O.S. 13 February] + 1871 – 1 August [O.S. 19 July] 1913) was one of Ukrainian + literature's foremost writers, best known for her poems and plays. + She was also an active political, civil, and feminist activist.[2] + + Among her best-known works are the collections of poems On the + Wings of Songs (1893), Thoughts and Dreams (1899), Echos (1902), + the epic poem Ancient Fairy Tale (1893), One Word (1903), plays Princess (1913), + Cassandra (1903—1907), In the Catacombs (1905), and Forest Song (1911).""" +} diff --git a/coolsite/women/management/__init__.py b/coolsite/women/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coolsite/women/management/commands/__init__.py b/coolsite/women/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coolsite/women/management/commands/fill_db.py b/coolsite/women/management/commands/fill_db.py new file mode 100644 index 0000000..5a73da8 --- /dev/null +++ b/coolsite/women/management/commands/fill_db.py @@ -0,0 +1,44 @@ +import os + +from django.core.management.base import BaseCommand +from women.models import Category, Women +from women.constants import WOMEN_CONTENT + +CATEGORIES = ("Characters", "Actresses", "Models", "Writers") +WOMEN = ("Trinity", "Sarah Conor", "Angelina Jolie", "Lesya Ukrainka") +PHOTO_PATH = "coolsite/media/photos/2022/04/$d/" +PHOTO_TITLES = ("trinity.jpeg", "connor.jpeg", "angelina.jpg", "lesya.jpeg") + + +class Command(BaseCommand): + help = 'Populates the database with test data' + + def handle(self, *args, **options): + if self.validate_fill_bd(): + return self.stdout.write(self.style.SUCCESS('Test data has already been written to the database')) + + self.create_categories() + self.create_women() + + self.stdout.write(self.style.SUCCESS('Test data added successfully')) + + @staticmethod + def create_categories(): + for cat in CATEGORIES: + Category.objects.create(name=cat) + + @staticmethod + def create_women(): + for index, woman in enumerate(WOMEN): + photo_filename = os.path.basename(f"{PHOTO_PATH}{PHOTO_TITLES[index]}") + obj = Women.objects.create( + title=WOMEN[index], + content=WOMEN_CONTENT[woman], + cat=Category.objects.get(pk=index + 1) + ) + obj.photo.save(photo_filename, open(f"{PHOTO_PATH}{PHOTO_TITLES[index]}", "rb"), save=True) + + @staticmethod + def validate_fill_bd(): + return Category.objects.filter(name__in=CATEGORIES).exists() + diff --git a/coolsite/women/migrations/0003_alter_category_options_alter_women_options.py b/coolsite/women/migrations/0003_alter_category_options_alter_women_options.py new file mode 100644 index 0000000..f1fab54 --- /dev/null +++ b/coolsite/women/migrations/0003_alter_category_options_alter_women_options.py @@ -0,0 +1,21 @@ +# Generated by Django 4.0.4 on 2023-06-21 09:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('women', '0002_category_alter_women_photo_women_cat'), + ] + + operations = [ + migrations.AlterModelOptions( + name='category', + options={'verbose_name': 'Category', 'verbose_name_plural': 'Categories'}, + ), + migrations.AlterModelOptions( + name='women', + options={'ordering': ['-time_create', 'title'], 'verbose_name': 'Famous woman', 'verbose_name_plural': 'Famous women'}, + ), + ] diff --git a/coolsite/women/static/women/.DS_Store b/coolsite/women/static/women/.DS_Store index fd341f8..cbd2e9b 100644 Binary files a/coolsite/women/static/women/.DS_Store and b/coolsite/women/static/women/.DS_Store differ diff --git a/coolsite/women/static/women/css/styles.css b/coolsite/women/static/women/css/styles.css index 253a9e3..b7987b9 100644 --- a/coolsite/women/static/women/css/styles.css +++ b/coolsite/women/static/women/css/styles.css @@ -77,20 +77,20 @@ ul.list-articles li { .header { background: #3F4137; - height: 60px; + height: 100px; } .logo { - background: url('../images/logo.png') no-repeat 10px 5px; + background: url('../images/logo.png') no-repeat 10px 10px; width: 70px; - height: 60px; + height: 100px; } ul.mainmenu { list-style: none; margin: 0; padding: 0; - height: 60px; + height: 100px; color: #fdc073; font-size: 20px; overflow: hidden; @@ -428,3 +428,19 @@ ul.lang-list li a:hover {color: #fdc073;} .list-pages .page-num-selected:hover { box-shadow: none; } + +.board { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 50px; + margin-bottom: 20px; +} +.cell { + display: flex; + align-items: center; + justify-content: center; + width: 50px; + height: 50px; + border: 3px solid black; + font-size: 48px; +} diff --git a/coolsite/women/static/women/images/logo.png b/coolsite/women/static/women/images/logo.png index a33001a..d0e3da6 100644 Binary files a/coolsite/women/static/women/images/logo.png and b/coolsite/women/static/women/images/logo.png differ diff --git a/coolsite/women/static/women/images/main.ico b/coolsite/women/static/women/images/main.ico index 08f039c..553bb6c 100644 Binary files a/coolsite/women/static/women/images/main.ico and b/coolsite/women/static/women/images/main.ico differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a2d44f1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' +services: + web: + build: + context: . + dockerfile: Dockerfile + ports: + - '8000:8000' + volumes: + - .:/women_blog_site + restart: always + depends_on: + - db + environment: + - DB_HOST=psql + - DB_NAME=my_database + - DB_USER=my_user + - DB_PASS=my_password + + + db: + image: postgres:latest + restart: always + container_name: "psql" + environment: + - POSTGRES_USER=my_user + - POSTGRES_PASSWORD=my_password + - POSTGRES_DB=my_database + ports: + - "5432:5432" diff --git a/requirements.txt b/requirements.txt index 910bc04..88f294e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ django-ranged-response==0.2.0 django-simple-captcha==0.5.17 Pillow==9.1.0 sqlparse==0.4.2 +psycopg2-binary==2.9.6 \ No newline at end of file