Example #1
0
    def start(self, context, request, appstruct, **kw):
        site = get_site_folder(True)
        url = request.resource_url(context, "")
        deadline_date = context.init_deadline(
            datetime.datetime.now(tz=pytz.UTC))
        localizer = request.localizer
        deadline_str = to_localized_time(
            deadline_date, request,
            format_id='defined_literal', ignore_month=True,
            ignore_year=True, translate=True)
        mail_template = site.get_mail_template('preregistration')
        subject = mail_template['subject']
        deadline_str = to_localized_time(
            deadline_date, request,
            format_id='defined_literal', ignore_month=True,
            ignore_year=True, translate=True)
        message = mail_template['template'].format(
            preregistration=context,
            user_title=localizer.translate(
                _(getattr(context, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)
        alert('email', [site.get_site_sender()], [context.email],
              {'subject': subject, 'body': message})

        request.registry.notify(ActivityExecuted(self, [context], get_current()))
        return {}
Example #2
0
    def start(self, context, request, appstruct, **kw):
        site = get_site_folder(True)
        url = request.resource_url(context, "")
        deadline_date = context.init_deadline(
            datetime.datetime.now(tz=pytz.UTC))
        localizer = request.localizer
        deadline_str = to_localized_time(deadline_date,
                                         request,
                                         format_id='defined_literal',
                                         ignore_month=True,
                                         ignore_year=True,
                                         translate=True)
        mail_template = site.get_mail_template('preregistration')
        subject = mail_template['subject']
        deadline_str = to_localized_time(deadline_date,
                                         request,
                                         format_id='defined_literal',
                                         ignore_month=True,
                                         ignore_year=True,
                                         translate=True)
        message = mail_template['template'].format(
            preregistration=context,
            user_title=localizer.translate(
                _(getattr(context, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)
        alert('email', [site.get_site_sender()], [context.email], {
            'subject': subject,
            'body': message
        })

        request.registry.notify(
            ActivityExecuted(self, [context], get_current()))
        return {}
Example #3
0
def remind_users_evolve(root, registry):
    from lac.ips.mailer import mailer_send
    from lac.utilities.utils import to_localized_time
    from lac.mail import (PREREGISTRATION_SUBJECT, PREREGISTRATION_MESSAGE)
    root = getSite()
    request = get_current_request()
    site = request.get_site_folder
    for preregistration in root.preregistrations:
        url = request.resource_url(preregistration, "")
        deadline_date = preregistration.init_deadline(
            datetime.datetime.now(tz=pytz.UTC))
        localizer = request.localizer
        deadline_str = to_localized_time(deadline_date,
                                         request,
                                         format_id='defined_literal',
                                         ignore_month=True,
                                         ignore_year=True,
                                         translate=True)
        log.info(getattr(preregistration, 'title', 'user'))
        message = PREREGISTRATION_MESSAGE.format(
            preregistration=preregistration,
            user_title=localizer.translate(
                _(getattr(preregistration, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)

        mailer_send(subject=PREREGISTRATION_SUBJECT,
                    recipients=[preregistration.email],
                    sender=site.get_site_sender(),
                    body=message)

    log.info('Remind users evolved.')
Example #4
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        site = get_site_folder(True, request)
        contacts = [
            c for c in getattr(site, 'contacts', []) if c.get('email', None)
        ]
        if contacts:
            subject = "Avis d'un utilisateur"
            mail = appstruct.get('improvement')
            sender = appstruct.get('email')
            alert('email', [sender], [contacts[-1].get('email')], {
                'subject': subject,
                'body': mail
            })

        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac." + appstruct['id']], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(now, translate=True)
        text = '{improvement}\n User: {user}\n URL: {url}\n Email: {email}\n Date: {date}'.format(
            **appstruct)
        alert('slack', [], ['improve'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = appstruct.get('email', '')

        return {}
Example #5
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        site = get_site_folder(True, request)
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac." + appstruct['id']], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(now, translate=True)
        text = 'Aimez-vous la nouvelle version: {new_version}\n '
        if appstruct['new_version'] == 'False':
            text += 'Pourquoi non: {explanation}\n '

        text += 'Aimeriez-vous une application mobile: {mobile_application}\n \n User: {user}\n Email: {email}\n Date: {date}'
        text = text.format(**appstruct)
        alert('slack', [], ['questionnaire'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = appstruct.get('email', '')

        return {}
Example #6
0
def remind_users_evolve(root, registry):
    from lac.ips.mailer import mailer_send
    from lac.utilities.utils import to_localized_time
    from lac.mail import (
        PREREGISTRATION_SUBJECT, PREREGISTRATION_MESSAGE)
    root = getSite()
    request = get_current_request()
    site = request.get_site_folder
    for preregistration in root.preregistrations:
        url = request.resource_url(preregistration, "")
        deadline_date = preregistration.init_deadline(
            datetime.datetime.now(tz=pytz.UTC))
        localizer = request.localizer
        deadline_str = to_localized_time(
            deadline_date, request,
            format_id='defined_literal', ignore_month=True,
            ignore_year=True, translate=True)
        log.info(getattr(preregistration, 'title', 'user'))
        message = PREREGISTRATION_MESSAGE.format(
            preregistration=preregistration,
            user_title=localizer.translate(
                _(getattr(preregistration, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)

        mailer_send(subject=PREREGISTRATION_SUBJECT,
                    recipients=[preregistration.email],
                    sender=site.get_site_sender(),
                    body=message)

    log.info('Remind users evolved.')
Example #7
0
    def start(self, context, request, appstruct, **kw):
        subject = appstruct.get('subject')
        mail = appstruct.get('message')
        sender = appstruct.get('email')
        services = appstruct.get('services')
        alert('email', [sender], list(services), {
            'subject': subject,
            'body': mail
        })
        appstruct.pop('_csrf_token_')
        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        appstruct['services'] = str(appstruct['services'])
        site = get_site_folder(True, request)
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac.contact"], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(now, translate=True)
        text = 'Sujet: {subject}\n Message: {message}\n User: {user}\n Nom: {name}\n Email: {email}\n Date: {date}\n\n Service: {services}'.format(
            **appstruct)
        alert('slack', [], ['lac_contact'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = sender

        return {}
Example #8
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        site = get_site_folder(True, request)
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac."+appstruct['id']], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(
            now, translate=True)
        text = 'Aimez-vous la nouvelle version: {new_version}\n '
        if appstruct['new_version'] == 'False':
            text += 'Pourquoi non: {explanation}\n '

        text += 'Aimeriez-vous une application mobile: {mobile_application}\n \n User: {user}\n Email: {email}\n Date: {date}'
        text = text.format(**appstruct)
        alert('slack', [], ['questionnaire'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = appstruct.get('email', '')

        return {}
Example #9
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        site = get_site_folder(True, request)
        contacts = [c for c in getattr(site, 'contacts', [])
                    if c.get('email', None)]
        if contacts:
            subject = "Avis d'un utilisateur"
            mail = appstruct.get('improvement')
            sender = appstruct.get('email')
            alert('email', [sender], [contacts[-1].get('email')],
                  {'subject': subject, 'body': mail})

        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac."+appstruct['id']], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(
            now, translate=True)
        text = '{improvement}\n User: {user}\n URL: {url}\n Email: {email}\n Date: {date}'.format(**appstruct)
        alert('slack', [], ['improve'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = appstruct.get('email', '')

        return {}
Example #10
0
    def start(self, context, request, appstruct, **kw):
        subject = appstruct.get('subject')
        mail = appstruct.get('message')
        sender = appstruct.get('email')
        services = appstruct.get('services')
        alert('email', [sender], list(services),
              {'subject': subject, 'body': mail})
        appstruct.pop('_csrf_token_')
        user = request.user
        appstruct['user'] = '******'
        if user:
            appstruct['user'] = get_oid(user)

        now = datetime.datetime.now(tz=pytz.timezone('Europe/Paris'))
        appstruct['date'] = now.isoformat()
        appstruct['services'] = str(appstruct['services'])
        site = get_site_folder(True, request)
        appstruct['site'] = get_oid(site)
        alert('arango', [], ["lac.contact"], appstruct)
        #alert slack
        appstruct['date'] = to_localized_time(
            now, translate=True)
        text = 'Sujet: {subject}\n Message: {message}\n User: {user}\n Nom: {name}\n Email: {email}\n Date: {date}\n\n Service: {services}'.format(**appstruct)
        alert('slack', [], ['lac_contact'], {'text': text})
        if user and not getattr(user, 'email', ''):
            user.email = sender

        return {}
Example #11
0
 def to_localized_time(
     self, date, date_from=None,
     date_only=False, format_id='digital',
     ignore_month=False, ignore_year=False,
     add_day_name=False):
     return to_localized_time(
         date, request=self.request, date_from=date_from,
         date_only=date_only, format_id=format_id,
         ignore_month=ignore_month, ignore_year=ignore_year,
         add_day_name=add_day_name, translate=True)
Example #12
0
 def relevant_data(self):
     result = super(CulturalEvent, self).relevant_data
     result.extend([', '.join([a.title for a in self.artists]),
                    ', '.join([to_localized_time(
                               d, format_id='direct_literal',
                               add_day_name=True, translate=True)
                               for d in occurences_start(self, 'dates')]),
                    ', '.join([s.venue.city for s in self.schedules
                               if s.venue]),
                    ', '.join([s.venue.title for s in self.schedules
                               if s.venue])])
     return result
Example #13
0
 def relevant_data(self):
     result = super(CulturalEvent, self).relevant_data
     result.extend([
         ', '.join([a.title for a in self.artists]), ', '.join([
             to_localized_time(d,
                               format_id='direct_literal',
                               add_day_name=True,
                               translate=True)
             for d in occurences_start(self, 'dates')
         ]), ', '.join([s.venue.city for s in self.schedules if s.venue]),
         ', '.join([s.venue.title for s in self.schedules if s.venue])
     ])
     return result
Example #14
0
 def test_to_localized_time(self):
     date = datetime.datetime(2016, 12, 9, 12, 13, 30)
     result = utils.to_localized_time(date, translate=True)
     self.assertEqual(result, '12/9/2016 12:13')
     result = utils.to_localized_time(date,
                                      format_id='defined_literal',
                                      translate=True)
     self.assertEqual(result,
                      "On December 9 2016 at 12 o'clock and 13 minutes")
     result = utils.to_localized_time(date,
                                      format_id='direct_literal',
                                      translate=True)
     self.assertEqual(result,
                      "December 9 2016 at 12 o'clock and 13 minutes")
     #date_only
     result = utils.to_localized_time(date, date_only=True, translate=True)
     self.assertEqual(result, '12/9/2016')
     result = utils.to_localized_time(date,
                                      format_id='defined_literal',
                                      date_only=True,
                                      translate=True)
     self.assertEqual(result, "On December 9 2016")
     result = utils.to_localized_time(date,
                                      format_id='direct_literal',
                                      date_only=True,
                                      translate=True)
     self.assertEqual(result, "December 9 2016")
     #ignore_year
     result = utils.to_localized_time(date,
                                      ignore_year=True,
                                      translate=True)
     self.assertEqual(result, '12/9 12:13')
     result = utils.to_localized_time(date,
                                      format_id='defined_literal',
                                      ignore_year=True,
                                      translate=True)
     self.assertEqual(result, "On December 9 at 12 o'clock and 13 minutes")
     result = utils.to_localized_time(date,
                                      format_id='direct_literal',
                                      ignore_year=True,
                                      translate=True)
     self.assertEqual(result, "December 9 at 12 o'clock and 13 minutes")
Example #15
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        if getattr(preregistration, 'is_cultural_animator', False) and \
           appstruct.get('structures', None):
            structure = appstruct['structures'][0]['_object_data']
            if structure:
                preregistration.setproperty('structure', structure)
        else:
            preregistration.is_cultural_animator = False

        url = request.resource_url(preregistration, "")
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(remove_expired_preregistration,
                                   deadline,
                                   call_id,
                                   root=root,
                                   preregistration=preregistration)
        preregistration.reindex()
        transaction.commit()
        deadline_date = preregistration.get_deadline_date()
        localizer = request.localizer
        site = request.get_site_folder
        mail_template = site.get_mail_template('preregistration')
        subject = mail_template['subject']
        deadline_str = to_localized_time(deadline_date,
                                         request,
                                         format_id='defined_literal',
                                         ignore_month=True,
                                         ignore_year=True,
                                         translate=True)
        message = mail_template['template'].format(
            preregistration=preregistration,
            user_title=localizer.translate(
                _(getattr(preregistration, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)
        alert('email', [site.get_site_sender()], [preregistration.email], {
            'subject': subject,
            'body': message
        })
        request.registry.notify(ActivityExecuted(self, [preregistration],
                                                 None))
        return {'preregistration': preregistration}
Example #16
0
 def to_localized_time(self,
                       date,
                       date_from=None,
                       date_only=False,
                       format_id='digital',
                       ignore_month=False,
                       ignore_year=False,
                       add_day_name=False):
     return to_localized_time(date,
                              request=self.request,
                              date_from=date_from,
                              date_only=date_only,
                              format_id=format_id,
                              ignore_month=ignore_month,
                              ignore_year=ignore_year,
                              add_day_name=add_day_name,
                              translate=True)
Example #17
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        if getattr(preregistration, 'is_cultural_animator', False) and \
           appstruct.get('structures', None):
            structure = appstruct['structures'][0]['_object_data']
            if structure:
                preregistration.setproperty('structure', structure)
        else:
            preregistration.is_cultural_animator = False

        url = request.resource_url(preregistration, "")
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(
            remove_expired_preregistration, deadline, call_id,
            root=root, preregistration=preregistration)
        preregistration.reindex()
        transaction.commit()
        deadline_date = preregistration.get_deadline_date()
        localizer = request.localizer
        site = request.get_site_folder
        mail_template = site.get_mail_template('preregistration')
        subject = mail_template['subject']
        deadline_str = to_localized_time(
            deadline_date, request,
            format_id='defined_literal', ignore_month=True,
            ignore_year=True, translate=True)
        message = mail_template['template'].format(
            preregistration=preregistration,
            user_title=localizer.translate(
                _(getattr(preregistration, 'user_title', ''))),
            url=url,
            deadline_date=deadline_str.lower(),
            lac_title=request.root.title)
        alert('email', [site.get_site_sender()], [preregistration.email],
              {'subject': subject, 'body': message})
        request.registry.notify(ActivityExecuted(self, [preregistration], None))
        return {'preregistration': preregistration}
Example #18
0
    def redirect(self, context, request, **kw):
        filters = kw.get('filters', [])
        keywords = []
        if filters:
            keywords = list(filters[0].get(
                'metadata_filter', {}).get(
                'tree', {}).get(ROOT_TREE, {}).keys())

        keywords = '-'.join(keywords)
        user = kw.get('user', None)
        user_title = getattr(user, 'title', user.name)
        now = datetime.datetime.now()
        date = to_localized_time(now, request=request, translate=True)
        file_name = 'Extraction_{keywords}_{date}_{user}'.format(
            keywords=keywords, date=date, user=user_title)
        file_name = file_name.replace(' ', '-')
        odtfile = kw.get('file', '')
        response = request.response
        response.content_type = 'application/vnd.oasis.opendocument.text'
        response.content_disposition = 'inline; filename="{file_name}.odt"'.format(
            file_name=file_name)
        response.app_iter = FileIter(odtfile)
        return response
Example #19
0
    def redirect(self, context, request, **kw):
        filters = kw.get('filters', [])
        keywords = []
        if filters:
            keywords = list(filters[0].get('metadata_filter',
                                           {}).get('tree',
                                                   {}).get(ROOT_TREE,
                                                           {}).keys())

        keywords = '-'.join(keywords)
        user = kw.get('user', None)
        user_title = getattr(user, 'title', user.name)
        now = datetime.datetime.now()
        date = to_localized_time(now, request=request, translate=True)
        file_name = 'Extraction_{keywords}_{date}_{user}'.format(
            keywords=keywords, date=date, user=user_title)
        file_name = file_name.replace(' ', '-')
        odtfile = kw.get('file', '')
        response = request.response
        response.content_type = 'application/vnd.oasis.opendocument.text'
        response.content_disposition = 'inline; filename="{file_name}.odt"'.format(
            file_name=file_name)
        response.app_iter = FileIter(odtfile)
        return response