From ccdb49c8ea5351f9f0cd856b7524b1c839ff54f6 Mon Sep 17 00:00:00 2001 From: reverend Date: Sun, 29 Nov 2020 19:22:55 +0100 Subject: [PATCH] Profile View --- .../templates/explorer/profile.html | 109 ++++++++++++++++++ .../lostplaces/views/explorer_views.py | 45 ++++++++ 2 files changed, 154 insertions(+) create mode 100644 django_lostplaces/lostplaces/templates/explorer/profile.html create mode 100644 django_lostplaces/lostplaces/views/explorer_views.py diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html new file mode 100644 index 0000000..4cf7948 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -0,0 +1,109 @@ +{% extends 'global.html'%} +{% load static %} +{% load i18n %} + +{% load svg_icon %} + +{% block maincontent %} + +
+
+
+
+

{{explorer.user.username}}

+
+
+ + + + + + + + + + + + + +
+ {% trans 'Joined' %} + + {{explorer.user.date_joined|date:'d.m.Y'}} +
+ {% trans 'Places'%} + + {{place_count}} +
+ {% trans 'Place Assets'%} + + {{asset_count}} +
+
+
+
+
+ +
+
+

{% trans 'Places submitted by' %} {{explorer.user.username}}

+ + + {% include 'partials/nav/pagination.html' %} + +
+
+ +
+

{% trans 'Images submitted by' %} {{explorer.user.username}}

+
+
    + {% for place_image in assets.placeimages.all %} +
  • + + + + {% if user.explorer == place_image.submitted_by%} + + + + + + {% endif %} +
  • + {% endfor %} +
+
+
+ +
+

{% trans 'Photo albums submitted by' %} {{explorer.user.username}}

+ +
+ +{% endblock maincontent %} \ No newline at end of file diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py new file mode 100644 index 0000000..3fee7d3 --- /dev/null +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from django.views import View + +from django.utils.translation import ugettext_lazy as _ + +from django.shortcuts import render, redirect, get_object_or_404 +from django.urls import reverse_lazy + +from lostplaces.common import get_all_subclasses +from lostplaces.views.base_views import IsAuthenticatedMixin +from lostplaces.models.models import Explorer +from lostplaces.models.place import Place, PlaceAsset + +class ExplorerProfileView(IsAuthenticatedMixin, View): + def get(self, request, explorer_id): + explorer = get_object_or_404(Explorer, pk=explorer_id) + place_list = Place.objects.filter(submitted_by=explorer) + place_count = place_list.count() + + context={ + 'explorer': explorer, + 'place_count': place_count, + 'place_list': place_list, + 'assets': {} + } + + asset_count = 0 + for subclass in get_all_subclasses(PlaceAsset): # kinda ugly, but PlaceAsset cannot be abstract according to django ORM + objects = subclass.objects.filter(submitted_by=explorer) + context['assets'][subclass.__name__.lower()+'s'] = objects + asset_count += objects.count() + + context['asset_count'] = asset_count + + print(context['assets']) + + return render( + request=request, + template_name='explorer/profile.html', + context=context + ) + + \ No newline at end of file