def weblate_context(request): """ Context processor to inject various useful variables into context. """ if "next" in request.GET: login_redirect_url = request.GET["next"] else: login_redirect_url = request.get_full_path() return { "version": weblate.VERSION, "weblate_url": URL_BASE % weblate.VERSION, "donate_url": URL_DONATE % weblate.VERSION, "site_title": appsettings.SITE_TITLE, "site_url": get_site_url(), "offer_hosting": appsettings.OFFER_HOSTING, "demo_server": appsettings.DEMO_SERVER, "enable_avatars": appsettings.ENABLE_AVATARS, "enable_sharing": appsettings.ENABLE_SHARING, "current_date": datetime.utcnow().strftime("%Y-%m-%d"), "current_year": datetime.utcnow().strftime("%Y"), "current_month": datetime.utcnow().strftime("%m"), "login_redirect_url": login_redirect_url, "mt_enabled": appsettings.MACHINE_TRANSLATION_ENABLED, "hooks_enabled": appsettings.ENABLE_HOOKS, "whiteboard_enabled": appsettings.ENABLE_WHITEBOARD, "registration_open": appsettings.REGISTRATION_OPEN, }
def get_share_url(self): """ Returns absolute URL usable for sharing. """ return get_site_url( reverse('engage', kwargs={'project': self.slug}) )
def get_widgets_url(self): """ Returns absolute URL for widgets. """ return get_site_url( reverse('widgets', kwargs={'project': self.slug}) )
def get_share_url(self): """ Returns absolute URL usable for sharing. """ return get_site_url( reverse("engage-lang", kwargs={"project": self.subproject.project.slug, "lang": self.language.code}) )
def get_widgets_url(self): """ Returns absolute URL for widgets. """ return get_site_url( "%s?lang=%s" % (reverse("widgets", kwargs={"project": self.subproject.project.slug}), self.language.code) )
def weblate_context(request): ''' Context processor to inject various useful variables into context. ''' return { 'version': weblate.VERSION, 'weblate_url': URL_BASE % weblate.VERSION, 'donate_url': URL_DONATE % weblate.VERSION, 'site_title': appsettings.SITE_TITLE, 'site_url': get_site_url(), 'offer_hosting': appsettings.OFFER_HOSTING, 'demo_server': appsettings.DEMO_SERVER, 'enable_avatars': appsettings.ENABLE_AVATARS, 'current_date': datetime.utcnow().strftime('%Y-%m-%d'), 'current_year': datetime.utcnow().strftime('%Y'), 'current_month': datetime.utcnow().strftime('%m'), 'current_url': request.get_full_path(), 'mt_enabled': appsettings.MACHINE_TRANSLATION_ENABLED, 'hooks_enabled': appsettings.ENABLE_HOOKS, 'registration_open': appsettings.REGISTRATION_OPEN, }
def widgets(request, project): obj = get_project(request, project) # Parse possible language selection form = EnageLanguageForm(obj, request.GET) lang = None if form.is_valid() and form.cleaned_data["lang"] != "": lang = Language.objects.get(code=form.cleaned_data["lang"]) if lang is None: engage_base = reverse("engage", kwargs={"project": obj.slug}) else: engage_base = reverse("engage-lang", kwargs={"project": obj.slug, "lang": lang.code}) engage_url = get_site_url(engage_base) engage_url_track = "%s?utm_source=widget" % engage_url widget_base_url = get_site_url(reverse("widgets", kwargs={"project": obj.slug})) widget_list = [] for widget_name in WIDGETS: widget_class = WIDGETS[widget_name] color_list = [] for color in widget_class.colors: if lang is None: color_url = reverse("widget-image", kwargs={"project": obj.slug, "widget": widget_name, "color": color}) else: color_url = reverse( "widget-image-lang", kwargs={"project": obj.slug, "widget": widget_name, "color": color, "lang": lang.code}, ) color_list.append({"name": color, "url": get_site_url(color_url)}) widget_list.append({"name": widget_name, "colors": color_list}) return render_to_response( "widgets.html", RequestContext( request, { "engage_url": engage_url, "engage_url_track": engage_url_track, "widget_list": widget_list, "widget_base_url": widget_base_url, "object": obj, "image_src": widget_list[0]["colors"][0]["url"], "form": form, }, ), )
def download_dictionary_ttkit(export_format, prj, lang, words): ''' Translate-toolkit builder for dictionary downloads. ''' # Use translate-toolkit for other formats if export_format == 'po': # Construct store from translate.storage.po import pofile store = pofile() # Export parameters content_type = 'text/x-po' extension = 'po' has_lang = False # Set po file header store.updateheader( add=True, language=lang.code, x_generator='Weblate %s' % weblate.VERSION, project_id_version='%s (%s)' % (lang.name, prj.name), language_team='%s <%s>' % ( lang.name, get_site_url(reverse( 'show_dictionary', kwargs={'project': prj.slug, 'lang': lang.code} )), ) ) else: # Construct store from translate.storage.tbx import tbxfile store = tbxfile() # Export parameters content_type = 'application/x-tbx' extension = 'tbx' has_lang = True # Setup response and headers response = HttpResponse(content_type='%s; charset=utf-8' % content_type) filename = 'glossary-%s-%s.%s' % (prj.slug, lang.code, extension) response['Content-Disposition'] = 'attachment; filename=%s' % filename # Add words for word in words.iterator(): unit = store.UnitClass(word.source) if has_lang: unit.settarget(word.target, lang.code) else: unit.target = word.target store.addunit(unit) # Save to response store.savefile(response) return response
def get_widgets_url(self): ''' Returns absolute URL for widgets. ''' return get_site_url('%s?lang=%s' % ( reverse( 'widgets', kwargs={ 'project': self.subproject.project.slug, }), self.language.code, ))
def get_share_url(self): ''' Returns absolute URL usable for sharing. ''' return get_site_url( reverse( 'engage-lang', kwargs={ 'project': self.subproject.project.slug, 'lang': self.language.code }))
def weblate_context(request): """ Context processor to inject various useful variables into context. """ if 'next' in request.GET: login_redirect_url = request.GET['next'] else: login_redirect_url = request.get_full_path() projects = Project.objects.all_acl(request.user) # Load user translations if user is authenticated usertranslations = None if request.user.is_authenticated(): usertranslations = Translation.objects.filter( language__in=request.user.profile.languages.all(), subproject__project__in=projects, ).order_by( 'subproject__project__name', 'subproject__name' ).select_related() return { 'version': weblate.VERSION, 'weblate_url': URL_BASE % weblate.VERSION, 'donate_url': URL_DONATE % weblate.VERSION, 'site_title': appsettings.SITE_TITLE, 'site_url': get_site_url(), 'offer_hosting': appsettings.OFFER_HOSTING, 'demo_server': appsettings.DEMO_SERVER, 'enable_avatars': appsettings.ENABLE_AVATARS, 'enable_sharing': appsettings.ENABLE_SHARING, 'piwik_site_id': appsettings.PIWIK_SITE_ID, 'piwik_url': appsettings.PIWIK_URL, 'google_analytics_id': appsettings.GOOGLE_ANALYTICS_ID, 'current_date': datetime.utcnow().strftime('%Y-%m-%d'), 'current_year': datetime.utcnow().strftime('%Y'), 'current_month': datetime.utcnow().strftime('%m'), 'login_redirect_url': login_redirect_url, 'mt_enabled': appsettings.MACHINE_TRANSLATION_ENABLED, 'hooks_enabled': appsettings.ENABLE_HOOKS, 'whiteboard_enabled': appsettings.ENABLE_WHITEBOARD, 'registration_open': appsettings.REGISTRATION_OPEN, 'acl_projects': projects, 'usertranslations': usertranslations, }
def export_stats(request, project, subproject): ''' Exports stats in JSON format. ''' subprj = get_subproject(request, project, subproject) try: indent = int(request.GET['indent']) except (ValueError, KeyError): indent = None jsonp = None if 'jsonp' in request.GET and request.GET['jsonp']: jsonp = request.GET['jsonp'] response = [] for trans in subprj.translation_set.all(): response.append({ 'code': trans.language.code, 'name': trans.language.name, 'total': trans.total, 'total_words': trans.total_words, 'last_change': trans.last_change, 'last_author': trans.get_last_author(), 'translated': trans.translated, 'translated_words': trans.translated_words, 'translated_percent': trans.get_translated_percent(), 'fuzzy': trans.fuzzy, 'fuzzy_percent': trans.get_fuzzy_percent(), 'failing': trans.failing_checks, 'failing_percent': trans.get_failing_checks_percent(), 'url': trans.get_share_url(), 'url_translate': get_site_url(trans.get_absolute_url()), }) json_data = json.dumps( response, default=json_dt_handler, indent=indent, ) if jsonp: return HttpResponse( '{0}({1})'.format( jsonp, json_data, ), content_type='application/javascript' ) return HttpResponse( json_data, content_type='application/json' )
def export_stats(request, project, subproject): """ Exports stats in JSON format. """ subprj = get_subproject(request, project, subproject) try: indent = int(request.GET["indent"]) except (ValueError, KeyError): indent = None jsonp = None if "jsonp" in request.GET and request.GET["jsonp"]: jsonp = request.GET["jsonp"] response = [] for trans in subprj.translation_set.all(): response.append( { "code": trans.language.code, "name": trans.language.name, "total": trans.total, "total_words": trans.total_words, "last_change": trans.last_change, "last_author": trans.get_last_author(), "translated": trans.translated, "translated_words": trans.translated_words, "translated_percent": trans.get_translated_percent(), "fuzzy": trans.fuzzy, "fuzzy_percent": trans.get_fuzzy_percent(), "failing": trans.failing_checks, "failing_percent": trans.get_failing_checks_percent(), "url": trans.get_share_url(), "url_translate": get_site_url(trans.get_absolute_url()), } ) json_data = json.dumps(response, default=json_dt_handler, indent=indent) if jsonp: return HttpResponse("{0}({1})".format(jsonp, json_data), content_type="application/javascript") return HttpResponse(json_data, content_type="application/json")
def export_stats(request, project, subproject): ''' Exports stats in JSON format. ''' subprj = get_subproject(request, project, subproject) try: indent = int(request.GET['indent']) except: indent = None response = [] for trans in subprj.translation_set.all(): response.append({ 'code': trans.language.code, 'name': trans.language.name, 'total': trans.total, 'total_words': trans.total_words, 'last_change': trans.get_last_change(), 'last_author': trans.get_last_author(False), 'translated': trans.translated, 'translated_words': trans.translated_words, 'translated_percent': trans.get_translated_percent(), 'fuzzy': trans.fuzzy, 'fuzzy_percent': trans.get_fuzzy_percent(), 'failing': trans.failing_checks, 'failing_percent': trans.get_failing_checks_percent(), 'url': trans.get_share_url(), 'url_translate': get_site_url(trans.get_absolute_url()), }) return HttpResponse( json.dumps( response, default=json_dt_handler, indent=indent, ), content_type='application/json' )
def get_notification_email(language, email, notification, translation_obj=None, context=None, headers=None, user=None, info=None): ''' Renders notification email. ''' cur_language = django_translation.get_language() context = context or {} headers = headers or {} references = None if 'unit' in context: unit = context['unit'] references = '{0}/{1}/{2}/{3}'.format( unit.translation.subproject.project.slug, unit.translation.subproject.slug, unit.translation.language.code, unit.id ) if references is not None: references = '<{0}@{1}>'.format(references, get_site_domain()) headers['In-Reply-To'] = references headers['References'] = references try: if info is None: info = translation_obj.__unicode__() weblate.logger.info( 'sending notification %s on %s to %s', notification, info, email ) # Load user language if language is not None: django_translation.activate(language) # Template name context['subject_template'] = 'mail/{}_subject.txt'.format( notification ) # Adjust context context['current_site_url'] = get_site_url() if translation_obj is not None: context['translation'] = translation_obj context['translation_url'] = get_site_url( translation_obj.get_absolute_url() ) context['site_title'] = SITE_TITLE # Render subject subject = render_to_string( context['subject_template'], context ).strip() # Render body body = render_to_string( 'mail/{}.txt'.format(notification), context ) html_body = render_to_string( 'mail/{}.html'.format(notification), context ) # Define headers headers['Auto-Submitted'] = 'auto-generated' headers['X-AutoGenerated'] = 'yes' headers['Precedence'] = 'bulk' headers['X-Mailer'] = 'Weblate {}'.format(weblate.VERSION) # Reply to header if user is not None: headers['Reply-To'] = user.email # List of recipients if email == 'ADMINS': emails = [a[1] for a in settings.ADMINS] else: emails = [email] # Create message email = EmailMultiAlternatives( settings.EMAIL_SUBJECT_PREFIX + subject, body, to=emails, headers=headers, ) email.attach_alternative( html_body, 'text/html' ) # Return the mail return email finally: django_translation.activate(cur_language)
def get_widgets_url(self): """ Returns absolute URL for widgets. """ return get_site_url(reverse("widgets", kwargs={"project": self.slug}))
def export_stats(request, project, subproject): ''' Exports stats in JSON format. ''' subprj = get_subproject(request, project, subproject) try: indent = int(request.GET['indent']) except (ValueError, KeyError): indent = None jsonp = None if 'jsonp' in request.GET and request.GET['jsonp']: jsonp = request.GET['jsonp'] response = [] for trans in subprj.translation_set.all(): response.append({ 'code': trans.language.code, 'name': trans.language.name, 'total': trans.total, 'total_words': trans.total_words, 'last_change': trans.last_change, 'last_author': trans.get_last_author(), 'translated': trans.translated, 'translated_words': trans.translated_words, 'translated_percent': trans.get_translated_percent(), 'fuzzy': trans.fuzzy, 'fuzzy_percent': trans.get_fuzzy_percent(), 'failing': trans.failing_checks, 'failing_percent': trans.get_failing_checks_percent(), 'url': trans.get_share_url(), 'url_translate': get_site_url(trans.get_absolute_url()), }) json_data = json.dumps( response, default=json_dt_handler, indent=indent, ) if jsonp: return HttpResponse('{0}({1})'.format( jsonp, json_data, ), content_type='application/javascript') return HttpResponse(json_data, content_type='application/json')
def send_notification_email(language, email, notification, translation_obj=None, context=None, headers=None, user=None, info=None): ''' Renders and sends notification email. ''' cur_language = django_translation.get_language() context = context or {} headers = headers or {} try: if info is None: info = translation_obj.__unicode__() weblate.logger.info( 'sending notification %s on %s to %s', notification, info, email ) # Load user language if language is not None: django_translation.activate(language) # Template name context['subject_template'] = 'mail/{}_subject.txt'.format( notification ) # Adjust context context['current_site_url'] = get_site_url() if translation_obj is not None: context['translation'] = translation_obj context['translation_url'] = get_site_url( translation_obj.get_absolute_url() ) context['site_title'] = SITE_TITLE # Render subject subject = render_to_string( context['subject_template'], context ).strip() # Render body body = render_to_string( 'mail/{}.txt'.format(notification), context ) html_body = render_to_string( 'mail/{}.html'.format(notification), context ) # Define headers headers['Auto-Submitted'] = 'auto-generated' headers['X-AutoGenerated'] = 'yes' headers['Precedence'] = 'bulk' headers['X-Mailer'] = 'Weblate {}'.format(weblate.VERSION) # Reply to header if user is not None: headers['Reply-To'] = user.email # List of recipients if email == 'ADMINS': emails = [a[1] for a in settings.ADMINS] else: emails = [email] # Create message email = EmailMultiAlternatives( settings.EMAIL_SUBJECT_PREFIX + subject, body, to=emails, headers=headers, ) email.attach_alternative( html_body, 'text/html' ) # Send it out email.send(fail_silently=False) except SMTPException as error: weblate.logger.error('Failed to send email: %s', error) finally: django_translation.activate(cur_language)
def update_unit(self, unit, request, user=None): ''' Updates backend file and unit. ''' if user is None: user = request.user # Save with lock acquired with self.subproject.repository_lock: src = unit.get_source_plurals()[0] add = False pounit, add = self.store.find_unit(unit.context, src) # Bail out if we have not found anything if pounit is None or pounit.is_obsolete(): return False, None # Check for changes if (not add and unit.target == pounit.get_target() and unit.fuzzy == pounit.is_fuzzy()): return False, pounit # Store translations if unit.is_plural(): pounit.set_target(unit.get_target_plurals()) else: pounit.set_target(unit.target) # Update fuzzy flag pounit.mark_fuzzy(unit.fuzzy) # Optionally add unit to translation file if add: self.store.add_unit(pounit) # We need to update backend now author = self.get_author_name(user) # Update po file header po_revision_date = (datetime.now().strftime('%Y-%m-%d %H:%M') + poheader.tzstring()) # Prepare headers to update headers = { 'add': True, 'last_translator': author, 'plural_forms': self.language.get_plural_form(), 'language': self.language_code, 'PO_Revision_Date': po_revision_date, } # Optionally store language team with link to website if self.subproject.project.set_translation_team: headers['language_team'] = '%s <%s>' % ( self.language.name, get_site_url(self.get_absolute_url()), ) # Optionally store email for reporting bugs in source report_source_bugs = self.subproject.report_source_bugs if report_source_bugs != '': headers['report_msgid_bugs_to'] = report_source_bugs # Update genric headers self.store.update_header(**headers) # commit possible previous changes (by other author) self.commit_pending(request, author) # save translation changes self.store.save() # commit VCS repo if needed self.git_commit(request, author, timezone.now(), sync=True) return True, pounit
def update_unit(self, unit, request, user=None): ''' Updates backend file and unit. ''' if user is None: user = request.user # Save with lock acquired with self.subproject.git_lock: src = unit.get_source_plurals()[0] add = False pounit, add = self.store.find_unit(unit.context, src) # Bail out if we have not found anything if pounit is None or pounit.is_obsolete(): return False, None # Check for changes if (not add and unit.target == pounit.get_target() and unit.fuzzy == pounit.is_fuzzy()): return False, pounit # Store translations if unit.is_plural(): pounit.set_target(unit.get_target_plurals()) else: pounit.set_target(unit.target) # Update fuzzy flag pounit.mark_fuzzy(unit.fuzzy) # Optionally add unit to translation file if add: self.store.add_unit(pounit) # We need to update backend now author = self.get_author_name(user) # Update po file header po_revision_date = ( datetime.now().strftime('%Y-%m-%d %H:%M') + poheader.tzstring() ) # Prepare headers to update headers = { 'add': True, 'last_translator': author, 'plural_forms': self.language.get_plural_form(), 'language': self.language_code, 'PO_Revision_Date': po_revision_date, } # Optionally store language team with link to website if self.subproject.project.set_translation_team: headers['language_team'] = '%s <%s>' % ( self.language.name, get_site_url(self.get_absolute_url()), ) # Optionally store email for reporting bugs in source report_source_bugs = self.subproject.report_source_bugs if report_source_bugs != '': headers['report_msgid_bugs_to'] = report_source_bugs # Update genric headers self.store.update_header( **headers ) # commit possible previous changes (by other author) self.commit_pending(request, author) # save translation changes self.store.save() # commit Git repo if needed self.git_commit(request, author, timezone.now(), sync=True) return True, pounit
def widgets(request, project): obj = get_project(request, project) # Parse possible language selection form = EnageLanguageForm(obj, request.GET) lang = None if form.is_valid() and form.cleaned_data['lang'] != '': lang = Language.objects.get(code=form.cleaned_data['lang']) if lang is None: engage_base = reverse('engage', kwargs={'project': obj.slug}) else: engage_base = reverse('engage-lang', kwargs={ 'project': obj.slug, 'lang': lang.code }) engage_url = get_site_url(engage_base) engage_url_track = '%s?utm_source=widget' % engage_url widget_base_url = get_site_url( reverse('widgets', kwargs={'project': obj.slug})) widget_list = [] for widget_name in sorted(WIDGETS, key=widgets_sorter): widget_class = WIDGETS[widget_name] color_list = [] for color in widget_class.colors: if lang is None: color_url = reverse('widget-image', kwargs={ 'project': obj.slug, 'widget': widget_name, 'color': color, 'extension': widget_class.extension, }) else: color_url = reverse('widget-image-lang', kwargs={ 'project': obj.slug, 'widget': widget_name, 'color': color, 'lang': lang.code, 'extension': widget_class.extension, }) color_list.append({ 'name': color, 'url': get_site_url(color_url), }) widget_list.append({ 'name': widget_name, 'colors': color_list, }) return render( request, 'widgets.html', { 'engage_url': engage_url, 'engage_url_track': engage_url_track, 'widget_list': widget_list, 'widget_base_url': widget_base_url, 'object': obj, 'image_src': widget_list[0]['colors'][0]['url'], 'form': form, })
def send_notification_email(language, email, notification, translation_obj=None, context=None, headers=None, user=None, info=None): ''' Renders and sends notification email. ''' cur_language = django_translation.get_language() if context is None: context = {} if headers is None: headers = {} try: if info is None: info = translation_obj.__unicode__() weblate.logger.info('sending notification %s on %s to %s', notification, info, email) # Load user language if language is not None: django_translation.activate(language) # Template names subject_template = 'mail/{}_subject.txt'.format(notification) body_template = 'mail/{}.txt'.format(notification) html_body_template = 'mail/{}.html'.format(notification) # Adjust context context['current_site_url'] = get_site_url() if translation_obj is not None: context['translation'] = translation_obj context['translation_url'] = get_site_url( translation_obj.get_absolute_url()) context['subject_template'] = subject_template # Render subject subject = render_to_string(subject_template, context).strip() # Render body body = render_to_string(body_template, context) html_body = render_to_string(html_body_template, context) # Define headers headers['Auto-Submitted'] = 'auto-generated' headers['X-AutoGenerated'] = 'yes' headers['Precedence'] = 'bulk' headers['X-Mailer'] = 'Weblate {}'.format(weblate.VERSION) # Reply to header if user is not None: headers['Reply-To'] = user.email # List of recipients if email == 'ADMINS': emails = [a[1] for a in settings.ADMINS] else: emails = [email] # Create message email = EmailMultiAlternatives( settings.EMAIL_SUBJECT_PREFIX + subject, body, to=emails, headers=headers, ) email.attach_alternative(html_body, 'text/html') # Send it out email.send(fail_silently=False) finally: django_translation.activate(cur_language)
def widgets(request, project): obj = get_project(request, project) # Parse possible language selection form = EnageLanguageForm(obj, request.GET) lang = None if form.is_valid() and form.cleaned_data['lang'] != '': lang = Language.objects.get(code=form.cleaned_data['lang']) if lang is None: engage_base = reverse('engage', kwargs={'project': obj.slug}) else: engage_base = reverse( 'engage-lang', kwargs={'project': obj.slug, 'lang': lang.code} ) engage_url = get_site_url(engage_base) engage_url_track = '%s?utm_source=widget' % engage_url widget_base_url = get_site_url( reverse('widgets', kwargs={'project': obj.slug}) ) widget_list = [] for widget_name in sorted(WIDGETS, key=widgets_sorter): widget_class = WIDGETS[widget_name] color_list = [] for color in widget_class.colors: if lang is None: color_url = reverse( 'widget-image', kwargs={ 'project': obj.slug, 'widget': widget_name, 'color': color, 'extension': widget_class.extension, } ) else: color_url = reverse( 'widget-image-lang', kwargs={ 'project': obj.slug, 'widget': widget_name, 'color': color, 'lang': lang.code, 'extension': widget_class.extension, } ) color_list.append({ 'name': color, 'url': get_site_url(color_url), }) widget_list.append({ 'name': widget_name, 'colors': color_list, }) return render( request, 'widgets.html', { 'engage_url': engage_url, 'engage_url_track': engage_url_track, 'widget_list': widget_list, 'widget_base_url': widget_base_url, 'object': obj, 'image_src': widget_list[0]['colors'][0]['url'], 'form': form, } )
def get_notification_email(language, email, notification, translation_obj=None, context=None, headers=None, user=None, info=None): ''' Renders notification email. ''' cur_language = django_translation.get_language() context = context or {} headers = headers or {} references = None if 'unit' in context: unit = context['unit'] references = '{0}/{1}/{2}/{3}'.format( unit.translation.subproject.project.slug, unit.translation.subproject.slug, unit.translation.language.code, unit.id) if references is not None: references = '<{0}@{1}>'.format(references, get_site_domain()) headers['In-Reply-To'] = references headers['References'] = references try: if info is None: info = translation_obj.__unicode__() weblate.logger.info('sending notification %s on %s to %s', notification, info, email) # Load user language if language is not None: django_translation.activate(language) # Template name context['subject_template'] = 'mail/{}_subject.txt'.format( notification) # Adjust context context['current_site_url'] = get_site_url() if translation_obj is not None: context['translation'] = translation_obj context['translation_url'] = get_site_url( translation_obj.get_absolute_url()) context['site_title'] = SITE_TITLE # Render subject subject = render_to_string(context['subject_template'], context).strip() # Render body body = render_to_string('mail/{}.txt'.format(notification), context) html_body = render_to_string('mail/{}.html'.format(notification), context) # Define headers headers['Auto-Submitted'] = 'auto-generated' headers['X-AutoGenerated'] = 'yes' headers['Precedence'] = 'bulk' headers['X-Mailer'] = 'Weblate {}'.format(weblate.VERSION) # Reply to header if user is not None: headers['Reply-To'] = user.email # List of recipients if email == 'ADMINS': emails = [a[1] for a in settings.ADMINS] else: emails = [email] # Create message email = EmailMultiAlternatives( settings.EMAIL_SUBJECT_PREFIX + subject, body, to=emails, headers=headers, ) email.attach_alternative(html_body, 'text/html') # Return the mail return email finally: django_translation.activate(cur_language)
def get_share_url(self): """ Returns absolute URL usable for sharing. """ return get_site_url(reverse('engage', kwargs={'project': self.slug}))
def get_widgets_url(self): """ Returns absolute URL for widgets. """ return get_site_url(reverse('widgets', kwargs={'project': self.slug}))
def get_notification_email( language, email, notification, translation_obj=None, context=None, headers=None, user=None, info=None ): """ Renders notification email. """ cur_language = django_translation.get_language() context = context or {} headers = headers or {} references = None if "unit" in context: unit = context["unit"] references = "{0}/{1}/{2}/{3}".format( unit.translation.subproject.project.slug, unit.translation.subproject.slug, unit.translation.language.code, unit.id, ) if references is not None: references = "<{0}@{1}>".format(references, get_site_domain()) headers["In-Reply-To"] = references headers["References"] = references try: if info is None: info = translation_obj.__unicode__() weblate.logger.info("sending notification %s on %s to %s", notification, info, email) # Load user language if language is not None: django_translation.activate(language) # Template name context["subject_template"] = "mail/{}_subject.txt".format(notification) # Adjust context context["current_site_url"] = get_site_url() if translation_obj is not None: context["translation"] = translation_obj context["translation_url"] = get_site_url(translation_obj.get_absolute_url()) context["site_title"] = SITE_TITLE # Render subject subject = render_to_string(context["subject_template"], context).strip() # Render body body = render_to_string("mail/{}.txt".format(notification), context) html_body = render_to_string("mail/{}.html".format(notification), context) # Define headers headers["Auto-Submitted"] = "auto-generated" headers["X-AutoGenerated"] = "yes" headers["Precedence"] = "bulk" headers["X-Mailer"] = "Weblate {}".format(weblate.VERSION) # Reply to header if user is not None: headers["Reply-To"] = user.email # List of recipients if email == "ADMINS": emails = [a[1] for a in settings.ADMINS] else: emails = [email] # Create message email = EmailMultiAlternatives(settings.EMAIL_SUBJECT_PREFIX + subject, body, to=emails, headers=headers) email.attach_alternative(html_body, "text/html") # Return the mail return email finally: django_translation.activate(cur_language)