0001-general-sms-are-separated-from-mail-announces-12918.patch
corbo/forms.py | ||
---|---|---|
1 | 1 |
from django import forms |
2 | 2 |
from django.utils.translation import ugettext_lazy as _ |
3 | 3 | |
4 |
from .models import Announce, Category, Broadcast, channel_choices
|
|
4 |
from .models import Announce, Category, Broadcast, SMS
|
|
5 | 5 | |
6 | 6 | |
7 | 7 |
class AnnounceForm(forms.ModelForm): |
... | ... | |
27 | 27 |
class Meta: |
28 | 28 |
fields = ('name', ) |
29 | 29 |
model = Category |
30 | ||
31 | ||
32 |
class SMSForm(forms.ModelForm): |
|
33 | ||
34 |
class Meta: |
|
35 |
model = SMS |
|
36 |
fields = '__all__' |
|
37 |
widgets = {'expedition_time': forms.TextInput(attrs={'class': 'datetimepicker', |
|
38 |
'readonly': True})} |
corbo/manage_urls.py | ||
---|---|---|
2 | 2 | |
3 | 3 |
from .views import add_announce, edit_announce, delete_announce, \ |
4 | 4 |
add_category, edit_category, view_category, delete_category, manage, \ |
5 |
add_announce_for_category, menu_json |
|
5 |
add_announce_for_category, add_sms, add_sms_for_category, edit_sms, \ |
|
6 |
delete_sms, menu_json |
|
6 | 7 | |
7 | 8 |
urlpatterns = patterns('', |
8 | 9 |
url(r'^$', manage, name='manage'), |
... | ... | |
15 | 16 |
name='view_category'), |
16 | 17 |
url(r'^category/(?P<pk>\d+)/announce/$', add_announce_for_category, |
17 | 18 |
name='add_announce_for_category'), |
19 |
url(r'^sms/add$', add_sms, |
|
20 |
name='add_sms'), |
|
21 |
url(r'^category/(?P<pk>\d+)/sms/$', add_sms_for_category, |
|
22 |
name='add_sms_for_category'), |
|
23 |
url(r'^sms/edit/(?P<pk>\d+)$', edit_sms, |
|
24 |
name='edit_sms'), |
|
25 |
url(r'^sms/delete/(?P<pk>\d+)$', delete_sms, |
|
26 |
name='delete_sms'), |
|
18 | 27 |
url(r'^category/add$', add_category, |
19 | 28 |
name='add_category'), |
20 | 29 |
url(r'^category/edit/(?P<pk>\d+)$', edit_category, |
corbo/migrations/0006_sms.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import models, migrations |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('corbo', '0005_auto_20160504_1747'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.CreateModel( |
|
15 |
name='SMS', |
|
16 |
fields=[ |
|
17 |
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
|
18 |
('content', models.TextField(help_text='160 chars maximum', max_length=160)), |
|
19 |
('expedition_time', models.DateTimeField(null=True, verbose_name='Expedition time', blank=True)), |
|
20 |
('category', models.ForeignKey(verbose_name='category', to='corbo.Category')), |
|
21 |
], |
|
22 |
options={ |
|
23 |
}, |
|
24 |
bases=(models.Model,), |
|
25 |
), |
|
26 |
] |
corbo/models.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
channel_choices = ( |
21 | 21 |
('mailto', _('Email')), |
22 |
('homepage', _('Homepage')) |
|
22 |
('homepage', _('Homepage')), |
|
23 |
('sms', _('SMS')) |
|
23 | 24 |
) |
24 | 25 | |
25 | 26 |
logger = logging.getLogger(__name__) |
... | ... | |
34 | 35 |
def get_announces_count(self): |
35 | 36 |
return self.announce_set.all().count() |
36 | 37 | |
38 |
def get_sms_count(self): |
|
39 |
return self.sms_set.all().count() |
|
40 | ||
37 | 41 |
def get_subscriptions_count(self): |
38 | 42 |
return self.subscription_set.all().count() |
39 | 43 | |
... | ... | |
139 | 143 | |
140 | 144 |
class Meta: |
141 | 145 |
unique_together = ('category', 'identifier', 'uuid') |
146 | ||
147 | ||
148 |
class SMS(models.Model): |
|
149 |
category = models.ForeignKey('Category', verbose_name=_('category')) |
|
150 |
content = models.TextField(max_length=160, help_text=_('160 chars maximum')) |
|
151 |
expedition_time = models.DateTimeField(_('Expedition time'), blank=True, |
|
152 |
null=True) |
|
153 | ||
154 |
@property |
|
155 |
def sent(self): |
|
156 |
return self.expedition_time and self.expedition_time > timezone.now() |
corbo/templates/corbo/category_detail.html | ||
---|---|---|
12 | 12 |
<h2>{{ object.name }}</h2> |
13 | 13 |
<a href="{% url 'delete_category' object.id %}" rel="popup">{% trans 'Delete' %}</a> |
14 | 14 |
<a href="{% url 'edit_category' object.id %}" rel="popup">{% trans 'Rename' %}</a> |
15 |
<a href="{% url 'add_sms_for_category' pk=object.pk %}">{% trans 'New SMS' %}</a> |
|
15 | 16 |
<a href="{% url 'add_announce_for_category' pk=object.pk %}">{% trans 'New announce' %}</a> |
16 | 17 |
{% endblock %} |
17 | 18 | |
18 | 19 |
{% block content %} |
19 | 20 |
<div id="management"> |
20 | 21 |
<ul class='objects-list single-links'> |
22 |
{% for sms in sms_messages %} |
|
23 |
<li class="{% if not sms.sent %}unpublished{% endif %}"> |
|
24 |
<a href="{% url 'edit_sms' sms.id %}">{{ sms.content|truncatechars:40 }}...</a> |
|
25 |
</li> |
|
26 |
{% endfor %} |
|
27 | ||
21 | 28 |
{% for announce in announces %} |
22 | 29 |
<li class="{% if not announce.is_published %}unpublished{% endif %}"> |
23 | 30 |
<a href="{% url 'edit_announce' announce.id %}">{{ announce.title }}</a> |
... | ... | |
29 | 36 |
{% endif %} |
30 | 37 |
</div> |
31 | 38 |
</li> |
32 |
{% empty %} |
|
33 |
<div class="empty"> |
|
34 |
{% trans "No announces yet." %} |
|
35 |
</div> |
|
36 | 39 |
{% endfor %} |
37 | 40 |
</ul> |
38 | 41 |
{% endblock %} |
corbo/templates/corbo/manage.html | ||
---|---|---|
4 | 4 |
{% block appbar %} |
5 | 5 |
<h2>{% trans "Categories" %}</h2> |
6 | 6 |
<a href="{% url 'add_category' %}" rel='popup'>{% trans 'New category' %}</a> |
7 |
<a href="{% url 'add_sms' %}">{% trans 'New sms' %}</a> |
|
7 | 8 |
<a href="{% url 'add_announce' %}">{% trans 'New announce' %}</a> |
8 | 9 |
{% endblock %} |
9 | 10 | |
... | ... | |
18 | 19 |
{% plural %} |
19 | 20 |
{{ announces_number }} announces |
20 | 21 |
{% endblocktrans %} / |
22 |
{% blocktrans with sms_number=obj.get_sms_count %} |
|
23 |
{{ sms_number }} sms |
|
24 |
{% endblocktrans %} / |
|
21 | 25 |
{% blocktrans count subscriptions_number=obj.get_subscriptions_count %} |
22 | 26 |
{{ subscriptions_number }} subscription |
23 | 27 |
{% plural %} |
corbo/views.py | ||
---|---|---|
19 | 19 |
from django.utils.translation import ugettext_lazy as _ |
20 | 20 | |
21 | 21 |
import models |
22 |
from .forms import AnnounceForm, CategoryForm |
|
22 |
from .forms import AnnounceForm, CategoryForm, SMSForm
|
|
23 | 23 | |
24 | 24 |
try: |
25 | 25 |
from mellon.utils import get_idps |
... | ... | |
60 | 60 |
add_announce = AnnounceCreateView.as_view() |
61 | 61 | |
62 | 62 | |
63 |
class AnnounceForCategoryCreateView(AnnounceCreateView): |
|
64 | ||
63 |
class ForCategoryMixin(object): |
|
65 | 64 |
def get_initial(self): |
66 |
initial = super(AnnounceForCategoryCreateView, self).get_initial()
|
|
65 |
initial = super(ForCategoryMixin, self).get_initial()
|
|
67 | 66 |
initial['category'] = models.Category.objects.get(pk=self.kwargs['pk']) |
68 | 67 |
return initial |
69 | 68 | |
70 | 69 |
def get_context_data(self, **kwargs): |
71 |
context = super(AnnounceForCategoryCreateView, self).get_context_data(**kwargs)
|
|
70 |
context = super(ForCategoryMixin, self).get_context_data(**kwargs)
|
|
72 | 71 |
context['category'] = kwargs['form'].initial['category'] |
73 | 72 |
return context |
74 | 73 | |
74 | ||
75 |
class AnnounceForCategoryCreateView(ForCategoryMixin, AnnounceCreateView): |
|
76 |
pass |
|
77 | ||
75 | 78 |
add_announce_for_category = AnnounceForCategoryCreateView.as_view() |
76 | 79 | |
77 | 80 | |
... | ... | |
98 | 101 | |
99 | 102 |
delete_announce = AnnounceDeleteView.as_view() |
100 | 103 | |
104 | ||
105 |
class SmsCreateView(CreateView): |
|
106 |
model = models.SMS |
|
107 |
form_class = SMSForm |
|
108 |
template_name = 'corbo/sms_form.html' |
|
109 | ||
110 |
def get_success_url(self): |
|
111 |
return reverse('view_category', kwargs={'pk': self.object.category.pk}) |
|
112 | ||
113 |
add_sms = SmsCreateView.as_view() |
|
114 | ||
115 | ||
116 |
class SmsForCategoryCreateView(ForCategoryMixin, SmsCreateView): |
|
117 |
pass |
|
118 | ||
119 |
add_sms_for_category = SmsForCategoryCreateView.as_view() |
|
120 | ||
121 | ||
122 |
class SmsEditView(UpdateView): |
|
123 |
model = models.SMS |
|
124 |
form_class = SMSForm |
|
125 | ||
126 |
def get_context_data(self, **kwargs): |
|
127 |
context = super(SmsEditView, self).get_context_data(**kwargs) |
|
128 |
category_id = kwargs['form'].initial['category'] |
|
129 |
context['category'] = models.Category.objects.get(pk=category_id) |
|
130 |
return context |
|
131 | ||
132 |
def get_success_url(self): |
|
133 |
return reverse('view_category', kwargs={'pk': self.object.category.pk}) |
|
134 | ||
135 |
edit_sms = SmsEditView.as_view() |
|
136 | ||
137 | ||
138 |
class SMSDeleteView(DeleteView): |
|
139 |
model = models.SMS |
|
140 | ||
141 |
delete_sms = SMSDeleteView.as_view() |
|
142 | ||
143 | ||
101 | 144 |
class CategoryCreateView(CreateView): |
102 | 145 |
form_class = CategoryForm |
103 | 146 |
template_name = 'corbo/category_form.html' |
... | ... | |
128 | 171 |
def get_context_data(self, **kwargs): |
129 | 172 |
context = super(CategoryView, self).get_context_data(**kwargs) |
130 | 173 |
context['announces'] = self.object.announce_set.all() |
174 |
context['sms_messages'] = self.object.sms_set.all() |
|
131 | 175 |
return context |
132 | 176 | |
133 | 177 |
view_category = CategoryView.as_view() |
134 |
- |