From 88c809a50d73878186841b02d081da652f5ab9e2 Mon Sep 17 00:00:00 2001 From: Bheesham Persaud Date: Sat, 24 Feb 2018 00:42:03 -0500 Subject: [PATCH 1/2] Add show-profile view. Allows users to view the profiles of other people. --- events/migrations/0009_auto_20180224_0556.py | 23 +++++++++++++ events/templates/events/team_list.html | 2 +- .../get_together/events/show_event.html | 4 ++- .../get_together/teams/show_team.html | 2 +- .../get_together/users/show_profile.html | 32 +++++++++++++++++++ get_together/urls.py | 1 + get_together/views/user.py | 21 ++++++++++++ 7 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 events/migrations/0009_auto_20180224_0556.py create mode 100644 get_together/templates/get_together/users/show_profile.html diff --git a/events/migrations/0009_auto_20180224_0556.py b/events/migrations/0009_auto_20180224_0556.py new file mode 100644 index 0000000..9990892 --- /dev/null +++ b/events/migrations/0009_auto_20180224_0556.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0 on 2018-02-24 05:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0008_add-team-description'), + ] + + operations = [ + migrations.AlterField( + model_name='searchable', + name='venue_name', + field=models.CharField(blank=True, max_length=256), + ), + migrations.AlterField( + model_name='userprofile', + name='avatar', + field=models.URLField(blank=True, max_length=150, null=True, verbose_name='Photo Image'), + ), + ] diff --git a/events/templates/events/team_list.html b/events/templates/events/team_list.html index d70b9a6..8a1a995 100644 --- a/events/templates/events/team_list.html +++ b/events/templates/events/team_list.html @@ -7,7 +7,7 @@ {{ team.country.name|default:'' }} {{ team.spr.name|default:'' }} {{ team.city.name|default:'' }} - {{ team.owner_profile }} + {{ team.owner_profile }} {{ team.created_time }} {% endfor %} diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index cc455f2..7f9bf79 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -75,7 +75,9 @@ {% for badge in attendee.user.user.account.badges.all %}{% endfor %}
-
{{attendee.user}} {{ attendee.status_name }}
+
+ {{attendee.user}} + {{ attendee.status_name }}
{% if attendee.role > 0 %}{{ attendee.role_name }}{% endif %}
diff --git a/get_together/templates/get_together/teams/show_team.html b/get_together/templates/get_together/teams/show_team.html index e3a2567..79debb5 100644 --- a/get_together/templates/get_together/teams/show_team.html +++ b/get_together/templates/get_together/teams/show_team.html @@ -61,7 +61,7 @@ {% for badge in member.user.user.account.badges.all %}{% endfor %}
-
{{member.user}}
+
{{member.user}}
{% if member.role > 0 %}{{ member.role_name }}{% endif %}
diff --git a/get_together/templates/get_together/users/show_profile.html b/get_together/templates/get_together/users/show_profile.html new file mode 100644 index 0000000..0ccf8af --- /dev/null +++ b/get_together/templates/get_together/users/show_profile.html @@ -0,0 +1,32 @@ +{% extends "get_together/base.html" %} + +{% block content %} + +{% if user %} + +

Profile: {{user.user}}

+ +Realname: {{user.realname}}
+ +{% if user.weburl %} +Homepage: {{user.weburl}}
+{% endif %} + +{% if teams %} +

Teams

+ +{% endif %} + +{% else %} + +

User not found.

+ +{% endif %} + +{% endblock %} diff --git a/get_together/urls.py b/get_together/urls.py index 198f633..92dc359 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -36,6 +36,7 @@ urlpatterns = [ path('api/find_city/', event_views.find_city), path('profile/+edit', views.edit_profile, name='edit-profile'), + path('profile//', views.show_profile, name='show-profile'), path('events/', views.events_list, name='events'), path('+create-team/', views.create_team, name='create-team'), diff --git a/get_together/views/user.py b/get_together/views/user.py index 088b035..c7c9aad 100644 --- a/get_together/views/user.py +++ b/get_together/views/user.py @@ -4,6 +4,7 @@ from django.contrib import messages from django.contrib.auth import logout as logout_user from django.shortcuts import render, redirect from django.http import HttpResponse, JsonResponse +from django.core.exceptions import ObjectDoesNotExist from events.models.profiles import Team, UserProfile, Member from events.forms import UserForm, UserProfileForm @@ -27,6 +28,26 @@ def login(request): return redirect('home') return render(request, 'get_together/users/login.html') + +def show_profile(request, user_id): + + template = 'get_together/users/show_profile.html' + + try: + user = UserProfile.objects.get(id=user_id) + except ObjectDoesNotExist: + return render(request, template, {'user': None}, status=404) + + teams = Member.objects.filter(user_id=user_id) + + context = { + 'user': user, + 'teams': teams, + } + + return render(request, template, context) + + def edit_profile(request): if not request.user.is_authenticated: messages.add_message(request, messages.WARNING, message=_('You must be logged in to edit your profile.')) From 5f4d85f7093352bcab147aebf92958ac147b6b3d Mon Sep 17 00:00:00 2001 From: Bheesham Persaud Date: Sun, 25 Feb 2018 12:11:26 -0500 Subject: [PATCH 2/2] Fix bug with show-profile. --- get_together/templates/get_together/users/show_profile.html | 2 +- get_together/views/user.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/get_together/templates/get_together/users/show_profile.html b/get_together/templates/get_together/users/show_profile.html index 0ccf8af..20d79e6 100644 --- a/get_together/templates/get_together/users/show_profile.html +++ b/get_together/templates/get_together/users/show_profile.html @@ -17,7 +17,7 @@ Homepage: {{user.weburl}}
diff --git a/get_together/views/user.py b/get_together/views/user.py index c7c9aad..1f0a47e 100644 --- a/get_together/views/user.py +++ b/get_together/views/user.py @@ -38,7 +38,7 @@ def show_profile(request, user_id): except ObjectDoesNotExist: return render(request, template, {'user': None}, status=404) - teams = Member.objects.filter(user_id=user_id) + teams = user.memberships.all() context = { 'user': user,