merge trunk
commit 8b9d125e0fef4a409290e5b10b58a64bb637b6c6
2 parents d663fcd + a1cdfa4
@Abhilash Raj Abhilash Raj authored on 14 Apr 2015
Showing 7 changed files
View
22
src/postorius/models.py
 
from datetime import datetime, timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.core.mail import send_mail
from django.db import models
from django.http import Http404
objects = AddressConfirmationProfileManager()
 
def __unicode__(self):
return u'Address Confirmation Profile for {0}'.format(self.email)
 
@property
def is_expired(self):
"""
a profile expires after 1 day by default.
>>> EMAIL_CONFIRMATION_FROM = 'postmaster@list.org'
>>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed'
 
:param request: The HTTP request object.
:type request: HTTPRequest
:type request: HTTPRequest
:param template_context: The context used when rendering the template.
Falls back to host url and activation link.
Falls back to host url and activation link.
:type template_context: django.template.Context
"""
# create the host url and the activation link need for the template
host_url = self._create_host_url(request)
# Get the url string from url conf.
url = reverse('address_activation_link',
kwargs={'activation_key': self.activation_key})
activation_link = '{0}{1}'.format(host_url, url)
# Detect the right template path, either from the param,
# Detect the right template path, either from the param,
# the setting or the default
if not template_path:
template_path = getattr(settings,
'EMAIL_CONFIRMATION_TEMPLATE',
template_context = Context(
{'activation_link': activation_link, 'host_url': host_url})
email_subject = getattr(
settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed')
try:
sender_address = getattr(settings, 'EMAIL_CONFIRMATION_FROM')
except AttributeError:
# settings.EMAIL_CONFIRMATION_FROM is not defined, fallback
# settings.DEFAULT_EMAIL_FROM as mentioned in the django
# docs. If that also fails, raise a `ImproperlyConfigured` Error.
try:
sender_address = getattr(settings, 'DEFAULT_FROM_EMAIL')
except AttributeError:
raise ImproperlyConfigured
 
send_mail(email_subject,
get_template(template_path).render(template_context),
getattr(settings, 'EMAIL_CONFIRMATION_FROM'),
sender_address,
[self.email])
View
3
■■
src/postorius/templates/postorius/base.html
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--><!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--><!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--><!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 
<title></title>
<title>Mailman/Postorius</title>
<meta name="description" content="">
<meta name="author" content="">
 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="{% static 'postorius/img/apple-touch-icon.png' %}">
 
<link rel="stylesheet" href="{% static 'postorius/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'postorius/css/style.css' %}">
 
</head>
<body class="{% block body_class %}{% endblock %}">
 
<header>
View
2
■■■
src/postorius/templates/postorius/lists/memberoptions.html
{% load i18n %}
{% load nav_helpers %}
 
{% block main %}
{% list_nav '' '' %}
{% list_nav '' 'Member Options' %}
 
{% if not user.is_superuser or not user.is_list_owner %}
<div class="mm_subHeader" >
<h1>{% trans "No Preferences Available" %}</h1>
View
2
■■■
src/postorius/templates/postorius/menu/list_nav.html
{% endif %}
{% if user.is_superuser or user.is_list_owner %}
<li class="mm_nav_item"><a class="{% nav_active_class current 'list_settings' %}" href="{% url 'list_settings' list.list_id %}">{% trans "Settings" %}</a></li>
{% endif %}
{% if user.is_superuser or user.is_list_moderator %}
{% if user.is_superuser or user.is_list_owner %}
<li class="mm_nav_item"><a class="{% nav_active_class current 'mass_subscribe' %}" href="{% url 'mass_subscribe' list.list_id %}">{% trans "Mass Subscribe" %}</a></li>
{% endif %}
{% if user.is_superuser or user.is_list_owner %}
<li class="mm_nav_item"><a class="{% nav_active_class current 'list_delete' %}" href="{% url 'list_delete' list.list_id %}">{% trans "Delete List" %}</a></li>
View
1
■■■■
src/postorius/templates/postorius/user_address_activation_sent.html
<h1>{% trans 'Email address activation sent' %}</h1>
<p>{% trans "A confirmation link has been sent to the email address you submitted. Please check your email account and click on the confirmation link to add this address for your account." %}</p>
{% endblock main %}
View
8
src/postorius/urls.py
url(r'^$',
ListSummaryView.as_view(
), name='list_summary'),
url(r'^subscribe$',
ListSubsribeView.as_view(
ListSubscribeView.as_view(
), name='list_subscribe'),
url(r'^unsubscribe/(?P<email>[^/]+)$',
ListUnsubscribeView.as_view(
), name='list_unsubscribe'),
url(r'^subscriptions$',
'list_subscriptions',
name='list_subscriptions'),
url(r'^mass_subscribe/$',
ListMassSubsribeView.as_view(
ListMassSubscribeView.as_view(
), name='mass_subscribe'),
url(r'^delete$',
'list_delete', name='list_delete'),
url(r'^held_messages/(?P<msg_id>[^/]+)/'
urlpatterns = patterns(
'postorius.views',
(r'^$', 'list_index'),
# /account/
url(r'^accounts/login/$', login_view, {"template_name": "postorius/login.html"}, name='user_login'),
url(r'^accounts/login/$', login_view,
{"template_name": "postorius/login.html"}, name='user_login'),
url(r'^accounts/logout/$', 'user_logout', name='user_logout'),
url(r'^accounts/profile/$', 'user_profile', name='user_profile'),
url(r'^tasks/$', 'user_tasks', name='user_tasks'),
url(r'^accounts/subscriptions/$', UserSubscriptionsView.as_view(),
View
40
src/postorius/views/list.py
user_passes_test)
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from urllib2 import HTTPError
 
'subscribed_address': subscribed_address},
context_instance=RequestContext(request))
 
 
class ListSubsribeView(MailingListView):
class ListSubscribeView(MailingListView):
 
"""Subscribe a mailing list."""
 
@method_decorator(login_required)
messages.error(request, e)
return redirect('list_summary', self.mailing_list.list_id)
 
 
class ListMassSubsribeView(MailingListView):
class ListMassSubscribeView(MailingListView):
 
"""Mass subscription."""
 
@method_decorator(list_owner_required)
messages.error(request, 'Please fill out the form correctly.')
else:
emails = request.POST["emails"].splitlines()
for email in emails:
parts = email.split('@')
if len(parts) != 2 or '.' not in parts[1]:
try:
validate_email(email)
self.mailing_list.subscribe(address=email)
messages.success(request,
'The address %s has been subscribed to %s.' %
(email, self.mailing_list.fqdn_listname))
except MailmanApiError:
return utils.render_api_error(request)
except HTTPError, e:
messages.error(request, e)
except ValidationError:
messages.error(request,
'The email address %s is not valid.' %
email)
else:
try:
self.mailing_list.subscribe(address=email)
messages.success(
request,
'The address %s has been subscribed to %s.' %
(email, self.mailing_list.fqdn_listname))
except MailmanApiError:
return utils.render_api_error(request)
except HTTPError, e:
messages.error(request, e)
return redirect('mass_subscribe', self.mailing_list.list_id)
 
 
def _get_choosable_domains(request):
try:
domains = Domain.objects.all()