diff --git a/LibCasaAdministration/settings.py b/LibCasaAdministration/settings.py index f44121d..e1df59b 100644 --- a/LibCasaAdministration/settings.py +++ b/LibCasaAdministration/settings.py @@ -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'. @@ -52,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': [ @@ -67,7 +82,6 @@ TEMPLATES = [ }, }, ] - WSGI_APPLICATION = 'LibCasaAdministration.wsgi.application' diff --git a/LibCasaAdministration/urls.py b/LibCasaAdministration/urls.py index a82db6b..523b71e 100644 --- a/LibCasaAdministration/urls.py +++ b/LibCasaAdministration/urls.py @@ -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) diff --git a/forum/admin.py b/forum/admin.py index fbef64a..1437edc 100644 --- a/forum/admin.py +++ b/forum/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin -from .models import Post, Replie, Profile +from .models import Post, Reply, Profile admin.site.register(Post) -admin.site.register(Replie) +admin.site.register(Reply) admin.site.register(Profile) \ No newline at end of file diff --git a/forum/forms.py b/forum/forms.py new file mode 100644 index 0000000..22dc099 --- /dev/null +++ b/forum/forms.py @@ -0,0 +1,7 @@ +from django import forms +from .models import Profile + +class ProfileForm(forms.ModelForm): + class Meta: + model = Profile + fields = ('image', ) \ No newline at end of file diff --git a/forum/views.py b/forum/views.py index c852520..5f955ee 100644 --- a/forum/views.py +++ b/forum/views.py @@ -2,7 +2,8 @@ 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'] @@ -34,6 +35,11 @@ def UserLogin(request): 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": @@ -59,4 +65,19 @@ def discussion(request, myid): 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 + 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})