Compare commits
3 Commits
master
...
devel/foru
Author | SHA1 | Date | |
---|---|---|---|
711661f158 | |||
4479bc8316 | |||
31a2e4004c |
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2022 Pratyush Desai
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'forum.apps.ForumConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@ -51,10 +52,25 @@ MIDDLEWARE = [
|
||||
|
||||
ROOT_URLCONF = 'LibCasaAdministration.urls'
|
||||
|
||||
# TEMPLATES = [
|
||||
# {
|
||||
# 'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
# 'DIRS': [],
|
||||
# 'APP_DIRS': True,
|
||||
# 'OPTIONS': {
|
||||
# 'context_processors': [
|
||||
# 'django.template.context_processors.debug',
|
||||
# 'django.template.context_processors.request',
|
||||
# 'django.contrib.auth.context_processors.auth',
|
||||
# 'django.contrib.messages.context_processors.messages',
|
||||
# ],
|
||||
# },
|
||||
# },
|
||||
# ]
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'DIRS': [os.path.join(BASE_DIR, "templates")],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@ -66,7 +82,6 @@ TEMPLATES = [
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'LibCasaAdministration.wsgi.application'
|
||||
|
||||
|
||||
|
@ -15,8 +15,11 @@ Including another URLconf
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf.urls.static import static
|
||||
from django.conf import settings
|
||||
|
||||
urlpatterns = [
|
||||
path('api/', include('api.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
path('', include('forum.urls')),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
7
README.md
Normal file
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Flask based Web Services
|
||||
|
||||
## Setting up FlaskBB
|
||||
|
||||
* Setup - Done
|
||||
* Productionize - todo
|
||||
* Flask integration with keycloak.
|
0
forum/__init__.py
Normal file
0
forum/__init__.py
Normal file
7
forum/admin.py
Normal file
7
forum/admin.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Post, Reply, Profile
|
||||
|
||||
admin.site.register(Post)
|
||||
admin.site.register(Reply)
|
||||
admin.site.register(Profile)
|
6
forum/apps.py
Normal file
6
forum/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ForumConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'forum'
|
7
forum/forms.py
Normal file
7
forum/forms.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django import forms
|
||||
from .models import Profile
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = ('image', )
|
47
forum/migrations/0001_initial.py
Normal file
47
forum/migrations/0001_initial.py
Normal file
@ -0,0 +1,47 @@
|
||||
# Generated by Django 4.0.4 on 2022-06-20 15:45
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Post',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('post_content', models.CharField(max_length=5000)),
|
||||
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('image', models.ImageField(default='', upload_to='images')),
|
||||
('user1', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Reply',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('reply_content', models.CharField(max_length=5000)),
|
||||
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('image', models.ImageField(default='', upload_to='images')),
|
||||
('post', models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='forum.post')),
|
||||
('user', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Profile',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('image', models.ImageField(default='default/user.png', upload_to='images')),
|
||||
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
0
forum/migrations/__init__.py
Normal file
0
forum/migrations/__init__.py
Normal file
25
forum/models.py
Normal file
25
forum/models.py
Normal file
@ -0,0 +1,25 @@
|
||||
from django.db import models
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.timezone import now
|
||||
|
||||
# Create your models here.
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
|
||||
image = models.ImageField(upload_to="images",default="default/user.png")
|
||||
|
||||
class Post(models.Model):
|
||||
user1 = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
|
||||
post_id = models.AutoField
|
||||
post_content = models.CharField(max_length=5000)
|
||||
timestamp= models.DateTimeField(default=now)
|
||||
image = models.ImageField(upload_to="images",default="")
|
||||
|
||||
class Reply(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
|
||||
reply_id = models.AutoField
|
||||
reply_content = models.CharField(max_length=5000)
|
||||
post = models.ForeignKey(Post, on_delete=models.CASCADE, default='')
|
||||
timestamp= models.DateTimeField(default=now)
|
||||
image = models.ImageField(upload_to="images",default="")
|
44
forum/templates/basic.html
Normal file
44
forum/templates/basic.html
Normal file
@ -0,0 +1,44 @@
|
||||
<title>{% block title %} {% endblock %}</title>
|
||||
<style>
|
||||
{% block css %} {% endblock %}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
||||
<a class="navbar-brand" href="/">Discussion Forum</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<ul class="navbar-nav mr-2">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href='#' id="navbarDropdown" role="button" data-toggle="dropdown"> Welcome {{request.user}}</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<a class="dropdown-item" href="/logout">Logout</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/register">Register</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/login">Login</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/myprofile">Profile</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<br>
|
||||
</body>
|
||||
{% block body %} {% endblock %}
|
37
forum/templates/discussion.html
Normal file
37
forum/templates/discussion.html
Normal file
@ -0,0 +1,37 @@
|
||||
{% for reply in replies %}
|
||||
<br>
|
||||
<div class="container">
|
||||
<div class="media">
|
||||
<img class="mr-3" src="/media/{{reply.image}}" alt="." width="30px" height="30px">
|
||||
<div class="media-body">
|
||||
<h4 class="mt-0">{{reply.user}} <span><small style="font-size: 13px;">({{reply.timestamp}})</small></span></h4>
|
||||
<h5>{{reply.reply_content}}</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="reply" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="/discussion/{{post.id}}/" method="POST"> {% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="exampleFormControlTextarea1">Post Your Solution Here</label>
|
||||
<input type="hidden" name="post_id" value="{{post.id}}">
|
||||
<textarea class="form-control" id="desc" name="desc" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Post Solution</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
60
forum/templates/forum.html
Normal file
60
forum/templates/forum.html
Normal file
@ -0,0 +1,60 @@
|
||||
<div class="container my-4">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">Project Gurukul Disscussion Forum</h1>
|
||||
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
|
||||
<hr class="my-4">
|
||||
<p>It uses utility classes for typography and spacing to space content out within the larger container.</p>
|
||||
<button class="btn btn-primary btn-lg" data-target="#questions" data-toggle="modal" role="button">Add Question</button>
|
||||
</div>
|
||||
{% for post in posts %}
|
||||
<div class="container-fluid mt-10">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<div class="media flex-wrap w-100 align-items-center"> <img src="/media/{{post.image}}"
|
||||
class="d-block ui-w-40 rounded-circle" alt="">
|
||||
<div class="media-body ml-3"> <a href="/discussion/{{post.id}}" data-abc="true">{{post.user1}}</a>
|
||||
</div>
|
||||
<div class="text-muted small ml-3">
|
||||
<div class="px-4 pt-3">{{post.timestamp}} </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>{{post.post_content}}</p>
|
||||
</div>
|
||||
<div class="card-footer d-flex flex-wrap justify-content-between align-items-center px-0 pt-0 pb-3">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="questions" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="/" method="POST"> {% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="exampleFormControlTextarea1">Post Your Question Here</label>
|
||||
<textarea class="form-control" id="content" name="content" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Post</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
10
forum/templates/login.html
Normal file
10
forum/templates/login.html
Normal file
@ -0,0 +1,10 @@
|
||||
<div id="login-box">
|
||||
<div class="items">
|
||||
<h1>Log In</h1>
|
||||
<form action="/login/" method="post"> {% csrf_token %}
|
||||
<input type="text" name="username" placeholder="Username" />
|
||||
<input type="password" name="password" placeholder="Password" />
|
||||
<input type="submit" name="signup_submit" value="Log In" />
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
19
forum/templates/register.html
Normal file
19
forum/templates/register.html
Normal file
@ -0,0 +1,19 @@
|
||||
{% block body %}
|
||||
<br>
|
||||
<div id="login-box">
|
||||
<div class="items">
|
||||
<h1>Register</h1>
|
||||
<form action="/register/" method="post"> {% csrf_token %}
|
||||
|
||||
<input type="text" name="username" placeholder="Username" />
|
||||
<input type="email" name="email" placeholder="E-mail" />
|
||||
<input type="text" name="first_name" placeholder="First Name" />
|
||||
<input type="text" name="last_name" placeholder="Last Name" />
|
||||
<input type="password" name="password" placeholder="Password" />
|
||||
<input type="password" name="confirm_password" placeholder="Confirm your password" />
|
||||
|
||||
<input type="submit" name="signup_submit" value="Register" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
3
forum/tests.py
Normal file
3
forum/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
forum/urls.py
Normal file
11
forum/urls.py
Normal file
@ -0,0 +1,11 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.forum, name="Forum"),
|
||||
path("discussion/<int:myid>/", views.discussion, name="Discussions"),
|
||||
path("register/", views.UserRegister, name="Register"),
|
||||
path("login/", views.UserLogin, name="Login"),
|
||||
path("logout/", views.UserLogout, name="Logout"),
|
||||
path("myprofile/", views.myprofile, name="Myprofile"),
|
||||
]
|
83
forum/views.py
Normal file
83
forum/views.py
Normal file
@ -0,0 +1,83 @@
|
||||
from django.shortcuts import render, redirect, HttpResponse, Http404
|
||||
from .models import User, Profile, Post, Reply
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from .forms import ProfileForm
|
||||
def UserRegister(request):
|
||||
if request.method=="POST":
|
||||
username = request.POST['username']
|
||||
email = request.POST['email']
|
||||
first_name=request.POST['first_name']
|
||||
last_name=request.POST['last_name']
|
||||
password = request.POST['password']
|
||||
confirm_password = request.POST['confirm_password']
|
||||
user = User.objects.create_user(username, email, password)
|
||||
user.first_name = first_name
|
||||
user.last_name = last_name
|
||||
user.save()
|
||||
return render(request, 'login.html')
|
||||
return render(request, "register.html")
|
||||
|
||||
|
||||
def UserLogin(request):
|
||||
if request.method=="POST":
|
||||
username = request.POST['username']
|
||||
password = request.POST['password']
|
||||
user = authenticate(username=username, password=password)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
messages.success(request, "Successfully Logged In")
|
||||
return redirect("/myprofile")
|
||||
else:
|
||||
return HttpResponse("User not Found")
|
||||
alert = True
|
||||
return render(request, 'login.html', {'alert':alert})
|
||||
return render(request, "login.html")
|
||||
|
||||
def UserLogout(request):
|
||||
logout(request)
|
||||
messages.success(request, "Successfully logged out")
|
||||
return redirect('/login')
|
||||
|
||||
def forum(request):
|
||||
profile = Profile.objects.all()
|
||||
if request.method=="POST":
|
||||
user = request.user
|
||||
image = request.user.profile.image
|
||||
content = request.POST.get('content','')
|
||||
post = Post(user1=user, post_content=content, image=image)
|
||||
post.save()
|
||||
alert = True
|
||||
return render(request, "forum.html", {'alert':alert})
|
||||
posts = Post.objects.all()
|
||||
return render(request, "forum.html", {'posts':posts})
|
||||
|
||||
def discussion(request, myid):
|
||||
post = Post.objects.filter(id=myid).first()
|
||||
replies = Reply.objects.filter(post=post)
|
||||
if request.method=="POST":
|
||||
user = request.user
|
||||
image = request.user.profile.image
|
||||
desc = request.POST.get('desc','')
|
||||
post_id =request.POST.get('post_id','')
|
||||
reply = Reply(user = user, reply_content = desc, post=post, image=image)
|
||||
reply.save()
|
||||
alert = True
|
||||
return render(request, "discussion.html", {'alert':alert})
|
||||
return render(request, "discussion.html", {'post':post, 'replies':replies})
|
||||
|
||||
@login_required(login_url = '/login')
|
||||
def myprofile(request):
|
||||
if request.method=="POST":
|
||||
user = request.user
|
||||
profile = Profile(user=user)
|
||||
profile.save()
|
||||
form = ProfileForm(data=request.POST, files=request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
obj = form.instance
|
||||
return render(request, "profile.html",{'obj':obj})
|
||||
else:
|
||||
form=ProfileForm()
|
||||
return render(request, "profile.html", {'form':form})
|
Reference in New Issue
Block a user