Skip to content

Commit

Permalink
add account templates
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Feb 2, 2023
1 parent 258961f commit b59a19c
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 9 deletions.
5 changes: 3 additions & 2 deletions findthatcharity/jinja2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import datetime

from django.conf import settings
from django.contrib.humanize.templatetags.humanize import naturalday, naturaltime
from django.core.cache import cache
from django.db import connection
from django.db.models import Count, F, Func
from django.templatetags.static import static
from django.urls import reverse
from django.utils.text import slugify
from humanize import naturaldelta
from markdownx.utils import markdownify

from findthatcharity.utils import (
Expand Down Expand Up @@ -129,7 +129,8 @@ def environment(**options):
env.filters.update(
{
"regex_search": regex_search,
"naturaldelta": lambda x: naturaldelta(x, minimum_unit="milliseconds"),
"naturalday": naturalday,
"naturaltime": naturaltime,
"list_to_string": list_to_string,
"slugify": slugify,
"titlecase": to_titlecase,
Expand Down
11 changes: 11 additions & 0 deletions findthatcharity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
"django.contrib.staticfiles",
"markdownx",
"prettyjson",
"django_registration",
"ninja_apikey",
"django_better_admin_arrayfield",
"django_filters",
"corsheaders",
Expand Down Expand Up @@ -276,7 +278,16 @@
DASHBOARD_ROW_LIMIT = 1000
DASHBOARD_ENABLE_FULL_EXPORT = True

ACCOUNT_ACTIVATION_DAYS = 7

TWITTER_CONSUMER_KEY = os.environ.get("TWITTER_CONSUMER_KEY")
TWITTER_CONSUMER_SECRET = os.environ.get("TWITTER_CONSUMER_SECRET")
TWITTER_ACCESS_TOKEN = os.environ.get("TWITTER_ACCESS_TOKEN")
TWITTER_ACCESS_TOKEN_SECRET = os.environ.get("TWITTER_ACCESS_TOKEN_SECRET")

DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL")
EMAIL_HOST = os.environ.get("EMAIL_HOST")
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
EMAIL_PORT = os.environ.get("EMAIL_PORT")
EMAIL_USE_SSL = os.environ.get("EMAIL_USE_SSL") == "True"
9 changes: 8 additions & 1 deletion findthatcharity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import addtocsv.views
import charity.urls
import companies.urls
import findthatcharity.views
import ftc.urls
import ftc.views
import reconcile.urls
Expand All @@ -33,8 +34,14 @@
"robots.txt",
TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
),
path(
"accounts/profile/",
findthatcharity.views.account_profile,
name="account_profile",
),
path("accounts/", include("django_registration.backends.activation.urls")),
path("accounts/", include("django.contrib.auth.urls")),
path("admin/", admin.site.urls, name="about"),
path("admin/", admin.site.urls, name="admin"),
path("", ftc.views.index, name="index"),
path("about", ftc.views.about, name="about"),
path("adddata/", addtocsv.views.index, name="csvtool"),
Expand Down
18 changes: 18 additions & 0 deletions findthatcharity/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django_sql_dashboard.models import Dashboard


def missing_page_handler(request, exception=None):
Expand All @@ -10,3 +12,19 @@ def missing_page_handler(request, exception=None):
},
status=404,
)


@login_required
def account_profile(request):
return render(
request,
"account_profile.html.j2",
{
"dashboards": {
"visible": Dashboard.get_visible_to_user(request.user).order_by("slug"),
"editable": Dashboard.get_editable_by_user(request.user).order_by(
"slug"
),
},
},
)
125 changes: 125 additions & 0 deletions jinja2/account_profile.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{% set frontpage = false %}
{% extends 'base.html.j2' %}

