def i18n_string(data, locales): locales = copy.deepcopy(locales) with language("en"): if hasattr(data, "_proxy____prepared"): data = str(data) if isinstance(data, str): data = {"en": str(data)} if not isinstance(data, dict): data = {"en": ""} english = data.get("en", "") for locale in locales: if locale != 'en' and not data.get(locale): with language(locale): data[locale] = gettext(english) return LazyI18nString(data)
def get(self, request, *args, **kwargs): locale = request.GET.get("locale", "en") with language(locale): data = ScheduleData( event=self.request.event, schedule=self.schedule, with_accepted=self.answer_type == "html" and self.schedule == self.request.event.wip_schedule, with_breaks=True, ).data schedule = self.get_schedule_data_proportional(data)["data"] for day in schedule: for room in day["rooms"]: room["name"] = str(room["name"]) room["talks"] = [{ "title": talk.submission.title if talk.submission else str(talk.description), "code": talk.submission.code if talk.submission else None, "display_speaker_names": talk.submission.display_speaker_names if talk.submission else None, "speakers": [{ "name": speaker.name, "code": speaker.code } for speaker in talk.submission.speakers.all()] if talk.submission else None, "height": talk.height, "top": talk.top, "start": talk.start, "end": talk.end, "do_not_record": talk.submission.do_not_record if talk.submission else None, "track": getattr(talk.submission.track, "name", "") if talk.submission else None, } for talk in room["talks"]] response = JsonResponse( { "schedule": schedule, "event": { "url": request.event.urls.schedule.full(), "tracks": [{ "name": track.name, "color": track.color } for track in request.event.tracks.all()], }, }, encoder=I18nJSONEncoder, ) response["Access-Control-Allow-Origin"] = "*" return response
def get(self, request, *args, **kwargs): locale = request.GET.get('locale', 'en') with language(locale): schedule = list(self.get_schedule_data()[0]) for day in schedule: for room in day['rooms']: room['name'] = str(room['name']) room['talks'] = [{ 'title': talk.submission.title if talk.submission else str(talk.description), 'code': talk.submission.code if talk.submission else None, 'display_speaker_names': talk.submission.display_speaker_names if talk.submission else None, 'speakers': [{ 'name': speaker.name, 'code': speaker.code } for speaker in talk.submission.speakers.all()] if talk.submission else None, 'height': talk.height, 'top': talk.top, 'start': talk.start, 'end': talk.end, 'do_not_record': talk.submission.do_not_record if talk.submission else None, 'track': getattr(talk.submission.track, 'name', '') if talk.submission else None, } for talk in room['talks']] response = JsonResponse( { 'schedule': schedule, 'event': { 'url': request.event.urls.schedule.full(), 'tracks': [{ 'name': track.name, 'color': track.color } for track in request.event.tracks.all()], } }, encoder=I18nJSONEncoder, ) response['Access-Control-Allow-Origin'] = '*' return response
def form_valid(self, form): preview = self.request.POST.get("action") == "preview" if preview: self.output = {} # Only approximate, good enough. Doesn't run deduplication, so it doesn't have to # run rendering for all placeholders for all people, either. result = form.get_recipient_submissions() if not len(result): messages.error( self.request, _("There are no proposals or sessions matching this selection."), ) return self.get(self.request, *self.args, **self.kwargs) for locale in self.request.event.locales: with language(locale): context_dict = TolerantDict() for k, v in form.get_valid_placeholders().items(): context_dict[ k ] = '<span class="placeholder" title="{}">{}</span>'.format( _( "This value will be replaced based on dynamic parameters." ), v.render_sample(self.request.event), ) subject = bleach.clean( form.cleaned_data["subject"].localize(locale), tags=[] ) preview_subject = subject.format_map(context_dict) message = form.cleaned_data["text"].localize(locale) preview_text = rich_text(message.format_map(context_dict)) self.output[locale] = { "subject": _("Subject: {subject}").format( subject=preview_subject ), "html": preview_text, } self.mail_count = len(result) return self.get(self.request, *self.args, **self.kwargs) result = form.save() messages.success( self.request, _( "{count} emails have been saved to the outbox – you can make individual changes there or just send them all." ).format(count=len(result)), ) return super().form_valid(form)