diff --git a/src/apps/account/templates/profile.html b/src/apps/account/templates/profile.html index 19bfc3f..c35adf0 100644 --- a/src/apps/account/templates/profile.html +++ b/src/apps/account/templates/profile.html @@ -4,15 +4,24 @@ {% block meta %}{% endblock %} {% block content %}
-
- - - - - - -
-

My Projects

+ {% if user.is_authenticated and user == page_owner %} +
+ + + + + + +
+ {% endif %} +

+ {% if user.is_authenticated and user == page_owner %} + My + {% else %} + {{ page_owner }} + {% endif %} + Projects +

{% for project in projects %}
diff --git a/src/apps/account/views.py b/src/apps/account/views.py index e1d98e2..53b0378 100644 --- a/src/apps/account/views.py +++ b/src/apps/account/views.py @@ -4,9 +4,7 @@ from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import redirect, render from django.urls import reverse_lazy -from django.views.generic import ListView, TemplateView, View - -from fossdb.models import Project +from django.views.generic import TemplateView, View from .forms import LoginForm, SignUpForm, UserChangeForm @@ -64,22 +62,6 @@ class PasswordChangeView(LoginRequiredMixin, TemplateView): return self.render_to_response(context) -class ProfileProjectListView(LoginRequiredMixin, ListView): - model = Project - template_name = "profile.html" - context_object_name = "projects" - login_url = reverse_lazy("login") - redirect_field_name = "redirect_to" - - def get_queryset(self): - return Project.objects.filter(owner=self.request.user) - - def get_context_data(self, *args, **kwargs): - data = super().get_context_data(**kwargs) - data["title"] = self.request.user.username + ("" if not self.request.user.full_name else f" ({self.request.user.full_name})") - return data - - def signup_view(request): form = SignUpForm(request.POST or None) if request.method == "POST": diff --git a/src/apps/fossdb/views.py b/src/apps/fossdb/views.py index 3031367..3f13ed0 100644 --- a/src/apps/fossdb/views.py +++ b/src/apps/fossdb/views.py @@ -1,6 +1,7 @@ +from django.contrib.auth import get_user_model from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.db.models import Q -from django.shortcuts import redirect +from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView @@ -34,6 +35,24 @@ class SearchResultsListView(ListView): return data +class ProfileProjectListView(ListView): + model = Project + template_name = "profile.html" + context_object_name = "projects" + slug_field = "username" + + def get_queryset(self): + username = self.kwargs.get("username") + self.user = get_object_or_404(get_user_model(), username=username) + return Project.objects.filter(owner__username=username) + + def get_context_data(self, *args, **kwargs): + data = super().get_context_data(**kwargs) + data["title"] = self.user.username + ("" if not self.user.full_name else f" ({self.user.full_name})") + data["page_owner"] = self.user + return data + + class ProjectListView(ListView): model = Project template_name = "explore.html" diff --git a/src/apps/main/urls.py b/src/apps/main/urls.py index 2a1e3d0..e8cef29 100644 --- a/src/apps/main/urls.py +++ b/src/apps/main/urls.py @@ -1,6 +1,5 @@ -from account.views import ProfileProjectListView from django.urls import path -from fossdb.views import ProjectCreateView, ProjectListView, SearchResultsListView +from fossdb.views import ProfileProjectListView, ProjectCreateView, ProjectListView, SearchResultsListView from . import views