{% block content %}
<div class="w-60-l w-100 center" id="content">
<h1>
Your profile
<span class="gray db normal f2">User: {{ request.user.username }}</span>
</h1>
<h2>Details</h2>
<table class="table w-auto">
<tr>
<th class="tl"><span class="pr4">Username</span></th>
<td class="tl">{{ request.user.username}}</td>
</tr>
<tr>
<th class="tl"><span class="pr4">Password</span></th>
<td class="tl"><a href="#">Reset password</a></td>
</tr>
<tr>
<th class="tl"><span class="pr4">First name</span></th>
<td class="tl">{{ request.user.first_name }}</td>
</tr>
<tr>
<th class="tl"><span class="pr4">Last name</span></th>
<td class="tl">{{ request.user.last_name }}</td>
</tr>
<tr>
<th class="tl"><span class="pr4">Email address</span></th>
<td class="tl">{{ request.user.email }}</td>
</tr>
</table>
<p>
<a href="{{ url('admin:auth_user_change', args=[request.user.id]) }}">Edit profile</a>
<a href="{{ url('admin:logout') }}">Log out</a>
</p>
<h2>Billing</h2>
</div>
<script async src="https://js.stripe.com/v3/pricing-table.js"></script>
<stripe-pricing-table pricing-table-id="prctbl_1MX3dgFBOJHReeSV0oK6ZBL2"
publishable-key="pk_live_51HbP7GFBOJHReeSVszOwKajn0TeGMfRnveNnRIk8ztLHgFhzNDUeKeuy8WHEQbYGHbNbDnc3Eb98vneSLZIE3IrF00tMab25RB">
</stripe-pricing-table>
<div class="w-60-l w-100 center" id="content">
<h2>API Keys</h2>
{% set keys = request.user.apikey_set.all()|groupby("is_valid") %}
<p>API Key values are only shown when they are created. If you have lost your API key please revoke that key and generate a new one.</p>
{% for valid in keys|reverse %}
{% if not valid.grouper %}
<details class="mv4">
<summary class="pointer">Previous API keys</summary>
{% endif %}
<table class="table f6">
<thead>
<tr>
<th class=""></th>
<th class=" tl"></th>
<th class="">Created</th>
<th class="">Expires</th>
<th class=""></th>
</tr>
</thead>
<tbody class="f6">
{% for key in valid.list %}
<tr>
<td class="w3">{{ loop.index }}</td>
<td class="tl">{{ key.label }}</td>
<td class="w5"><time datetime="{{ key.created_at.isoformat() }}">{{ key.created_at|naturaltime }}</time></td>
<td class="w5">
{% if key.expires_at %}
<time datetime="{{ key.expires_at.isoformat() }}">{{ key.expires_at|naturaltime }}</time>
{% elif key.revoked %}
<span class="">Revoked</span>
{% else %}
<span class="gray">Does not expire</span>
{% endif %}
</td>
<td class="w4">
{% if key.is_valid %}
<input type="button" value="Revoke API key" />
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if not valid.grouper %}
</details>
{% endif %}
{% endfor %}
<input type="button" value="Create new API key" />
<h2>SQL Dashboard</h2>
<p>SQL Dashboard is a tool for creating SQL queries and visualizing the results. You can create a new dashboard or edit an existing one.</p>
<h3>Your SQL dashboards</h3>
<table class="table f6">
<thead>
<tr>
<th class="f6 tl"></th>
<th class="f6 tl"></th>
<th class="f6"></th>
<th class="f6">Created</th>
<th class="f6"></th>
</tr>
</thead>
<tbody class="f6">
{% for dashboard in dashboards.visible %}
<tr>
<td class="tl">
<a href="{{ dashboard.get_absolute_url() }}">{{ dashboard.title }}</a>
</td>
<td class="tl">{{ dashboard.description }}</td>
<td class="tl w4">{{ dashboard.view_summary() }}</td>
<td class="w5">
<time datetime="{{ dashboard.created_at.isoformat() }}">{{ dashboard.created_at|naturaltime }}</time>
</td>
<td class="w3">
{% if dashboard.user_can_edit(request.user) %}
<a href="{{ dashboard.get_edit_url() }}">Edit</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
8 changes: 7 additions & 1 deletion jinja2/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
<body class="home w-100 sans-serif near-black base-font bg-wavy">
<header class="body header-font normal ph3 ph5-ns pt4 {% if frontpage %}pt5-ns pb5{% else %}pb4{% endif %} moon-gray">
<div class="fr f3-ns mt1 mr2 w-100 w-auto-ns tr pb3">
<a href="{{ url('about') }}" class="white logo underline double underline-yellow">About</a>
{# <a href="{{ url('about') }}" class="white logo underline double underline-yellow">About</a>
| <a href="{{ url('about') }}#data-sources" class="white logo underline double underline-yellow">Data sources</a>
| <a href="{{ url('about') }}#privacy" class="white logo underline double underline-yellow">Privacy</a>
{% if request.user.is_superuser %}
| <a href="{{ url('admin:index') }}" class="white logo underline double underline-yellow">Admin</a>
{% endif %}#}
{% if request.user.is_authenticated %}
<a href="{{ url('account_profile') }}" class="white logo underline double underline-yellow">Profile</a>
| <a href="{{ url('admin:logout') }}" class="white logo underline double underline-yellow">Logout</a>
{% else %}
<a href="{{ url('login') }}" class="white logo underline double underline-yellow">Login</a>
{% endif %}
</div>
<h1 class="{% if frontpage %}f-subheadline-ns{% endif %} tracked-tight f1 lh-title mv0 logo normal">
Expand Down
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ django-markdownx>=4.0.0b1
django-widget-tweaks
dj-database-url
django-ninja
django-ninja-apikey
django-registration
django-sql-dashboard
whitenoise
gunicorn
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ colorama==0.4.6
# via
# click
# tqdm
confusable-homoglyphs==3.2.0
# via django-registration
coverage==7.1.0
# via -r requirements.in
cssselect==1.2.0
Expand All @@ -64,7 +66,9 @@ django==4.1.6
# django-filter
# django-markdownx
# django-ninja
# django-ninja-apikey
# django-prettyjson
# django-registration
# django-sql-dashboard
django-better-admin-arrayfield==1.4.2
# via -r requirements.in
Expand All @@ -83,9 +87,15 @@ django-filter==22.1
django-markdownx==4.0.0b1
# via -r requirements.in
django-ninja==0.20.0
# via
# -r requirements.in
# django-ninja-apikey
django-ninja-apikey==0.1.0
# via -r requirements.in
django-prettyjson==0.4.1
# via -r requirements.in
django-registration==3.3
# via -r requirements.in
django-sql-dashboard==1.1
# via -r requirements.in
django-widget-tweaks==1.4.12
Expand Down
10 changes: 5 additions & 5 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<body class="home w-100 sans-serif near-black base-font bg-wavy">
<header class="body header-font normal ph3 ph5-ns pt4 {% if frontpage %}pt5-ns pb5{% else %}pb4{% endif %} moon-gray">
<div class="fr f3-ns mt1 mr2 w-100 w-auto-ns tr pb3">
<a href="{% url 'about' %}" class="white logo underline double underline-yellow">About</a>
| <a href="{% url 'about' %}#data-sources" class="white logo underline double underline-yellow">Data sources</a>
| <a href="{% url 'about' %}#privacy" class="white logo underline double underline-yellow">Privacy</a>
{% if request.user.is_superuser %}
| <a href="{% url 'admin:index' %}" class="white logo underline double underline-yellow">Admin</a>
{% if request.user.is_authenticated %}
<a href="{% url 'account_profile' %}" class="white logo underline double underline-yellow">Profile</a>
| <a href="{% url 'admin:logout' %}" class="white logo underline double underline-yellow">Logout</a>
{% else %}
<a href="{% url 'login' %}" class="white logo underline double underline-yellow">Login</a>
{% endif %}
</div>
<h1 class="{% if frontpage %}f-subheadline-ns{% endif %} tracked-tight f1 lh-title mv0 logo normal">
Expand Down
8 changes: 8 additions & 0 deletions templates/django_registration/activation_complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<p>{% trans "Your account is now activated." %}</p>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions templates/django_registration/activation_email_body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n %}
{% trans "Activate account at" %} {{ site.name }}:

