Пример #1
0
def test_view(request):
    debug = False
    f = Flash()
    f.critical('flashin test...')
    #~ relaties = DBSession.query(Relatie)
    relaties_dinsdag = request.mongo_db['relaties'].find(
        {"Relatie.children.news.children.day.text": "dinsdag"})
    relaties_vrijdag = request.mongo_db['relaties'].find(
        {"Relatie.children.news.children.day.text": "dinsdag"})
    records = dict()
    records['dinsdag'] = dict(
        (record['_id'], type(record['_id'])) for record in relaties_dinsdag)
    records['vrijdag'] = dict(
        (record['_id'], record) for record in relaties_vrijdag)
    l = type(records['dinsdag'].items())
    #~ g = TestView.get_grid(Relatie, relaties)
    debug = '\n'.join((str(type(records)), str(l)))
    userid = authenticated_userid(request)
    if userid is None:
        raise Forbidden()
    return {
        'relaties': records,
        'greeting': 'Hello, {n}!'.format(n=userid),
        'debug': debug,
        'flash': f.render(),
    }
Пример #2
0
 def render_xhr_format(self, fs=None, **kwargs):
     html = Base.render_xhr_format(self, fs=fs, **kwargs)
     if fs and request.POST and 'field' not in request.GET:
         flash = Flash()
         if fs.errors:
             errors = [
                 f.label() for f in fs.render_fields.values() if f.errors
             ]
             flash.error('Field(s) %s have errors' % ','.join(errors))
         else:
             flash.info('Record saved')
         html = literal(html) + flash.render()
     return html
Пример #3
0
 def render_xhr_format(self, fs=None, **kwargs):
     html = Base.render_xhr_format(self, fs=fs, **kwargs)
     if fs and request.POST and 'field' not in request.GET:
         flash = Flash()
         if fs.errors:
             errors = [f.label() for f in fs.render_fields.values() if f.errors]
             flash.error('Field(s) %s have errors' % ','.join(errors))
         else:
             flash.info('Record saved')
         html = literal(html) + flash.render()
     return html
Пример #4
0
    def main(self, ezine):
        """
        main(ezine)

        """
        # initialize variables
        newsletter = '.'.join((ezine.name, 'html'))
        subject = ezine.subject
        brand = ezine.type

        log.info('{n} started'.format(n='run.py'))
        try:
            n = pynotify.Notification('{n} started'.format(n='run.py'), '')
            n.show()
        except:
            f = Flash()
            f.critical('{n} started'.format(n='run.py'))

        # READ SETTINGS
        s = Settings(brand)
        log.debug('Settings read are: {s}'.format(s=s))
        # Did we get a filename?
        if newsletter or subject:
            if newsletter:
                s.filenames = (newsletter, )
            if subject:
                s.email_properties['subject'] = subject

        # START RUN FOR...
        if s.yamlfile:
            log.info('Reading yaml file')
            with open(s.yamlfile, 'r') as f:
                data = yaml.load(f)
        else:
            pass

        # TODO: check if list or str, and if dir: dan alle files

        for file in s.filenames:
            if not newsletter:
                s.filepath = os.path.join(s.mainpath, file)
            s.email_name = file.split('.')[0].capitalize()
            s.email_properties['name'] = s.email_name
            log.info('Handling file: {n}.'.format(n=s.email_name))
            if s.yamlfile:
                with open(s.yamlfile, 'r') as f:
                    data = yaml.load(f)
                for d in data['mails']:
                    if d == s.email_name:
                        s.email_properties['subject'] = data['mails'][d][
                            'Subject']

            # MAKE EZINE
            if s.todo['make']:
                ezine = s.ezine

            # UPLOAD EZINE TO FTP
            if s.todo['upload']:
                log.debug('Brand is "{b}".'.format(b=brand))
                log.debug('File is "{f}".'.format(f=file))
                try:
                    f = Ftp(s.host, s.ftpuser, s.ftppasswd, s.remotedir)
                except Exception as e:
                    raise e
                else:
                    if asbool(self.request.registry.settings['local_devel']):
                        if newsletter:
                            resource = '/'.join(
                                ('http://lima.malimedia.be.devel', 'ezine',
                                 brand, file))
                        else:
                            resource = os.path.join(s.mainpath, s.filename)
                    else:
                        resource = '/'.join(
                            ('http://lima.malimedia.be', 'ezine', brand, file))
                    log.debug('Resource is "{r}".'.format(r=resource))
                    ezine_url = f.upload(resource)

            # PREMAIL EZINE
            if s.todo['premail']:
                p = Premailer()
                #~ link_query_string = 'utm_source={s}&utm_medium=email'.format(s=s.email_name)
                data = p.premail(ezine_url)
                urlsdict = dict({
                    'htmlContent': data['documents']['html'],
                    'textContent': data['documents']['txt'],
                })
                t = Helper().read_url(urlsdict['htmlContent'])
                urlsdict['htmlContent'] = t.decode('utf-8').replace(
                    '%7B%7B', '{{').replace('%7D%7D', '}}')
                t = Helper().read_url(urlsdict['textContent'])
                urlsdict['textContent'] = t.decode('utf-8').replace(
                    '%7B%7B', '{{').replace('%7D%7D', '}}')
                # put in email_properties dict
                s.email_properties.update(urlsdict)

            # SAVE PREMAILED HTML
            if s.todo['save_premail_html']:
                ext = 'html'
                t = Helper().make_filename(file, ext)
                filepath = '/'.join((s.pre_html_path, t))
                with open(filepath, 'w') as f:
                    f.write(s.email_properties['htmlContent'])
                log.info('Premailed {t} saved in {p}'.format(t=ext,
                                                             p=filepath))

            # SAVE PREMAILED TXT
            if s.todo['save_premail_txt']:
                ext = 'txt'
                t = Helper().make_filename(file, 'txt')
                filepath = '/'.join((s.pre_txt_path, t))
                with open(filepath, 'w') as f:
                    f.write(s.email_properties['textContent'])
                log.info('Premailed {t} saved in {p}'.format(t=ext,
                                                             p=filepath))

            # SAVE PDF VERSION
            if s.todo['save_pdf']:
                c = Html2pdf()
                c.to_pdf(s.filepath, s.pdf_path)

            # CONNECT TO CLANG
            if s.todo['upsert'] or s.todo['send_test']:
                a = Api(s.wsdl, s._token)

            # UPSERT
            if s.todo['upsert']:
                # did we premail first or not (and in the latter case: we should have ezine.html_pre)
                if not s.todo['premail']:
                    s.email_properties['htmlContent'] = ezine.html_pre
                # make ezine object from htmlurl and texturl
                ezine = a.create_Emailobject_from_wsdl(s.email_properties)
                # put ezine in Clang
                # using "upsert" so we also need something to distinguish this object
                # ie., name & folder, id, ...
                response = a.email_upsert(ezine,
                                          name=s.email_properties['name'],
                                          folder=s.email_properties['folder'])

            # SEND TEST
            # TODO: alleen send test werkt niet (response?)
            if s.todo['send_test']:
                response = a.email_sendToGroup(response.msg.id,
                                               s.test_group_id)

        log.info('{n} terminated'.format(n='run.py'))

        try:
            n = pynotify.Notification('{n} terminated'.format(n='run.py'), '')
            n.show()
        except:
            pass