Compare commits

..

42 Commits

Author SHA1 Message Date
Jukoga c37470a53d redone the docker for testing 2024-08-12 23:37:55 +02:00
Jukoga 230e85d3d0 redone the docker for testing 2024-08-12 23:18:42 +02:00
Jukoga 32c5a88f1c the migrations drive me crazy 2024-08-12 23:08:46 +02:00
Jukoga 2cf5562d04 deleted migrations 2024-08-12 23:07:30 +02:00
Surya 74baf03ae7 Delete server.bat
There is no need of this file as it no longer provides the required functionality.
2024-08-05 13:22:44 +02:00
Jukoga c0ac934c64 updated the README.md again 2024-08-05 13:19:03 +02:00
Surya e7a1572905 Merge pull request 'made everything to a docker file' (#6) from dockerisation into master
Reviewed-on: #6
This makes the Site Ready for Deployment.
2024-08-05 13:17:28 +02:00
Jukoga c916a2f583 updated the README.md 2024-08-05 13:13:59 +02:00
root 2e1fd94c8f production ready 2024-08-05 13:01:21 +02:00
Jukoga 2c286dacf4 made everything to a docker file 2024-08-01 13:33:38 +02:00
Jukoga 812099ee7f removed pycache 2024-07-24 23:53:44 +02:00
Jukoga 80af0bb917 deleted the sql file 2024-07-24 23:39:33 +02:00
Jukoga 588b151acd added pycache to all paths 2024-07-24 23:35:39 +02:00
Jukoga 28c5a0982d Merge remote-tracking branch 'origin/master'
# Conflicts:
#	blog/views.py
#	db.sqlite3
#	requirements.txt
#	templates/base.html
2024-07-24 23:33:58 +02:00
surya 29692b81ac Cleanup
Cleaned up the Project and re-migrated all the models
2024-07-24 23:28:40 +02:00
Surya 8e87a99ff2 Update blog/views.py 2024-07-24 23:27:34 +02:00
Surya fca2a8e35f Update README.md 2024-07-24 23:24:52 +02:00
Surya e8ca2d76b0 Made the `SECRET` secret
Made the `SECRET KEY` secret by using .env
2024-07-24 23:24:48 +02:00
surya 233381c9c2 Cleanup
Cleaned up the Project and re-migrated all the models
2024-07-25 02:31:23 +05:30
Surya 072df100ca Delete templates/users/login.html 2024-07-24 22:51:38 +02:00
Surya 4d8011eec6 Delete templates/users/logout.html 2024-07-24 22:51:33 +02:00
Surya b3be15b09e Delete templates/users/profile.html 2024-07-24 22:51:28 +02:00
Surya dae1b0cb7f Delete templates/users/register.html 2024-07-24 22:51:23 +02:00
Surya 5d402e7d67 Delete users/models.py 2024-07-24 22:50:20 +02:00
Surya e4c441848e Delete users/forms.py 2024-07-24 22:50:15 +02:00
Surya 212c7b033f Delete users/__init__.py 2024-07-24 22:50:09 +02:00
Surya 70ca6c2f48 Delete users/apps.py 2024-07-24 22:50:03 +02:00
Surya 19cb537864 Delete users/admin.py 2024-07-24 22:49:57 +02:00
Surya c1b711fe6a Delete users/signals.py 2024-07-24 22:49:47 +02:00
Surya 22a53d09ec Delete users/tests.py 2024-07-24 22:49:40 +02:00
Surya ee1a702618 Delete users/views.py 2024-07-24 22:49:32 +02:00
Surya cb4e2d2236 Delete users/urls.py 2024-07-24 22:49:18 +02:00
Surya 7bc99713c8 Update BH/urls.py 2024-07-24 22:48:46 +02:00
Surya 0e27feddb4 Update BH/settings.py 2024-07-24 22:43:16 +02:00
Surya 9de438c885 Delete templates/blog/blogCreate.html 2024-07-24 22:42:02 +02:00
Surya 9a6a88e695 Update blog/views.py 2024-07-24 22:41:34 +02:00
Surya 826d8aa56d Update blog/urls.py 2024-07-24 22:40:56 +02:00
Jukoga 79acc8163a deleted the blog create url 2024-07-24 21:50:06 +02:00
Jukoga d54da6f04d created .env file 2024-07-24 21:33:06 +02:00
Jukoga 02774e6094 delted everything that has todo with user 2024-07-24 21:25:47 +02:00
Jukoga 4ae7240d68 Merge branch 'refs/heads/MariaDB' into prod 2024-07-24 21:12:02 +02:00
Jukoga 4edf0577e6 Changed from DBLite to MariaDB 2024-07-19 22:55:11 +02:00
59 changed files with 81 additions and 426 deletions

8
.gitignore vendored
View File

@ -1,11 +1,15 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*/__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
#added
staticfiles/
*/migrations/
blog/migrations/
# Distribution / packaging
.Python
build/

Binary file not shown.

Binary file not shown.

View File

@ -17,6 +17,8 @@ from dotenv import load_dotenv
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR + '/templates')
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
@ -27,9 +29,9 @@ load_dotenv()
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'beyond-heroes.com', 'www.beyond-heroes.com']
# Application definition
@ -38,7 +40,6 @@ INSTALLED_APPS = [
'crispy_forms',
'crispy_bootstrap4',
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -83,8 +84,12 @@ WSGI_APPLICATION = 'BH.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}
@ -125,6 +130,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR + '/media')
MEDIA_URL = '/media/'

