~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to notification/models.py

  • Committer: franku
  • Date: 2018-04-05 07:30:42 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: somal@arcor.de-20180405073042-yd8jgpkptorjwxrs
replace unmaintained pagination app; fixes for context_instance, NoArgsCommand and resolve_variable()

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from django.db.models.query import QuerySet
10
10
from django.conf import settings
11
11
from django.core.urlresolvers import reverse
12
 
from django.template import Context
13
12
from django.template.loader import render_to_string
14
13
 
15
14
from django.core.exceptions import ImproperlyConfigured
186
185
 
187
186
    """
188
187
    format_templates = {}
 
188
 
189
189
    for format in formats:
190
190
        # conditionally turn off autoescaping for .txt extensions in format
191
 
        if format.endswith('.txt'):
192
 
            context.autoescape = False
193
 
        else:
194
 
            context.autoescape = True
 
191
        # if format.endswith('.txt'):
 
192
        #     context.autoescape = False
 
193
        # else:
 
194
        #     context.autoescape = True
195
195
        format_templates[format] = render_to_string((
196
196
            'notification/%s/%s' % (label, format),
197
 
            'notification/%s' % format), context_instance=context)
 
197
            'notification/%s' % format), context)
 
198
 
198
199
    return format_templates
199
200
 
200
201
 
250
251
                activate(language)
251
252
 
252
253
            # update context with user specific translations
253
 
            context = Context({
 
254
            context = {
254
255
                'user': user,
255
 
                'notices_url': notices_url,
256
256
                'current_site': current_site,
257
257
                'subject': notice_type.display,
258
258
                'description': notice_type.description,
259
 
            })
 
259
            }
260
260
            context.update(extra_context)
261
261
 
262
262
            # get prerendered format messages
265
265
            # Strip newlines from subject
266
266
            subject = ''.join(render_to_string('notification/email_subject.txt', {
267
267
                'message': messages['short.txt'],
268
 
            }, context).splitlines())
269
 
            
 
268
            }).splitlines())
 
269
 
270
270
            # Strip leading newlines. Make writing the email templates easier:
271
271
            # Each linebreak in the templates results in a linebreak in the emails
272
272
            # If the first line in a template contains only template tags the 
273
273
            # email will contain an empty line at the top.
274
274
            body = render_to_string('notification/email_body.txt', {
275
275
                'message': messages['full.txt'],
276
 
            }, context).lstrip()
 
276
                'notices_url': notices_url,
 
277
            }).lstrip()
277
278
 
278
279
            if should_send(user, notice_type, '1') and user.email:  # Email
279
280
                recipients.append(user.email)
280
281
            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
281
 
 
 
282
        
282
283
        # reset environment to original language
283
284
        activate(current_language)
284
285
    except NoticeType.DoesNotExist: