diff --git a/LibCasaAdministration/settings.py b/LibCasaAdministration/settings.py index 2ed38c0..f44121d 100644 --- a/LibCasaAdministration/settings.py +++ b/LibCasaAdministration/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'forum.apps.ForumConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/forum/__init__.py b/forum/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/forum/admin.py b/forum/admin.py new file mode 100644 index 0000000..fbef64a --- /dev/null +++ b/forum/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin + +from .models import Post, Replie, Profile + +admin.site.register(Post) +admin.site.register(Replie) +admin.site.register(Profile) \ No newline at end of file diff --git a/forum/apps.py b/forum/apps.py new file mode 100644 index 0000000..f0cb8de --- /dev/null +++ b/forum/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ForumConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'forum' diff --git a/forum/migrations/0001_initial.py b/forum/migrations/0001_initial.py new file mode 100644 index 0000000..bf5e545 --- /dev/null +++ b/forum/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/forum/migrations/__init__.py b/forum/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/forum/models.py b/forum/models.py new file mode 100644 index 0000000..8a1273a --- /dev/null +++ b/forum/models.py @@ -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="") \ No newline at end of file diff --git a/forum/templates/basic.html b/forum/templates/basic.html new file mode 100644 index 0000000..9e63f8a --- /dev/null +++ b/forum/templates/basic.html @@ -0,0 +1,44 @@ +{% block title %} {% endblock %} + + + + +
+ +{% block body %} {% endblock %} \ No newline at end of file diff --git a/forum/templates/discussion.html b/forum/templates/discussion.html new file mode 100644 index 0000000..f1da076 --- /dev/null +++ b/forum/templates/discussion.html @@ -0,0 +1,37 @@ +{% for reply in replies %} +
+
+
+ . +
+

{{reply.user}}             ({{reply.timestamp}})

+
{{reply.reply_content}}
+
+
+
+{% endfor %} + + \ No newline at end of file diff --git a/forum/templates/forum.html b/forum/templates/forum.html new file mode 100644 index 0000000..4ca3cf8 --- /dev/null +++ b/forum/templates/forum.html @@ -0,0 +1,60 @@ +
+
+

Project Gurukul Disscussion Forum

+

This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.

+
+

It uses utility classes for typography and spacing to space content out within the larger container.

+ +
+ {% for post in posts %} +
+
+
+
+
+
+ +
+
{{post.timestamp}}
+
+
+
+
+

{{post.post_content}}

+
+ +
+
+
+
+ {% endfor %} + +
+ + + \ No newline at end of file diff --git a/forum/templates/login.html b/forum/templates/login.html new file mode 100644 index 0000000..8391aee --- /dev/null +++ b/forum/templates/login.html @@ -0,0 +1,10 @@ +
+
+

Log In

+ {% csrf_token %} + + + +
+
+ {% endblock %} \ No newline at end of file diff --git a/forum/templates/register.html b/forum/templates/register.html new file mode 100644 index 0000000..e620a69 --- /dev/null +++ b/forum/templates/register.html @@ -0,0 +1,19 @@ +{% block body %} +
+
+
+

Register

+ {% csrf_token %} + + + + + + + + + +
+
+ + {% endblock %} \ No newline at end of file diff --git a/forum/tests.py b/forum/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/forum/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/forum/urls.py b/forum/urls.py new file mode 100644 index 0000000..e5ba4a9 --- /dev/null +++ b/forum/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path("", views.forum, name="Forum"), + path("discussion//", 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"), +] diff --git a/forum/views.py b/forum/views.py new file mode 100644 index 0000000..c852520 --- /dev/null +++ b/forum/views.py @@ -0,0 +1,62 @@ +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 + +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 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}) \ No newline at end of file