Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external links to Chapter Profile #37

Merged
merged 21 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8f65deb
Added groups model to chapters
Upasanadhameliya Oct 26, 2021
95a4b2d
Chapters inheriting from Groups
Upasanadhameliya Oct 26, 2021
e440206
Added fields to Groups
Upasanadhameliya Oct 26, 2021
ce77203
Added introduction to Groups base model
Upasanadhameliya Oct 28, 2021
7d1d137
Added homepage migration
Upasanadhameliya Oct 28, 2021
82891d8
Added members to groups as a many to many relationship
Upasanadhameliya Oct 28, 2021
03be904
Added link to chapters index from home page
Upasanadhameliya Oct 28, 2021
0b0e60d
Solved the grouping of regions in chapters index
Upasanadhameliya Oct 28, 2021
3c3f7ee
Added the logic to join a chapter or leave a chapter
Upasanadhameliya Oct 29, 2021
8448e91
Merge branch 'develop' into chapterprofile
Upasanadhameliya Nov 2, 2021
e8d9382
Reformatted models using black
Upasanadhameliya Nov 2, 2021
5dcf909
Added comments
Upasanadhameliya Nov 2, 2021
16c6e5a
Join Membership changed from "GET" to "POST"
Upasanadhameliya Nov 3, 2021
15f113d
Reformatted files with black
Upasanadhameliya Nov 3, 2021
2832a14
Added GroupsIndexPage
Upasanadhameliya Nov 10, 2021
99b7adf
Added i18n tags and removed parent page link
Upasanadhameliya Nov 10, 2021
ea078b3
Get Context in Groups Index Page was made more generic
Upasanadhameliya Nov 11, 2021
1ec55ad
Shortened and cleaned the get_context() of Group model
Upasanadhameliya Nov 11, 2021
7f687c8
Deleted irrelevant comment in Group model serve() method
Upasanadhameliya Nov 11, 2021
d568ed0
Restricted the join group form to only authenticated users
Upasanadhameliya Nov 11, 2021
46a18d3
Removed .specific to refer to child pages from home page
Upasanadhameliya Nov 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions project/chapters/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django import forms

class GroupMembershipForm(forms.Form):
MEMBERSHIP_ACTION_CHOICES = [("join", "Join"), ("leave", "Leave")]

membership_action = forms.ChoiceField(label='Membership action', choices=MEMBERSHIP_ACTION_CHOICES)
21 changes: 15 additions & 6 deletions project/chapters/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.shortcuts import redirect

from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.fields import RichTextField, StreamField
Expand All @@ -8,6 +9,7 @@
from wagtail.admin.edit_handlers import StreamFieldPanel

from accounts.models import User
from .forms import GroupMembershipForm


# Create your models here.
Expand Down Expand Up @@ -63,13 +65,20 @@ def get_context(self, request, *args, **kwargs):

def serve(self, request, *args, **kwargs):
# If query argument "join" is passed as true then add member
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved
if request.GET.get("join", "False").lower() == "true":
# Later on can add code to get admin approval to join group --------
self.members.add(request.user)
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = GroupMembershipForm(request.POST)
# check whether it's valid:
if form.is_valid():
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved
if request.user.is_authenticated:
membership_action = form.cleaned_data.get("membership_action")
if membership_action == "join":
self.members.add(request.user)
elif membership_action == "leave":
self.members.remove(request.user)
else:
return redirect("login")
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved

# If query argument "leave" is passed as true then remove member
if request.GET.get("leave", "False").lower() == "true":
self.members.remove(request.user)

return super().serve(request, *args, **kwargs)

Expand Down
15 changes: 10 additions & 5 deletions project/chapters/templates/chapters/chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
<h1>{{ page.title }}</h1>

{{ page.introduction | richtext }}
{% if member == True %}
<a class="btn btn-secondary" href="{% pageurl page %}?leave=true">Leave Chapter</a><br><br>
{% else %}
<a class="btn btn-primary" href="{% pageurl page %}?join=true">Join Chapter</a><br><br>
{% endif %}
<form action="." method="post">
{% csrf_token %}
{% if member == False %}
<input id="membership_action" type="hidden" name="membership_action" value="join">
<input type="submit" class="btn btn-primary"value="Join group">
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved
{% else %}
<input id="membership_action" type="hidden" name="membership_action" value="leave">
<input type="submit" class="btn btn-secondary" value="Leave group">
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
</form>
<p><a href="{{ page.get_parent.url }}">Return to {{ page.get_parent.title }} Page </a></p>
Upasanadhameliya marked this conversation as resolved.
Show resolved Hide resolved
{% endblock content %}