Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/thraxil/spokehub
Browse files Browse the repository at this point in the history
  • Loading branch information
argoncobalt committed Mar 12, 2016
2 parents 7f267eb + dff6a51 commit 42e819b
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 41 deletions.
Empty file added spokehub/broadcast/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions spokehub/broadcast/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BroadcastConfig(AppConfig):
name = 'broadcast'
10 changes: 10 additions & 0 deletions spokehub/broadcast/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import forms


class BroadcastForm(forms.Form):
subject = forms.CharField(label='Subject', required=True)
body = forms.CharField(
label='message body',
required=True,
widget=forms.Textarea(attrs={'style': 'width: 100%'}),
)
Empty file.
25 changes: 25 additions & 0 deletions spokehub/broadcast/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase, Client
from spokehub.main.tests.factories import UserFactory


class BroadcastViewTest(TestCase):
def setUp(self):
self.c = Client()

def test_get(self):
r = self.c.get(reverse('broadcast', args=[]))
self.assertEqual(r.status_code, 200)

def test_post(self):
UserFactory()
r = self.c.post(
reverse('broadcast', args=[]),
{
'subject': 'cat',
'body': 'kitty cat',
}
)
self.assertEqual(r.status_code, 302)
self.assertEqual(len(mail.outbox), 1)
8 changes: 8 additions & 0 deletions spokehub/broadcast/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf.urls import patterns, url
from .views import BroadcastView


urlpatterns = patterns(
'',
url(r'^$', BroadcastView.as_view(), name='broadcast'),
)
18 changes: 18 additions & 0 deletions spokehub/broadcast/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.contrib.auth.models import User
from django.views.generic.edit import FormView
from .forms import BroadcastForm


class BroadcastView(FormView):
template_name = "broadcast/broadcast.html"
form_class = BroadcastForm
success_url = "/"

def form_valid(self, form):
for u in User.objects.all().exclude(username='AnonymousUser'):
u.email_user(
form.cleaned_data['subject'],
form.cleaned_data['body'],
'Hub Conversation <hello@spokehub.org>',
)
return super(BroadcastView, self).form_valid(form)
31 changes: 18 additions & 13 deletions spokehub/invite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,7 @@ def form_valid(self, form):
self.invite.delete()

p = get_user_profile(user)
# handle profile photo upload
if 'profileimage' in self.request.FILES:
filename = upload_image('profile',
self.request.FILES['profileimage'])
filename = os.path.join(settings.MEDIA_ROOT, filename)
mugshot_path = upload_to_mugshot(p, filename)
thumbnailer = get_thumbnailer(
open(filename, 'rb'), relative_name=mugshot_path)
thumb = thumbnailer.get_thumbnail(
{'size': (settings.USERENA_MUGSHOT_SIZE,
settings.USERENA_MUGSHOT_SIZE)},
save=True)
p.mugshot = thumb.name
self.handle_profile_photo_upload(p)

# handle cover photo upload
if 'coverimage' in self.request.FILES:
Expand All @@ -95,6 +83,23 @@ def form_valid(self, form):
self.user = user
return super(SignupView, self).form_valid(form)

def handle_profile_photo_upload(self, p):
if 'profileimage' in self.request.FILES:
filename = upload_image('profile',
self.request.FILES['profileimage'])
if filename is None:
# they uploaded something that wasn't a photo
return
filename = os.path.join(settings.MEDIA_ROOT, filename)
mugshot_path = upload_to_mugshot(p, filename)
thumbnailer = get_thumbnailer(
open(filename, 'rb'), relative_name=mugshot_path)
thumb = thumbnailer.get_thumbnail(
{'size': (settings.USERENA_MUGSHOT_SIZE,
settings.USERENA_MUGSHOT_SIZE)},
save=True)
p.mugshot = thumb.name


def upload_image(d, f):
ext = f.name.split(".")[-1].lower()
Expand Down
1 change: 1 addition & 0 deletions spokehub/settings_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
'guardian',
'easy_thumbnails',
'spokehub.gravatar',
'spokehub.broadcast',
]

INTERNAL_IPS = ('127.0.0.1', )
Expand Down
21 changes: 21 additions & 0 deletions spokehub/templates/broadcast/broadcast.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% load bootstrap %}

{% block content %}
<div id="site-wrapper">
<div class="content-wrapper content-container recover-password user-page">
<div class="page-heading"><h2><b>Send Broadcast Email to All Users</b></h2></div>
<div class="form-container">
{% if request.user.is_superuser %}

<form action="." method="post">
{{form|bootstrap}}
<input type="submit" value="send broadcast message" />
</form>
{% else %}
<p>Sorry, superuser only</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}
29 changes: 1 addition & 28 deletions spokehub/templates/userena/profile_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ <h2><b>{{ profile.user.username }}</b> {% if profile.user.get_full_name %}({{ pr
<dd><a href="mailto:{{profile.user.email}}">{{ profile.user.email }}</a></dd>
{% endif %}

<!--{% if profile.cover %}
<dt>Cover photo path:</dt>
<dd>{{profile.cover.url}}</dd>
{% endif %}-->

{% endblock %}
</dl>
{% endblock %}
Expand All @@ -59,33 +54,11 @@ <h2><b>{{ profile.user.username }}</b> {% if profile.user.get_full_name %}({{ pr
{% if user.username == profile.user.username %}
{% if user.is_superuser %}
<p><a href="{% url 'invite_form' %}">Invite Users</a></p>
<p><a href="{% url 'broadcast' %}">Send Broadcast Email</a></p>
{% endif %}
{% endif %}


<!--{% with questions=user.profile.questions %}
{% if questions.count %}
<h3>Questions Asked</h3>
<ul>
{% for question in questions %}
<li><a href="{{question.get_absolute_url}}">{{question.added}}: {{question.body}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% with questions=user.profile.replied_to %}
{% if questions %}
<h3>Questions Replied to</h3>
<ul>
{% for question in questions %}
<li><a href="{{question.get_absolute_url}}">{{question.added}}: {{question.body}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}-->
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions spokehub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
(r'^test/$', TemplateView.as_view(template_name='layout_test.html')),

(r'^invite/', include('spokehub.invite.urls')),
(r'^broadcast/', include('spokehub.broadcast.urls')),
(r'^admin/', include(admin.site.urls)),
url(r'^_impersonate/', include('impersonate.urls')),
url(r'^stats/$', TemplateView.as_view(template_name="stats.html"),
Expand Down

0 comments on commit 42e819b

Please sign in to comment.