Skip to content

Commit

Permalink
updating training->events and other tweaks (#5)
Browse files Browse the repository at this point in the history
* updating training->events and other tweaks
* one missing template change
* fixing center view (has bug)

Signed-off-by: vsoch <vsochat@stanford.edu>
  • Loading branch information
vsoch committed Sep 8, 2020
1 parent b7c2afc commit a1e7d98
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 81 deletions.
7 changes: 7 additions & 0 deletions docs/_docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ the base containers are maintained for you. And a few final tips:

- if you need to re-do the storage upload, you can delete the buckets entirely (both for staging and production) and they will be re-generated.


#### Custom Domain

If you want to add a custom domain, you can purchase it with [Google Domains]()
and then [follow instructions](https://cloud.google.com/appengine/docs/standard/python3/mapping-custom-domains)
to use it for App Engine.

## Cleaning Up

You should navigate to App Engine --> Settings and then click on "Disable Application" to permanently disable it.
Expand Down
10 changes: 5 additions & 5 deletions mhttc/apps/base/templates/base/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<a href="{% url 'new_project' %}">New Project</a></li>
</ul>
</div>{% endif %}-->
<!--Training-->
<!--Events-->
{% if request.user.has_full_access %}<div class="ct-toc-item active">
<a class="ct-toc-link" href="">Training Certificates</a>
<a class="ct-toc-link" href="">Event Certificates</a>
<ul class="nav ct-sidenav">
<li class="{% if request.path == '/u/center/'%}active{% endif %}">
<a href="{% url 'center_training' %}">Training</a></li>
<li class="{% if request.path == '/training/'%}active{% endif %}">
<a href="{% url 'new_training' %}">New Training</a></li>
<a href="{% url 'center_events' %}">Events</a></li>
<li class="{% if request.path == '/event/'%}active{% endif %}">
<a href="{% url 'new_event' %}">New Event</a></li>
</ul>
</div>{% endif %}
<div class="ct-toc-item active">
Expand Down
2 changes: 1 addition & 1 deletion mhttc/apps/base/templates/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<div class="ct-page-title">
<h1 class="ct-title" id="content">
Welcome to the MHTTC Network Interweb!
Welcome to the MHTTC Network Intranet!
</h1>
<div class="avatar-group mt-3">
</div>
Expand Down
11 changes: 7 additions & 4 deletions mhttc/apps/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_temporary_image(self):
return image_path

def get_absolute_url(self):
return reverse("training_details", args=[self.uuid])
return reverse("event_details", args=[self.uuid])

def get_label(self):
return "training"
Expand All @@ -77,16 +77,19 @@ def send_certificate(self, training):
DOMAIN_NAME,
reverse("download_certificate", args=[training.uuid]),
)

message = (
"Congratulations! You've completed the training '%s' at a Mental Health Technology Transfer Network Center!\n"
"Thank you for attending the event '%s' from the Mental Health Technology Transfer Center (MHTTC) Network!\n"
"You can visit %s to download your certificate.\n\n"
"If this message was in error, please respond to this email and let us know."
"If this message was in error, please respond to this email and let us know.\n\n"
"Be sure to look for more of our events at www.mhttcnetwork.org and find "
" your MHTTC Regional or National Focus Area Center at https://mhttcnetwork.org/centers/selection"
% (training.name, url)
)
if send_email(
email_to=self.email,
message=message,
subject="[MHTTC] Your training certificate is ready!",
subject="Your event certificate of completion is ready!",
):
self.save()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{% load static %}
{% block content %}

<h1>Training for {{ center.name }}</h1>
<h1>Events for {{ center.name }}</h1>
<hr>
{% if events.count > 0 %}
<table class="table table-bordered" id="center-trining" width="100%" cellspacing="0">
<thead>
<tr>
<th>Title of Training</th>
<th>Title of Event</th>
<th>Description</th>
<th>Contact</th>
<th></th>
Expand All @@ -18,11 +18,11 @@ <h1>Training for {{ center.name }}</h1>
<td>{{ training.name }}</td>
<td>{{ training.description | truncatechars:100 }}</td>
<td><a href="mailto:{{ training.contact.email }}">{{ training.contact.email }}</a></td>
<td><a href="{% url 'edit_training' training.uuid %}"><button type="button" class="btn btn-primary btn-sm">Edit</button></a>
<td><a href="{% url 'edit_event' training.uuid %}"><button type="button" class="btn btn-primary btn-sm">Edit</button></a>
<a href="{{ training.get_absolute_url }}"><button type="button" class="btn btn-primary btn-sm">View</button></a></td>
</tr>{% endfor %}
</tbody>
</table>
{% else %}
<p class="alert alert-primary">The {{ request.user.center.name }} does not have any training events! <a style="float:right" href="{% url 'new_training' %}"><button class="btn btn-primary btn-sm" type="button">make a new training</button></a>.</p>{% endif %}
<p class="alert alert-primary">The {{ request.user.center.name }} does not have any events! <a style="float:right" href="{% url 'new_event' %}"><button class="btn btn-primary btn-sm" type="button">make a new event</button></a>.</p>{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2>Send Certificates</h2>
<div class="tab-pane show" id="nav-certificate" role="tabpanel" aria-labelledby="nav-certificate-tab" style="padding-top:20px">
{% if training.image_data %}<img src="data:image/png;base64, {{ training.image_data }}">{% endif %}

<form method="POST" class="post-form" enctype="multipart/form-data" action="{% url 'update_training_image' training.uuid %}">{% csrf_token %}
<form method="POST" class="post-form" enctype="multipart/form-data" action="{% url 'update_event_image' training.uuid %}">{% csrf_token %}
<p><label for="id_file">Update Image File (png saved from template):</label><input accept="image/x-png" type="file" name="file" class="form-control" required="" id="id_file"></p>
<button type="submit" class="save btn btn-default">Save</button>
</form>
Expand Down Expand Up @@ -68,7 +68,7 @@ <h2 style="padding-top:40px">Current Participants</h2>
</thead>
<tbody>
<tr>
<td>Title of Training</td>
<td>Title of Event</td>
<td>{{ training.name }}</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<table class="table table-bordered" id="trainings_table" width="100%" cellspacing="0">
<thead>
<tr>
<th>Title of Training</th>
<th>Title of Event</th>
<th>Description</th>
<th></th>
<th></th>
Expand All @@ -10,7 +10,7 @@
</thead>
<tbody>{% for training in trainings %}
<tr>
<td><a href="{% url 'training_details' training.uuid %}">{{ training.name }}</a></td>
<td><a href="{% url 'event_details' training.uuid %}">{{ training.name }}</a></td>
<td style="white-space: break-spaces">{{ training.description | truncatechars:100 }}</td>
<td></td>
<td></td>
Expand Down
20 changes: 20 additions & 0 deletions mhttc/apps/main/templates/events/new_event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base/page.html" %}
{% load static %}
{% block content %}
<h2>{% if form.name.value %}Edit{% else %}New{% endif %} Event</h2>
<hr>
<p class="alert alert-info" style="max-width:100%">This event {% if form.name.value %}is{% else %}will be{% endif %} associated with your center, {{ request.user.center.name }}. By default, the certificate will use <a target="_blank" href="https://docs.google.com/presentation/d/1V7YYtwcwfhSd1WJ9C0XGWOLwXjPU6zcdFxjeGYeXJJE/edit?usp=sharing">this template</a>. To customize this template for your event, open the template, update the logo(s) and the signature(s), and delete the orange box. Do not move or edit the information that is covered by the orange box. Then File -> Download -> PNG Image (current slide). Then save the image on your computer, and then upload it in the "Image File" box below.</p>

<br><a href="{% url 'center_events' %}"><< back</a>
<hr>
<form method="POST" class="post-form" enctype="multipart/form-data">{% csrf_token %}
<p><label for="id_name">Title of Event:</label> <input type="text" name="name" maxlength="250" class="form-control" required id="id_name"></p>
<p><label for="id_description">Description:</label> <input type="text" name="description" maxlength="500" class="form-control" id="id_description"></p>
<p><label for="id_contact">Contact:</label> <select name="contact" class="form-control" required id="id_contact">
<option value="" selected>---------</option>{% for user in request.user.center.user_set.all %}
<option value="{{ user.id }}">{{ user.username }}</option>{% endfor %}
</select></p>
<p><label for="id_file">Image File (png saved from template):</label><input accept="image/x-png" type="file" name="file" class="form-control" required="" id="id_file"></p>
<button type="submit" class="save btn btn-default">Save</button>
</form>
{% endblock %}
20 changes: 0 additions & 20 deletions mhttc/apps/main/templates/training/new_training.html

This file was deleted.

18 changes: 9 additions & 9 deletions mhttc/apps/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
path(
"project/forms/<uuid:uuid>/", views.view_project_form, name="view_project_form"
),
# Training
path("training/new/", views.new_training, name="new_training"),
# Events
path("event/new/", views.new_event, name="new_event"),
path(
"training/<uuid:uuid>/certificate/",
"event/<uuid:uuid>/certificate/",
views.download_certificate,
name="download_certificate",
),
path(
"training/<uuid:uuid>/update/image",
views.update_training_image,
name="update_training_image",
"event/<uuid:uuid>/update/image",
views.update_event_image,
name="update_event_image",
),
path("training/<uuid:uuid>/edit", views.edit_training, name="edit_training"),
path("training/<uuid:uuid>/", views.training_details, name="training_details"),
path("center/training/", views.center_training, name="center_training"),
path("event/<uuid:uuid>/edit", views.edit_event, name="edit_event"),
path("event/<uuid:uuid>/", views.event_details, name="event_details"),
path("center/events/", views.center_events, name="center_events"),
]
4 changes: 2 additions & 2 deletions mhttc/apps/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def make_certificate_response(name, center, training_title, image_path=None):

response = HttpResponse(content_type="application/pdf")
response["Content-Disposition"] = (
'attachment; filename="MHTTC-training-%s-certificate.pdf"'
'attachment; filename="MHTTC-event-%s-certificate.pdf"'
% center.replace(" ", "-").lower()
)

Expand All @@ -50,6 +50,6 @@ def make_certificate_response(name, center, training_title, image_path=None):

# More body Text ...
c.setFont("Helvetica", 20, leading=None)
c.drawCentredString(480, 150, center + ": " + training_title)
c.drawCentredString(480, 150, training_title)
c.save()
return response
50 changes: 25 additions & 25 deletions mhttc/apps/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ def view_project_form(request, uuid):
raise Http404


## Training
## Events


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
@user_agree_terms
def new_training(request):
"""Create a new training. A user that does not have full access to the site
def new_event(request):
"""Create a new event. A user that does not have full access to the site
cannot see this view
"""
if not request.user.has_full_access:
Expand All @@ -256,17 +256,17 @@ def new_training(request):
training.center = request.user.center
training.image_data = encoded_string
training.save()
return redirect("training_details", uuid=training.uuid)
return redirect("event_details", uuid=training.uuid)
else:
form = TrainingForm()
return render(request, "training/new_training.html", {"form": form})
return render(request, "events/new_event.html", {"form": form})


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
@user_agree_terms
def center_training(request):
"""Return a listing of training events being held by the center. A user
def center_events(request):
"""Return a listing of events being held by the center. A user
that does not have full access to the site cannot see this view.
"""
if not request.user.has_full_access:
Expand All @@ -279,16 +279,16 @@ def center_training(request):
events = Training.objects.filter(center=request.user.center)
return render(
request,
"training/center_training.html",
"events/center_events.html",
{"events": events, "center": request.user.center},
)


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
@user_agree_terms
def training_details(request, uuid):
"""Return the details of a training. A user that does not have full access
def event_details(request, uuid):
"""Return the details of an event. A user that does not have full access
to the site cannot see this view.
"""
if not request.user.has_full_access:
Expand All @@ -307,15 +307,15 @@ def training_details(request, uuid):
or not request.user.has_full_access
):
messages.warning(request, "You are not allowed to perform this action.")
return redirect("center_training")
return redirect("center_events")

# Can only send if there is an associated image data
if training.image_data in [None, ""]:
messages.info(
request,
"You must upload a certificate template before sending certificates.",
)
return redirect("training_details", uuid=training.uuid)
return redirect("event_details", uuid=training.uuid)

# Add new participant emails
emails = request.POST.get("emails", "")
Expand Down Expand Up @@ -351,7 +351,7 @@ def training_details(request, uuid):

return render(
request,
"training/training_details.html",
"events/event_details.html",
context={"training": training, "edit_permission": edit_permission},
)
except Training.DoesNotExist:
Expand All @@ -361,8 +361,8 @@ def training_details(request, uuid):
@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
@user_agree_terms
def update_training_image(request, uuid):
"""update the image for a training.
def update_event_image(request, uuid):
"""update the image for an event.
"""
if request.method == "POST":

Expand All @@ -374,21 +374,21 @@ def update_training_image(request, uuid):
# Only allowed to edit for their center
if request.user.center != training.center:
messages.warning(request, "You are not allowed to perform this action.")
return redirect("center_training")
return redirect("center_events")

training.image_data = base64.b64encode(request.FILES["file"].read()).decode(
"utf-8"
)
training.save()

return redirect("training_details", uuid=training.uuid)
return redirect("event_details", uuid=training.uuid)


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
@user_agree_terms
def edit_training(request, uuid):
"""edit training details
def edit_event(request, uuid):
"""edit event details
"""
try:
training = Training.objects.get(uuid=uuid)
Expand All @@ -398,23 +398,23 @@ def edit_training(request, uuid):
# Only allowed to edit for their center
if request.user.center != training.center:
messages.warning(request, "You are not allowed to perform this action.")
return redirect("center_training")
return redirect("center_events")

if request.method == "POST":
form = TrainingForm(request.POST)
if form.is_valid():
training = form.save(commit=False)
training.center = request.user.center
training.save()
return redirect("training_details", uuid=training.uuid)
return redirect("event_details", uuid=training.uuid)
else:
form = TrainingForm(initial=model_to_dict(training))
return render(request, "training/new_training.html", {"form": form})
return render(request, "events/new_event.html", {"form": form})


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
def download_certificate(request, uuid):
"""download a certificate for a training.
"""download a certificate for an event.
"""
try:
training = Training.objects.get(uuid=uuid)
Expand All @@ -435,7 +435,7 @@ def download_certificate(request, uuid):
)
return render(
request,
"training/download_certificate.html",
"events/download_certificate.html",
{"form": form, "training": training},
)

Expand All @@ -451,6 +451,6 @@ def download_certificate(request, uuid):
form = CertificateForm()
return render(
request,
"training/download_certificate.html",
"events/download_certificate.html",
{"form": form, "training": training},
)

0 comments on commit a1e7d98

Please sign in to comment.