Implement team join request functionality with views and actions
- Added join_requests.html template for displaying pending join requests. - Created join_team.html template for users to submit join requests. - Implemented request_processed.html template to show the result of join request processing. - Developed authentication utilities for user session management. - Introduced convenience redirects for common URL patterns. - Established team management routes and actions for creating, editing, and joining teams. - Added functionality for approving and denying join requests with email notifications. - Enhanced team views to include user permissions and team member details. - Implemented utility functions for team-related operations such as calculating total points and team rank.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<!-- Add this to the form, right before the submit button -->
|
||||
<div class="mb-6">
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="is_open"
|
||||
name="is_open"
|
||||
class="h-4 w-4 text-irish-green focus:ring-irish-green border-gray-300 rounded"
|
||||
>
|
||||
<label for="is_open" class="ml-2 block text-gray-700">
|
||||
Open Team (anyone can join without approval)
|
||||
</label>
|
||||
</div>
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
If unchecked, users will need to request to join and be approved by a captain.
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,18 @@
|
||||
<!-- Add this to the form, right before the submit button -->
|
||||
<div class="mb-6">
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="is_open"
|
||||
name="is_open"
|
||||
{% if team.is_open %}checked{% endif %}
|
||||
class="h-4 w-4 text-irish-green focus:ring-irish-green border-gray-300 rounded"
|
||||
>
|
||||
<label for="is_open" class="ml-2 block text-gray-700">
|
||||
Open Team (anyone can join without approval)
|
||||
</label>
|
||||
</div>
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
If unchecked, users will need to request to join and be approved by a captain.
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,90 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="max-w-4xl mx-auto my-8">
|
||||
<div class="bg-white p-8 rounded-lg shadow-md">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h1 class="text-2xl font-bold">Join Requests - {{ team.name }}</h1>
|
||||
<a href="/teams/{{ team.id }}" class="text-irish-green hover:underline">Back to Team</a>
|
||||
</div>
|
||||
|
||||
{% if request.query_params.get('message') %}
|
||||
<div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-6" role="alert">
|
||||
<p>{{ request.query_params.get('message') }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if requests|length > 0 %}
|
||||
<div class="bg-blue-50 p-4 rounded-md mb-6">
|
||||
<p class="text-blue-800">
|
||||
<i class="fas fa-info-circle mr-2"></i>
|
||||
You have {{ requests|length }} pending join request{% if requests|length > 1 %}s{% endif %}.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full bg-white border border-gray-200">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b">User</th>
|
||||
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b">Date</th>
|
||||
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b">Message</th>
|
||||
<th class="py-3 px-4 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200">
|
||||
{% for item in requests %}
|
||||
<tr>
|
||||
<td class="py-4 px-4 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
{% if item.user.picture %}
|
||||
<img src="{{ item.user.picture }}" alt="{{ item.user.username }}" class="w-8 h-8 rounded-full mr-3">
|
||||
{% else %}
|
||||
<div class="w-8 h-8 rounded-full bg-irish-green flex items-center justify-center text-white mr-3">
|
||||
<span>{{ item.user.username[0]|upper }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-900">{{ item.user.username }}</div>
|
||||
<div class="text-sm text-gray-500">{{ item.user.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="py-4 px-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ item.request.created_at.strftime('%Y-%m-%d %H:%M') }}
|
||||
</td>
|
||||
<td class="py-4 px-4 text-sm text-gray-500 max-w-xs truncate">
|
||||
{% if item.request.message %}
|
||||
{{ item.request.message }}
|
||||
{% else %}
|
||||
<span class="text-gray-400 italic">No message</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="py-4 px-4 whitespace-nowrap text-sm font-medium">
|
||||
<form action="/teams/{{ team.id }}/requests/{{ item.request.id }}" method="post" class="inline-block">
|
||||
<input type="hidden" name="decision" value="approve">
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white py-1 px-3 rounded mr-2">
|
||||
Approve
|
||||
</button>
|
||||
</form>
|
||||
<form action="/teams/{{ team.id }}/requests/{{ item.request.id }}" method="post" class="inline-block">
|
||||
<input type="hidden" name="decision" value="deny">
|
||||
<button type="submit" class="bg-red-500 hover:bg-red-600 text-white py-1 px-3 rounded">
|
||||
Deny
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center py-12">
|
||||
<i class="fas fa-inbox text-gray-300 text-5xl mb-4"></i>
|
||||
<p class="text-xl text-gray-500">No pending join requests</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="max-w-md mx-auto my-8">
|
||||
<div class="bg-white p-8 rounded-lg shadow-md">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h1 class="text-2xl font-bold">Join Request - {{ team.name }}</h1>
|
||||
<a href="/teams/{{ team.id }}" class="text-irish-green hover:underline">Back to Team</a>
|
||||
</div>
|
||||
|
||||
{% if error %}
|
||||
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-6" role="alert">
|
||||
<p>{{ error }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if is_open %}
|
||||
<div class="text-center">
|
||||
<div class="bg-green-100 p-4 rounded-md mb-6">
|
||||
<p class="text-green-800">
|
||||
<i class="fas fa-info-circle mr-2"></i>
|
||||
This is an open team. You can join immediately without approval.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form action="/teams/join/{{ team.id }}" method="post">
|
||||
<button type="submit" class="bg-irish-green text-white py-2 px-6 rounded-md hover:bg-opacity-90 transition w-full">
|
||||
Join Now
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="mb-6">
|
||||
<p class="text-gray-700 mb-4">You're requesting to join <strong>{{ team.name }}</strong>. Your request will need to be approved by a team captain.</p>
|
||||
|
||||
<form action="/teams/{{ team.id }}/join" method="post" class="space-y-4">
|
||||
<div>
|
||||
<label for="message" class="block text-sm font-medium text-gray-700 mb-1">Message (Optional)</label>
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
rows="4"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
placeholder="Tell the team why you'd like to join..."
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="w-full bg-irish-green text-white py-2 px-6 rounded-md hover:bg-opacity-90 transition">
|
||||
Send Join Request
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Request Processed{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>Team Join Request Processed</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-success">
|
||||
{{ message }}
|
||||
</div>
|
||||
<div class="text-center mt-4">
|
||||
<a href="/teams/{{ team_id }}" class="btn btn-primary">Go to Team Page</a>
|
||||
<a href="/teams" class="btn btn-outline-secondary">Back to Teams List</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user