View File

@ -20,7 +20,6 @@ from django.urls import path, include
urlpatterns = [
path('', include('blog.urls')),
path('users/', include('users.urls')),
path('admin/', admin.site.urls),
]

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
# Use the official MariaDB base image
FROM mariadb:latest
# Set environment variables
ENV MARIADB_ROOT_PASSWORD=DB_ROOTPW
ENV MARIADB_ROOT_HOST=%
ENV MARIADB_DATABASE=DBNAME
ENV MARIADB_USER=DB_USER
ENV MARIADB_PASSWORD=DB_PASSWORD
# Expose the MariaDB port
EXPOSE 3306

View File

@ -1,13 +1,23 @@
## Requirements
The website requires the following:
- Docker
- Docker Compose
- A running MariaDB Instance
## Deployment
To deploy the website:
To deploy the website:
- first clone the repository to any local folder
- then open the folder with the `manage.py` file
- then `Shift`+`Right Click` and click on `Open PowerShell window here`
- then create the virtual environment by typing `py -m venv .venv`
- then activate the virtual environment by typing `.venv\Scripts\Activate`
- then install the requirements by typing `pip install -r requirements.txt`
- then type in `py manage.py runserver 3000`
- open browser at address `localhost:3000` or `127.0.0.1:3000`
- then open the folder
- create a new file called `.env` and add the following:
```
SECRET_KEY=your_secret_key
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=your_db_port
```
- run `docker-compose up --build` this starts the website at localhost:3030
## Structure
The website has a Home page and a News page currently. The News page shows all developer blogs.

17
TestInstructions.md Normal file
View File

@ -0,0 +1,17 @@
First of change the Env variables in the .env and the docker-compose.yml file to your own values.
Then create the docker container and run it with the following command:
```bash
docker-compose up --build
```
This starts the Database \
Then run the following command to create the database tables:
```bash
python manage.py migrate
python manage.py migrate --run-syncdb
```
At last, run the following command to start the server:
```bash
python manage.py runserver 3030
```

View File

