[Re: #52] Email admins on new suggestion
parent
65bac5cafb
commit
62e48dc659
|
@ -8,6 +8,9 @@ from django.contrib import messages
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseNotFound, HttpResponseServerError, HttpResponse
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from db.base.models import Mode, Transmitter, Satellite, Suggestion
|
||||
from db.base.forms import SatelliteSearchForm, SuggestionForm
|
||||
|
@ -64,6 +67,30 @@ def suggestion(request):
|
|||
suggestion.user = request.user
|
||||
suggestion.save()
|
||||
|
||||
# Notify admins
|
||||
admins = User.objects.filter(is_superuser=True)
|
||||
site = get_current_site(request)
|
||||
subject = '[{0}] A new suggestion was submitted'.format(site.name)
|
||||
template = 'emails/new_suggestion.txt'
|
||||
saturl = '{0}{1}'.format(
|
||||
site.domain,
|
||||
reverse('satellite', kwargs={'norad': suggestion.satellite.norad_cat_id})
|
||||
)
|
||||
data = {
|
||||
'satname': suggestion.satellite.name,
|
||||
'saturl': saturl,
|
||||
'site_name': site.name
|
||||
}
|
||||
message = render_to_string(template, {'data': data})
|
||||
for user in admins:
|
||||
try:
|
||||
user.email_user(subject, message, from_email=settings.DEFAULT_FROM_EMAIL)
|
||||
except:
|
||||
logger.error(
|
||||
'Could not send email to user',
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
messages.success(request, ('Your suggestion was stored successfully. '
|
||||
'Thanks for contibuting!'))
|
||||
return redirect(reverse('home'))
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="col-md-5">
|
||||
<h2>Confirm E-mail Address</h2>
|
||||
|
||||
{% if confirmation %}
|
||||
|
@ -18,7 +18,7 @@
|
|||
is an e-mail address for user {{ user_display }}.
|
||||
</p>
|
||||
<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">{% csrf_token %}
|
||||
<button class="submit" type="submit">Confirm</button>
|
||||
<button class="btn btn-default" type="submit">Confirm</button>
|
||||
</form>
|
||||
{% else %}
|
||||
{% url 'account_email' as email_url %}
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
<h2>Delete Password</h2>
|
||||
<p>You may delete your password since you are currently logged in using OpenID.</p>
|
||||
<form method="post" action="./">{% csrf_token %}
|
||||
<button class="btn" type="submit">delete my password</button>
|
||||
<button class="btn btn-danger" type="submit">delete my password</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<form method="POST" action="./" class="password_reset">{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn" type="submit">Reset My Password</button>
|
||||
<button class="btn btn-default" type="submit">Reset My Password</button>
|
||||
</form>
|
||||
<p>Please contact us if you have any trouble resetting your password.</p>
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{% if form %}
|
||||
<form method="POST" action="./">{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button type="submit" name="action">change password</button>
|
||||
<button type="btn btn-default" name="action">change password</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<p>Your password is now changed.</p>
|
||||
|
|
|
@ -6,15 +6,22 @@
|
|||
{% block title %} - Sign Up{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Sign Up</h1>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<h2>Sign Up</h2>
|
||||
|
||||
<p>Already have an account? Then please <a href="{{ login_url }}">sign in</a>.</p>
|
||||
<p>Already have an account? Then please <a href="{{ login_url }}">sign in</a>.</p>
|
||||
|
||||
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
|
||||
{% endif %}
|
||||
<button class="btn" type="submit">Sign Up »</button>
|
||||
</form>
|
||||
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
|
||||
{% endif %}
|
||||
<button class="btn btn-default" type="submit">Sign Up »</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{% extends 'emails/base.txt' %}
|
||||
|
||||
{% block main %}
|
||||
New suggestion for Satellite {{ data.satname }} was submitted!
|
||||
|
||||
{{ data.saturl }}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue