mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 17:12:55 +00:00
✨ Features: - Complete Django project with authentication - Email/password and social login (Google, Facebook) - Role-based access control (admin, staff, user) - Docker and Docker Compose setup - Production-ready configuration - Static file handling with WhiteNoise - PostgreSQL database integration - Comprehensive documentation - GitHub CI/CD workflows - Dokploy deployment configuration 🚀 Ready for deployment on Dokploy, Heroku, Railway, and other platforms
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from django.contrib.auth.decorators import login_required
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.shortcuts import render, redirect
|
|
from django.views.generic import TemplateView, UpdateView
|
|
from django.contrib import messages
|
|
from django.urls import reverse_lazy
|
|
from .models import User, UserProfile
|
|
|
|
|
|
class ProfileView(LoginRequiredMixin, TemplateView):
|
|
template_name = 'account/profile.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context['user'] = self.request.user
|
|
return context
|
|
|
|
|
|
class ProfileUpdateView(LoginRequiredMixin, UpdateView):
|
|
model = UserProfile
|
|
template_name = 'account/profile_edit.html'
|
|
fields = ['bio', 'location', 'birth_date', 'avatar', 'phone_number']
|
|
success_url = reverse_lazy('accounts:profile')
|
|
|
|
def get_object(self):
|
|
profile, created = UserProfile.objects.get_or_create(user=self.request.user)
|
|
return profile
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, 'Your profile has been updated successfully!')
|
|
return super().form_valid(form)
|
|
|
|
|
|
@login_required
|
|
def dashboard(request):
|
|
context = {
|
|
'user': request.user,
|
|
'user_groups': request.user.groups.all(),
|
|
}
|
|
return render(request, 'account/dashboard.html', context) |