Project

General

Profile

« Previous | Next » 

Revision 8e8b10ae

Added by Serghei Mihai over 6 years ago

manager: add test sms send (#20174)

View differences:

corbo/views.py
20 20

  
21 21
import models
22 22
from .forms import AnnounceForm, CategoryForm, SubscriptionsImportForm, \
23
    SendTestEmailForm
23
    SendTestEmailForm, SendTestSMSForm
24 24
from . import utils
25 25

  
26 26
try:
......
264 264
        context = super(AnnounceView, self).get_context_data(**kwargs)
265 265
        context['category'] = self.object.category
266 266
        context['broadcasts'] = self.object.broadcast_set.filter(deliver_time__isnull=False)
267
        context['sms_enabled'] = settings.SMS_GATEWAY_URL
267 268
        return context
268 269

  
269 270
view_announce = AnnounceView.as_view()
270 271

  
271 272

  
272
class EmailAnnounceView(FormView):
273
    form_class = SendTestEmailForm
274
    template_name = 'corbo/test_email_send_form.html'
275

  
273
class SendAnnounceView(FormView):
276 274
    def get_initial(self):
277
        return {'email': self.request.user.email}
275
        return {'email': self.request.user.email,
276
                'mobile': self.request.session.get('mellon_session', {}).get('mobile', '')}
278 277

  
279 278
    def get_success_url(self, *args, **kwargs):
280 279
        return reverse('view_announce', kwargs={'pk': self.kwargs['pk']})
281 280

  
281
    def get_context_data(self, **kwargs):
282
        context = super(SendAnnounceView, self).get_context_data(**kwargs)
283
        context['object'] = models.Announce.objects.get(pk=self.kwargs['pk'])
284
        return context
285

  
286

  
287
class EmailAnnounceView(SendAnnounceView):
288
    form_class = SendTestEmailForm
289
    template_name = 'corbo/email_test_announce_form.html'
290

  
282 291
    def form_valid(self, form):
283 292
        email = form.cleaned_data['email']
284 293
        announce = models.Announce.objects.get(pk=self.kwargs['pk'])
......
286 295
        messages.info(self.request, _('Email successfully sent'))
287 296
        return super(EmailAnnounceView, self).form_valid(form)
288 297

  
289
    def get_context_data(self, **kwargs):
290
        context = super(EmailAnnounceView, self).get_context_data(**kwargs)
291
        context['object'] = models.Announce.objects.get(pk=self.kwargs['pk'])
292
        return context
293

  
294 298
email_announce = EmailAnnounceView.as_view()
295 299

  
300

  
301
class SMSAnnounceView(SendAnnounceView):
302
    form_class = SendTestSMSForm
303
    template_name = 'corbo/sms_test_announce_form.html'
304

  
305
    def form_valid(self, form):
306
        mobile = form.cleaned_data['mobile']
307
        announce = models.Announce.objects.get(pk=self.kwargs['pk'])
308
        sms_sent = utils.send_sms(announce.text, [mobile])
309
        if sms_sent == 1:
310
            messages.info(self.request, _('SMS successfully sent'))
311
        else:
312
            messages.error(self.request, _('Error occured while sending SMS'))
313
        return super(SMSAnnounceView, self).form_valid(form)
314

  
315
sms_announce = SMSAnnounceView.as_view()
316

  
317

  
296 318
def menu_json(request):
297 319
    label = _('Announces')
298 320
    json_str = json.dumps([{'label': force_text(label),

Also available in: Unified diff