http://{{ site.domain }}{% url 'registration_activate' activation_key %}

{% blocktrans %}Link is valid for {{ expiration_days }} days.{% endblocktrans %}
1 change: 1 addition & 0 deletions templates/django_registration/activation_email_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% load i18n %}{% trans "Account activation on" %} {{ site.name }}
8 changes: 8 additions & 0 deletions templates/django_registration/registration_closed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<p>{% trans "Registration is currently closed." %}</p>
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions templates/django_registration/registration_complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<p>{% trans "You are now registered. Activation email sent." %}</p>
</div>
{% endblock %}
13 changes: 13 additions & 0 deletions templates/django_registration/registration_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}
{% load widget_tweaks %}
{% load i18n %}

{% block content %}

<div class="w-100 w-25-ns center">
<form method="post" action=".">
{% include "snippets/form.html" with button="Register" %}
</form>
</div>

{% endblock %}
8 changes: 8 additions & 0 deletions templates/registration/logged_out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<p>{% trans "Logged out" %}</p>
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions templates/registration/password_change_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<p>{% trans "Password changed" %}</p>
</div>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/registration/password_change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="w-100 w-25-ns center">
<form method="post" action=".">
{% include "snippets/form.html" with button="Change password" %}
</form>
</div>
{% endblock %}
Loading

0 comments on commit b59a19c

Please sign in to comment.