@ -1,37 +0,0 @@
# Generated by Django 5.0.2 on 2024-07-06 16:24
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Blog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('title', models.CharField(max_length=150)),
('date_posted', models.DateTimeField(default=django.utils.timezone.now)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('date_posted', models.DateTimeField(default=django.utils.timezone.now)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -7,7 +7,7 @@ from django.utils import timezone
class Blog(models.Model):
content = models.TextField()
title = models.CharField(max_length=150)
author = models.ForeignKey(User, on_delete=models.CASCADE)
author = models.TextField() #models.ForeignKey(User, on_delete=models.CASCADE)
date_posted = models.DateTimeField(default=timezone.now)
def get_absolute_url(self):

View File

@ -5,7 +5,6 @@ urlpatterns = [
path('', views.home, name='Home'),
path('news/', views.news, name='News'),
path('blog/<int:pk>', views.BlogDetailView.as_view(), name='Blog'),
path('blog/create/', views.BlogCreateView.as_view(), name='BlogCreate'),
path('dev/', views.dev, name='Dev'),
path('dev/support/', views.support, name='Support'),
]

View File

@ -3,8 +3,6 @@ from django.shortcuts import render
from django.contrib.auth.mixins import *
from django.views.generic import *
from .models import *
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.decorators import method_decorator
# Create your views here.
@ -45,17 +43,6 @@ class BlogDetailView(DetailView):
template_name = 'blog/blogDetail.html'
@method_decorator(staff_member_required, name='dispatch')
class BlogCreateView(LoginRequiredMixin, CreateView):
model = Blog
template_name = 'blog/blogCreate.html'
fields = ['title', 'content']
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
def dev(request):
return render(request, 'dev.html', {'title': 'Development'})

Binary file not shown.

15
docker-compose.yml Normal file
View File

@ -0,0 +1,15 @@
version: '3.8'
services:
mariadb:
build: .
container_name: mariadb
restart: unless-stopped
environment:
MARIADB_ROOT_PASSWORD: 'DB_ROOTPW'
MARIADB_ROOT_HOST: '%'
MARIADB_DATABASE: 'DBNAME'
MARIADB_USER: 'DB_USER'
MARIADB_PASSWORD: 'DB_PASSWORD'
ports:
- "3306:3306"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

View File

@ -1,5 +0,0 @@
@ echo off
echo The devlopment server will start in a few seconds...
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 3000

View File

@ -8,7 +8,6 @@
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #000;">
<div class="container">
<a class="navbar-brand" href="/">
<img src="/media/logo.jpg" alt="BH Logo" height="40"> Beyond Heroes
</a>
@ -26,35 +25,6 @@
</li>
</ul>
</div>
<div class="ml-auto"></div>
<div class="justify-content-center" id="navbarNav">
<ul class="navbar-nav">
{% if user.is_authenticated %}
<li class="nav-item">
{% if user.is_staff %}
<form action="{% url 'BlogCreate' %}" method="get">
{% csrf_token %}
<button class="nav-link btn btn-link" type="submit">Post</button>
</form>
{% endif %}
</li>
<li class="nav-item">
<form action="{% url 'Logout' %}" method="post">
{% csrf_token %}
<button class="nav-link btn btn-link" type="submit">Logout</button>
</form>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'Login' %}">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'Register' %}">Register</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% block content %}

View File

@ -1,19 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}
<div class="container mt-5">
<form method="POST">
{% csrf_token %}
<div class="card mb-4">
<div class="card-header">
Create a New Blog Article
</div>
<div class="card-body">
{{ form | crispy }}
<br>
<button class="btn btn-light" type="submit"> Post </button>
</div>
</div>
</form>
</div>
{% endblock %}

View File

@ -10,7 +10,7 @@
<p class="card-text">{{ object.content | markdown | safe }}</p>
</div>
<div class="card-footer">
By <cite title="{{ object.author }}"><a href="#" class="link text-dark">{{ object.author }}</a></cite> on <cite title="{{ object.date_posted }}">{{ object.date_posted|date:"M j, o" }}</cite>
By <cite title="{{ object.author }}"></cite> on <cite title="{{ object.date_posted }}">{{ object.date_posted|date:"M j, o" }}</cite>
</div>
</div>

View File

@ -1,24 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}
<div class="container mt-5">
<form method="POST">
{% csrf_token %}
<div class="card mb-4">
<div class="card-header">
Login
</div>
<div class="card-body">
{{ form | crispy }}
<br>
<button class="btn btn-light" type="submit"> Login </button>
</div>
<div class="card-footer">
<small class="text-muted">
Don't Have An Account? <a class="link" href="{% url 'Register' %}">Register</a>
</small>
</div>
</div>
</form>
</div>
{% endblock %}

View File

