Limit event and team listing to only those the user is connected to.

This commit is contained in:
Michael Hall 2018-03-04 14:45:25 -05:00
parent a76076e58a
commit a908901ca9
9 changed files with 32 additions and 29 deletions

View file

@ -54,16 +54,19 @@ form {
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
{% if request.user.is_authenticated %}
<li class="nav-item{% if request.resolver_match.url_name == "events" %} active{% endif %}">
<a class="nav-link" href="{% url 'events' %}">Events{% if request.resolver_match.url_name == "events" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
<li class="nav-item{% if request.resolver_match.url_name == "teams" %} active{% endif %}">
<a class="nav-link" href="{% url 'teams' %}">Teams{% if request.resolver_match.url_name == "teams" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
{% comment %}
<li class="nav-item{% if request.resolver_match.url_name == "places" %} active{% endif %}">
<a class="nav-link" href="{% url 'places' %}">Places{% if request.resolver_match.url_name == "places" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
{% endcomment %}
{% endif %}
</ul>
<ul class="navbar-nav">
{% if request.user.is_authenticated %}
@ -72,7 +75,7 @@ form {
<img class="rounded-circle mr-1" src="{{request.user.profile.avatar}}" height="24px"/>{% if request.user.profile.realname %}{{ request.user.profile.realname }}{% else %}{{ request.user.username }}{% endif %}
</a>
<div class="dropdown-menu" aria-labelledby="navbarUserMenuLink">
<a class="dropdown-item" href="{% url 'edit-profile' %}">Profile</a>
<a class="dropdown-item" href="{% url 'show-profile' request.user.profile.id %}">Profile</a>
<a class="dropdown-item" href="{% url 'logout' %}">Logout</a>
</div>
</li>

View file

@ -7,7 +7,7 @@
{% endblock %}
{% block content %}
<h3>Upcoming events</h3>
<h3>Your upcoming events</h3>
<div class="container">
<div class="row">
{% for event in events_list %}

View file

@ -25,11 +25,13 @@
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">
{% if event.team.category %}
<img class="card-img-top" src="{{event.team.category.img_url}}" alt="{{event.event_title}}">
<a href="{{event.event_url}}">
{% if event.img_url %}
<img class="card-img-top" src="{{event.img_url}}" alt="{{event.event_title}}">
{% else %}
<img class="card-img-top" src="{% static 'img/team_placeholder.png' %}" alt="{{event.event_title}}">
{% endif %}
</a>
<p class="card-title">{{event.group_name}}</p>
</div>
<div class="card-body">
@ -61,11 +63,13 @@
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">
<a href="{% url 'show-team' team.id %}">
{% if team.category %}
<img class="card-img-top" src="{{team.category.img_url}}" alt="{{team.name}}">
{% else %}
<img class="card-img-top" src="{% static 'img/team_placeholder.png' %}" alt="{{team.name}}">
{% endif %}
</a>
<p class="card-title">{{team.name}}</p>
</div>
<div class="card-body">

View file

@ -6,23 +6,10 @@
{% endblock %}
{% block content %}
{% if my_teams %}
<h4>My Teams</h4>
{% include "events/team_list.html" with teams_list=my_teams %}
<br/>
{% endif %}
{% if request.user.is_authenticated %}
<br/>
<form action="{% url 'create-team' %}" method="get">
<button type="submit" class="btn btn-primary">Start a Team</button>
</form>
{% endif %}
<h4>All Teams</h4>
<h3>Your Teams</h3>
<div class="fluid-container">
<div class="row">
{% for team in all_teams %}
{% for team in teams %}
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">

View file

@ -4,7 +4,8 @@
<div class="container">
<div class="row">
<div class="col">
<h2>Profile: {{request.user}}</h2>
<img class="align-bottom" border="1" src="{{profile.avatar}}" height="64px"/>
<h2>Profile: {{user}}</h2>
<form action="{% url "edit-profile" %}" method="post">
{% csrf_token %}
{% include "events/profile_form.html" %}

View file

@ -7,7 +7,13 @@
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-6">
<div class="h2"><img class="align-bottom" border="1" src="{{user.avatar}}" height="64px"/> {{user.user}}</div>
<div class="h2">
<img class="align-bottom" border="1" src="{{user.avatar}}" height="64px"/> {{user.user}}
{% if user.user.id == request.user.id %}
<a href="{% url 'edit-profile' %}" class="btn btn-secondary btn-sm">Edit Profile</a>
{% endif %}
</div>
<p>Full name: <strong>{{user.realname}}</strong></p>
@ -17,7 +23,7 @@
</div>
<div class="col-md-3">
{% if teams %}
<h3>Teams</h3>
<h4>Your Teams</h4>
<ul>
{% for t in teams %}
<li>

View file

@ -15,7 +15,7 @@ import simplejson
# Create your views here.
def events_list(request, *args, **kwargs):
events = Event.objects.filter(end_time__gt=datetime.datetime.now()).order_by('start_time')
events = Event.objects.filter(attendees=request.user.profile, end_time__gt=datetime.datetime.now()).order_by('start_time')
context = {
'events_list': events,
}

View file

@ -2,6 +2,7 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.contrib.auth import logout as logout_user
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.http import HttpResponse, JsonResponse
@ -14,13 +15,12 @@ import datetime
import simplejson
# Create your views here.
@login_required
def teams_list(request, *args, **kwargs):
teams = Team.objects.all()
teams = request.user.profile.memberships.all()
context = {
'all_teams': teams,
'teams': teams,
}
if request.user.is_authenticated:
context['my_teams'] = request.user.profile.memberships.all()
return render(request, 'get_together/teams/list_teams.html', context)
def show_team(request, team_id, *args, **kwargs):

View file

@ -62,6 +62,8 @@ def edit_profile(request):
profile_form = UserProfileForm(instance=profile)
context = {
'user': user,
'profile': profile,
'user_form': user_form,
'profile_form': profile_form,
}
@ -81,7 +83,7 @@ def edit_profile(request):
else:
messages.add_message(request, messages.WARNING, message=_('Your email address has changed, please confirm your new address.'))
return redirect('send-confirm-email')
return redirect('home')
return redirect('show-profile', profile.id)
else:
context = {
'user_form': user_form,