Skip to content

Commit

Permalink
Add local Django community page (#1371)
Browse files Browse the repository at this point in the history
* Add django-countries requirement

This django package provides the equivalent of a choice field containing a list of all the countries in the world.

This will be used when adding a Local Django Community to the new section of the community page.

* Add LocalDjangoCommunity model

This model facilitates the listing of local django communities from around the world. This will be listed on a page within the community section of the website.

* Add Local Django Communities page to the community section

This change adds the local django communities page to the communities section of djangoproject.com

* Fix accessibility community page and add empty case

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sarah Abderemane <sarahabderemane@gmail.com>
  • Loading branch information
3 people authored Nov 25, 2023
1 parent 44dd5a8 commit dfa7429
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 5 deletions.
16 changes: 15 additions & 1 deletion aggregator/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from django.contrib import admin

from .models import APPROVED_FEED, DENIED_FEED, Feed, FeedItem, FeedType
from .models import (
APPROVED_FEED,
DENIED_FEED,
Feed,
FeedItem,
FeedType,
LocalDjangoCommunity,
)


@admin.action(description="Mark selected feeds as approved.")
Expand Down Expand Up @@ -41,3 +48,10 @@ def mark_denied(modeladmin, request, queryset):
FeedType,
prepopulated_fields={"slug": ("name",)},
)

admin.site.register(
LocalDjangoCommunity,
prepopulated_fields={"slug": ("name",)},
list_filter=["name", "city", "country", "is_active"],
search_fields=["name", "city", "country"],
)
34 changes: 34 additions & 0 deletions aggregator/migrations/0004_add_local_django_community.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.19 on 2023-06-05 03:45

from django.db import migrations, models
import django_countries.fields


class Migration(migrations.Migration):

dependencies = [
('aggregator', '0003_increase_url_max_length'),
]

operations = [
migrations.CreateModel(
name='LocalDjangoCommunity',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=120)),
('description', models.TextField()),
('slug', models.SlugField(max_length=125)),
('city', models.CharField(max_length=85)),
('country', django_countries.fields.CountryField(max_length=2)),
('continent', models.CharField(choices=[('Africa', 'Africa'), ('North America', 'North America'), ('South America', 'South America'), ('Europe', 'Europe'), ('Asia', 'Asia'), ('Oceania', 'Oceania'), ('Antarctica', 'Antarctica')], max_length=15)),
('website_url', models.URLField(blank=True, default=None, max_length=250, null=True)),
('event_site_url', models.URLField(blank=True, default=None, max_length=250, null=True)),
('is_active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.AddConstraint(
model_name='localdjangocommunity',
constraint=models.CheckConstraint(check=models.Q(models.Q(('event_site_url__isnull', False), ('website_url__isnull', False)), models.Q(('event_site_url__isnull', False), ('website_url__isnull', True)), models.Q(('event_site_url__isnull', True), ('website_url__isnull', False)), _connector='OR'), name='website_url_and_or_event_site_url'),
),
]
48 changes: 48 additions & 0 deletions aggregator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import feedparser
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
from django_countries.fields import CountryField
from django_push.subscriber import signals as push_signals
from django_push.subscriber.models import Subscription

Expand Down Expand Up @@ -190,3 +192,49 @@ def feed_updated(sender, notification, **kwargs):


push_signals.updated.connect(feed_updated)

CONTINENTS = [
("Africa", "Africa"),
("North America", "North America"),
("South America", "South America"),
("Europe", "Europe"),
("Asia", "Asia"),
("Oceania", "Oceania"),
("Antarctica", "Antarctica"),
]


class LocalDjangoCommunity(models.Model):
name = models.CharField(max_length=120)
description = models.TextField()
slug = models.SlugField(max_length=125)
city = models.CharField(max_length=85)
country = CountryField()
continent = models.CharField(choices=CONTINENTS, max_length=15)
website_url = models.URLField(max_length=250, default=None, blank=True, null=True)
event_site_url = models.URLField(
max_length=250, default=None, blank=True, null=True
)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
constraints = [
models.CheckConstraint(
check=(
models.Q(website_url__isnull=False, event_site_url__isnull=False)
| models.Q(website_url__isnull=True, event_site_url__isnull=False)
| models.Q(website_url__isnull=False, event_site_url__isnull=True)
),
name="website_url_and_or_event_site_url",
),
]

def clean(self):
if not self.website_url and not self.event_site_url:
raise ValidationError(
"You must provide at least a website or event site URL"
)

def __str__(self):
return self.name
5 changes: 5 additions & 0 deletions aggregator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

