Révision 46bbe5fe
Ajouté par Serghei Mihai (congés, retour 15/05) il y a plus de 9 ans
corbo/channels.py | ||
---|---|---|
1 |
from django.utils.translation import ugettext_lazy as _ |
|
2 |
|
|
3 |
def get_channel_choices(include=[], exclude=[]): |
|
4 |
for channel in HomepageChannel, SMSChannel, EmailChannel: |
|
5 |
if include and channel.identifier not in include: |
|
6 |
continue |
|
7 |
if exclude and channel.identifier in exclude: |
|
8 |
continue |
|
9 |
for identifier, display_name in channel.get_choices(): |
|
10 |
yield (identifier, display_name) |
|
11 |
|
|
12 |
class HomepageChannel(object): |
|
13 |
identifier = 'homepage' |
|
14 |
|
|
15 |
@classmethod |
|
16 |
def get_choices(self): |
|
17 |
return (('homepage', _('Homepage')),) |
|
18 |
|
|
19 |
class SMSChannel(object): |
|
20 |
|
|
21 |
@classmethod |
|
22 |
def get_choices(self): |
|
23 |
return (('sms', _('SMS')),) |
|
24 |
|
|
25 |
def send(self, announce): |
|
26 |
pass |
|
27 |
|
|
28 |
class EmailChannel(object): |
|
29 |
identifier = 'email' |
|
30 |
|
|
31 |
@classmethod |
|
32 |
def get_choices(self): |
|
33 |
return (('email', _('Email')),) |
|
34 |
|
|
35 |
def send(self, announce): |
|
36 |
pass |
corbo/forms.py | ||
---|---|---|
1 | 1 |
from django import forms |
2 |
from django.utils.translation import ugettext_lazy as _ |
|
2 | 3 |
|
3 |
from .models import Announce, Category |
|
4 |
from .models import Announce, Category, Broadcast |
|
5 |
from .channels import get_channel_choices |
|
4 | 6 |
|
5 | 7 |
class AnnounceForm(forms.ModelForm): |
8 |
transport_channel = forms.MultipleChoiceField(required=False, |
|
9 |
choices=get_channel_choices(), |
|
10 |
widget=forms.CheckboxSelectMultiple()) |
|
6 | 11 |
|
7 | 12 |
class Meta: |
8 | 13 |
model = Announce |
... | ... | |
13 | 18 |
'size': 8}) |
14 | 19 |
} |
15 | 20 |
|
21 |
def __init__(self, *args, **kwargs): |
|
22 |
super(AnnounceForm, self).__init__(*args, **kwargs) |
|
23 |
self.fields['transport_channel'].initial = [b.channel for \ |
|
24 |
b in self.instance.broadcast_set.all()] |
|
25 |
|
|
26 |
def save(self, *args, **kwargs): |
|
27 |
instance = super(AnnounceForm, self).save(*args, **kwargs) |
|
28 |
if instance: |
|
29 |
channels = self.cleaned_data['transport_channel'] |
|
30 |
for channel in channels: |
|
31 |
Broadcast.objects.get_or_create(announce=instance, |
|
32 |
channel=channel) |
|
33 |
self.instance.broadcast_set.exclude(announce=instance, |
|
34 |
channel__in=channels).delete() |
|
35 |
return instance |
|
36 |
|
|
16 | 37 |
class CategoryForm(forms.ModelForm): |
17 | 38 |
class Meta: |
18 | 39 |
fields = ('name', ) |
corbo/models.py | ||
---|---|---|
5 | 5 |
|
6 | 6 |
from ckeditor.fields import RichTextField |
7 | 7 |
|
8 |
import channels |
|
9 |
|
|
8 | 10 |
class Category(models.Model): |
9 | 11 |
name = models.CharField(max_length=64, blank=False, null=False) |
10 | 12 |
ctime = models.DateTimeField(auto_now_add=True) |
... | ... | |
13 | 15 |
return self.name |
14 | 16 |
|
15 | 17 |
class Announce(models.Model): |
18 |
category = models.ForeignKey('Category', verbose_name=_('category')) |
|
16 | 19 |
title = models.CharField(_('title'), max_length=256, |
17 | 20 |
help_text=_('maximum 256 characters')) |
18 |
text = RichTextField(_('Content'))
|
|
21 |
text = models.TextField(_('Content'))
|
|
19 | 22 |
publication_time = models.DateTimeField(_('publication time'), blank=True, |
20 | 23 |
null=True) |
21 | 24 |
expiration_time = models.DateTimeField(_('Expires on'), blank=True, |
22 | 25 |
null=True) |
23 | 26 |
ctime = models.DateTimeField(_('creation time'), auto_now_add=True) |
24 | 27 |
mtime = models.DateTimeField(_('modification time'), auto_now=True) |
25 |
category = models.ForeignKey('Category', verbose_name=_('category')) |
|
26 | 28 |
|
27 | 29 |
def __unicode__(self): |
28 | 30 |
return u'{title} ({id}) at {mtime}'.format(title=self.title, |
... | ... | |
44 | 46 |
verbose_name = _('announce') |
45 | 47 |
ordering = ('-mtime',) |
46 | 48 |
|
49 |
class Broadcast(models.Model): |
|
50 |
announce = models.ForeignKey(Announce, verbose_name=_('announce')) |
|
51 |
channel = models.CharField(_('channel'), max_length=32, |
|
52 |
choices=channels.get_channel_choices(), blank=False) |
|
53 |
time = models.DateTimeField(_('sent time'), auto_now_add=True) |
|
54 |
result = models.TextField(_('result'), blank=True) |
|
55 |
|
|
56 |
def __unicode__(self): |
|
57 |
return u'announce {id} sent via {channel} at {time}'.format( |
|
58 |
id=self.announce.id, channel=self.channel, time=self.time) |
|
59 |
|
|
60 |
class Meta: |
|
61 |
verbose_name = _('sent') |
|
62 |
ordering = ('-time',) |
|
63 |
unique_together = ('announce', 'channel') |
|
64 |
|
|
47 | 65 |
class SubscriptionType(models.Model): |
48 | 66 |
subscription = models.ForeignKey('Subscription') |
49 | 67 |
identifier = models.CharField(_('identifier'), max_length=128, blank=True, |
corbo/static/css/corbo.css | ||
---|---|---|
277 | 277 |
form ul li label { |
278 | 278 |
display: block; |
279 | 279 |
} |
280 |
|
|
281 |
#id_transport_channel li, #id_transport_channel label { |
|
282 |
display: inline; |
|
283 |
} |
Formats disponibles : Unified diff
announce broadcasting channels added