~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to notification/models.py

  • Committer: kaputtnik
  • Date: 2019-06-14 18:40:56 UTC
  • mfrom: (532.1.31 widelands)
  • Revision ID: kaputtnik-20190614184056-l0ha8pm5zais9mxk
Adapted code for use with python 3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import datetime
 
2
import base64
2
3
 
3
4
try:
4
 
    import cPickle as pickle
 
5
    import pickle as pickle
5
6
except ImportError:
6
7
    import pickle
7
8
 
48
49
    # number
49
50
    default = models.IntegerField(_('default'))
50
51
 
51
 
    def __unicode__(self):
 
52
    def __str__(self):
52
53
        return self.label
53
54
 
54
55
    class Meta:
150
151
        if updated:
151
152
            notice_type.save()
152
153
            if verbosity > 1:
153
 
                print 'Updated %s NoticeType' % label
 
154
                print('Updated %s NoticeType' % label)
154
155
    except NoticeType.DoesNotExist:
155
156
        NoticeType(label=label, display=display,
156
157
                   description=description, default=default).save()
157
158
        if verbosity > 1:
158
 
            print 'Created %s NoticeType' % label
 
159
            print('Created %s NoticeType' % label)
159
160
 
160
161
 
161
162
def get_notification_language(user):
222
223
        notice_type = NoticeType.objects.get(label=label)
223
224
 
224
225
        current_site = Site.objects.get_current()
225
 
        notices_url = u"http://%s%s" % (
226
 
            unicode(current_site),
 
226
        notices_url = "http://%s%s" % (
 
227
            str(current_site),
227
228
            reverse('notification_notices'),
228
229
        )
229
230
 
257
258
 
258
259
            # get prerendered format messages and subjects
259
260
            messages = get_formatted_messages(formats, label, context)
260
 
            
 
261
 
261
262
            # Create the subject
262
263
            # Use 'email_subject.txt' to add Strings in every emails subject
263
264
            subject = render_to_string('notification/email_subject.txt',
264
265
                                       {'message': messages['short.txt'],}).replace('\n', '')
265
 
            
 
266
 
266
267
            # Strip leading newlines. Make writing the email templates easier:
267
268
            # Each linebreak in the templates results in a linebreak in the emails
268
269
            # If the first line in a template contains only template tags the 
275
276
            if should_send(user, notice_type, '1') and user.email:  # Email
276
277
                recipients.append(user.email)
277
278
 
278
 
            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
279
 
        
 
279
            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients, fail_silently=True)
 
280
 
280
281
        # reset environment to original language
281
282
        activate(current_language)
282
283
    except NoticeType.DoesNotExist:
322
323
    notices = []
323
324
    for user in users:
324
325
        notices.append((user, label, extra_context, on_site))
325
 
    NoticeQueueBatch(pickled_data=pickle.dumps(
326
 
        notices).encode('base64')).save()
 
326
 
 
327
    NoticeQueueBatch(pickled_data=base64.b64encode(
 
328
        pickle.dumps(notices))).save()
327
329
 
328
330
 
329
331
class ObservedItemManager(models.Manager):