urlpatterns = [
path("", views.index, name="community-index"),
path(
"local/",
views.LocalDjangoCommunitiesListView.as_view(),
name="local-django-communities",
),
path("mine/", views.my_feeds, name="community-my-feeds"),
path("<feed_type_slug>/", views.FeedListView.as_view(), name="community-feed-list"),
path("add/<feed_type_slug>/", views.add_feed, name="community-add-feed"),
Expand Down
15 changes: 14 additions & 1 deletion aggregator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.views.generic.list import ListView

from .forms import FeedModelForm
from .models import APPROVED_FEED, Feed, FeedItem, FeedType
from .models import APPROVED_FEED, Feed, FeedItem, FeedType, LocalDjangoCommunity


def index(request):
Expand Down Expand Up @@ -108,3 +108,16 @@ def delete_feed(request, feed_id):
feed.delete()
return redirect("community-my-feeds")
return render(request, "aggregator/delete-confirm.html", {"feed": feed})


class LocalDjangoCommunitiesListView(ListView):
"""
Shows a list of community meetups
"""

model = LocalDjangoCommunity
context_object_name = "django_communities"
template_name = "aggregator/local-django-community.html"

def get_queryset(self):
return self.model.objects.all().order_by("continent").values()
9 changes: 9 additions & 0 deletions djangoproject/scss/_dark-mode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ html[data-theme="light"],
--search-mark-text: #{$green-dark};

--selection: #{$green-very-light};

--community-img-bg: #{$green-very-light};
--community-img-fg: #{$green-dark};
}

@media (prefers-color-scheme: dark) {
Expand Down Expand Up @@ -105,6 +108,9 @@ html[data-theme="light"],
--search-mark-text: #{$black-light-5};

--selection: #{$green-medium};

--community-img-bg: #{$green-dark};
--community-img-fg: #{$white};
}

body .homepage {
Expand Down Expand Up @@ -201,6 +207,9 @@ html[data-theme="dark"] {

--selection: #{$green-dark};

--community-img-bg: #{$green-dark};
--community-img-fg: #{$white};

.img-release {
filter: invert(1);
}
Expand Down
6 changes: 3 additions & 3 deletions djangoproject/scss/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3685,11 +3685,11 @@ ul.corporate-members li {
flex-direction: column;
justify-content: center;
align-items: center;
background: var(--secondary-accent);
background: var(--community-img-bg);
border-radius: 20px;
}

.community-cta svg {
color: var(--body-fg);
.community-cta svg, h3 {
color: var(--community-img-fg);
}
}
9 changes: 9 additions & 0 deletions djangoproject/templates/aggregator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ <h3>Report an issue</h3>
<h3>Contribute to Django</h3>
</div>
</a>
<a href="/community/local/" class="community-cta-a">
<div class="community-cta">
<div>
{# Material Symbols - Copyright 2022 Google LLC - Used under terms of Apache 2.0 license #}
<svg xmlns="http://www.w3.org/2000/svg" height="150" viewBox="0 -960 960 960" width="150"><path d="M480.089-490Q509-490 529.5-510.589q20.5-20.588 20.5-49.5Q550-589 529.411-609.5q-20.588-20.5-49.5-20.5Q451-630 430.5-609.411q-20.5 20.588-20.5 49.5Q410-531 430.589-510.5q20.588 20.5 49.5 20.5ZM480-159q133-121 196.5-219.5T740-552q0-117.79-75.292-192.895Q589.417-820 480-820t-184.708 75.105Q220-669.79 220-552q0 75 65 173.5T480-159Zm0 79Q319-217 239.5-334.5T160-552q0-150 96.5-239T480-880q127 0 223.5 89T800-552q0 100-79.5 217.5T480-80Zm0-472Z" fill="currentColor"/></svg>
</div>
<h3>Local Django Community</h3>
</div>
</a>
</div>

<h2>Django RSS feeds</h2>
Expand Down
51 changes: 51 additions & 0 deletions djangoproject/templates/aggregator/local-django-community.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "base_community.html" %}

{% block content %}

{# Group meetups by country and then by location #}
{% regroup django_communities|dictsort:"continent" by continent as grouped_django_communities %}


<h2>Local Django Communities</h2>

{% if grouped_django_communities %}<h3>Table of contents<a class="plink" href="#table-of-contents"></a></h3>{% endif %}
<ul>
{% for local_django_community in grouped_django_communities %}
<li><a href="#{{ local_django_community.grouper.title }}-meetups">{{ local_django_community.grouper.title }}</a></li>
{% endfor %}
</ul>


{% for local_django_community in grouped_django_communities %}
<div class="section">
<h2>{{ local_django_community.grouper.title }} <a class="plink" href="#{{ local_django_community.grouper.title | lower }}-meetups"></a></h2>
<ul>
{% for django_community in local_django_community.list %}
<li>
<h3 id="{{ django_community.slug }}-team">{{ django_community.name }} <a class="plink" href="#{{ django_community.slug }}-meetup"></a></h3>
<p class="meta">{{ django_community.city }}, {{ django_community.country }} &nbsp;
{% if django_community.is_active %}
Active
{% else %}
Inactive
{% endif %}
</p>
<p>{{ django_community.description|safe }}</p>
<p>
{% if django_community.website_url %}
<a href="{{ django_community.website_url }}">Community Website</a> &nbsp;
{% endif %}
{% if django_community.event_site_url %}
<a href="{{ django_community.event_site_url }}">Event Website</a>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
</div>
{% empty %}
Local Django communities are coming soon. Please check back later.

{% endfor %}
{##}
{% endblock %}
1 change: 1 addition & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Babel==2.10.1
django-contact-form==1.9
django-countries==7.5.1
django-hosts==5.1
django-money==2.1.1
django-push==1.1
Expand Down

0 comments on commit dfa7429

Please sign in to comment.