@ -1,25 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tags}}">{{ message }}</div>
{% endfor %}
{% endif %}
<div class="container mt-5">
<div class="card mb-4">
<div class="card-header h5">
You have been Logged Out
</div>
<div class="card-body">
Hope you enjoyed Today!
</div>
<div class="card-footer">
<small class="text-muted">
Go to <a href="{% url 'Home' %}" class="link">Home</a> or <a href="{% url 'Login' %}" class="link" type="submit"> Log in </a> Again?
</small>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,58 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% load markdown_extras %}
<!-- Main Content -->
<div class="container mt-5">
<div class="row">
<!-- Mainbar -->
<div class="col-lg-8">
<div class="card-body">
<div class="card">
<div class="card-header">
Latest Posts
</div>
<div class="card-body">
{% for post in posts %}
{% if post.author == profileUser %}
<!-- Posts will be dynamically added here -->
<div class="card mb-3 userPost">
<div class="card-body">
<h5 class="card-title">{{ post.author.username }} <a href="#" class="link text-secondary lead" style="text-decoration: none;">@{{ post.author.id }}</a></h5>
<p class="card-text">{{ post.content | markdown | safe }}</p>
</div>
</div>
<!-- End of Posts -->
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
<!-- Sidebar -->
<div class="col-lg-4">
<div class="card mb-4">
<div class="row" style="padding-bottom: 20px;">
<div class="col-md-4 text-center">
<img src="https://cdn.pixabay.com/photo/2017/06/13/12/54/profile-2398783_1280.png" alt="Profile Image" class="profile-image">
</div>
<div class="col-md-8">
<h2 class="mt-3" style="margin-bottom: 0px;">{{ profileUser.username }}</h2>
<p class="text-secondary lead" style="margin-bottom: 0px;">@{{ profileUser.id }}</p>
<p>Date Joined: Jan 1, 2022</p>
{% if profileUser == user %}
<a href="#" class="link">Edit Profile</a>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,24 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}
<div class="container mt-5">
<form method="POST">
{% csrf_token %}
<div class="card mb-4">
<div class="card-header">
Create an Account
</div>
<div class="card-body">
{{ form | crispy }}
<br>
<button class="btn btn-light sm" type="submit"> Register </button>
</div>
<div class="card-footer">
<small class="text-muted">
Already Have An Account? <a class="link" href="{% url 'Login' %}">Sign In</a>
</small>
</div>
</div>
</form>
</div>
{% endblock %}

View File

View File

@ -1,5 +0,0 @@
from django.contrib import admin
from .models import Profile
# Register your models here.

View File

@ -1,8 +0,0 @@
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
def ready(self):
import users.signals

View File

@ -1,21 +0,0 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Profile
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
class UserUpdateForm(forms.ModelForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'email']

View File

@ -1,28 +0,0 @@
# Generated by Django 5.0.2 on 2024-07-06 16:24
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('about', models.TextField(default='Hi, I am new to TechBlog')),
('gender', models.TextField(default='None')),
('dob', models.DateField(default='1999-01-01')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -1,16 +0,0 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
about = models.TextField(default='Hi, I am new to TechBlog')
gender = models.TextField(default='None')
dob = models.DateField(default='1999-01-01')
# image = models.ImageField(default='default.png', name='profile_pic', upload_to='profile_pics')
def __str__(self):
return f"{self.user.username}'s Profile"

View File

@ -1,3 +0,0 @@
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,11 +0,0 @@
from django.urls import path
from django.contrib.auth import views as login_view
from . import views
urlpatterns = [
path('profile/', views.profile, name='Profile'),
path('profile/<int:pk>', views.profile, name='NamedProfile'),
path('login/', login_view.LoginView.as_view(template_name='users/login.html'), name='Login'),
path('logout/', login_view.LogoutView.as_view(template_name='users/logout.html'), name='Logout'),
path('register/', views.register, name='Register')
]

View File

@ -1,77 +0,0 @@
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm
from blog.models import *
from .models import *
from django.views.generic import *
# Create your views here.
# def users(request):
# return render(request, 'users/users.html', {'title': 'Users'})
def getFromArr(arr, indices, *args, **kwargs):
x = []
for i in indices:
x.append(arr[i])
return x
@login_required
def profile(request, *args, **kwargs):
try:
user = User._default_manager.all()[kwargs['pk'] - 1]
except:
user = request.user
print(user.id)
allow_empty = True
queryset = None
model = Post
paginate_by = None
paginate_orphans = 0
context_object_name = 'posts'
ordering = ['-date_posted']
if queryset is not None:
queryset = queryset
if isinstance(queryset, QuerySet):
queryset = queryset.all()
elif model is not None:
queryset = model._default_manager.all()
else:
raise ImproperlyConfigured(
"%(cls)s is missing a QuerySet. Define "
"%(cls)s.model, %(cls)s.queryset, or override "
"%(cls)s.get_queryset()." % {"cls": self.__class__.__name__}
)
if ordering:
if isinstance(ordering, str):
ordering = (ordering,)
queryset = queryset.order_by(*ordering)
return render(request, 'users/profile.html', {'title': 'Profile', 'profileUser': user, context_object_name: queryset})
users = {
'user': User.objects.all()
}
def login(request):
return render(request, 'users/login.html', {'title': 'Login'})
def register(request):
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'{username}! Your account has been created.')
return redirect('Login')
else:
form = UserRegisterForm()
return render(request, 'users/register.html', {'title': 'Register', 'form': form})