コード例 #1
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def get_last_accessed(request):
    last_accessed = None
    try:
        if 'If-Modified-Since' in request.headers:
            last_accessed_str = request.headers.get('If-Modified-Since')
            try:
                last_accessed = utils.strToUTC(last_accessed_str)
            except Exception, e:
                request.registry['logger'].log(type='error',
                                               severity=LOG.ERROR,
                                               msg='Exception: %e' % str(e))
                last_accessed = 0
            # pop off tz adjustment (in seconds)
            if request.registry['logger']:
                ims_str = time.strftime('%a, %d %b %Y %H:%M:%S GMT',
                                        time.gmtime(last_accessed))
                request.registry['logger'].log(type='campaign',
                                               severity=LOG.DEBUG,
                                               msg='I-M-S: %s (%s)' %
                                                   (ims_str,
                                                       last_accessed_str),
                                               fields={})
    except Exception, e:
        settings = request.registry.settings
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        request.registry['logger'].log(type='error',
                                       severity=LOG.ERROR,
                                       msg='Exception: %s' % str(e))
コード例 #2
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def get_last_accessed(request):
    last_accessed = None
    try:
        if 'If-Modified-Since' in request.headers:
            last_accessed_str = request.headers.get('If-Modified-Since')
            try:
                last_accessed = utils.strToUTC(last_accessed_str)
            except Exception, e:
                request.registry['logger'].log(type='error',
                                               severity=LOG.ERROR,
                                               msg='Exception: %e' % str(e))
                last_accessed = 0
            # pop off tz adjustment (in seconds)
            if request.registry['logger']:
                ims_str = time.strftime('%a, %d %b %Y %H:%M:%S GMT',
                                        time.gmtime(last_accessed))
                request.registry['logger'].log(type='campaign',
                                               severity=LOG.DEBUG,
                                               msg='I-M-S: %s (%s)' %
                                               (ims_str, last_accessed_str),
                                               fields={})
    except Exception, e:
        settings = request.registry.settings
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        request.registry['logger'].log(type='error',
                                       severity=LOG.ERROR,
                                       msg='Exception: %s' % str(e))
コード例 #3
0
ファイル: sql.py プロジェクト: jrconlin/campaign_manager
 def health_check(self):
     if utils.strToBool(self.settings.get('db.skip_health', False)):
         return True
     try:
         healthy = True
         with self.engine.begin() as conn:
             test_id = "test" + os.urandom(5).encode("hex")
             ins = self.campaigns.insert().values(
                 id=test_id,
                 product="test",
                 channel="test",
                 platform="test",
                 start_time=0,
                 end_time=0,
                 note="test",
                 dest_url="test",
                 author="test",
                 created=0)
             conn.execute(ins)
             sel = self.campaigns.select(self.campaigns.c.id == test_id)
             resp = conn.execute(sel)
             rows = resp.fetchall()
             if not len(rows):
                 healthy = False
             conn.execute(self.campaigns.delete(self.campaigns.c.id ==
                                                test_id))
     except Exception, e:
         import warnings
         warnings.warn(str(e))
         return False
コード例 #4
0
ファイル: sql.py プロジェクト: jrconlin/campaign_manager
 def health_check(self):
     if utils.strToBool(self.settings.get('db.skip_health', False)):
         return True
     try:
         healthy = True
         with self.engine.begin() as conn:
             test_id = "test" + os.urandom(5).encode("hex")
             ins = self.campaigns.insert().values(id=test_id,
                                                  product="test",
                                                  channel="test",
                                                  platform="test",
                                                  start_time=0,
                                                  end_time=0,
                                                  note="test",
                                                  dest_url="test",
                                                  author="test",
                                                  created=0)
             conn.execute(ins)
             sel = self.campaigns.select(self.campaigns.c.id == test_id)
             resp = conn.execute(sel)
             rows = resp.fetchall()
             if not len(rows):
                 healthy = False
             conn.execute(
                 self.campaigns.delete(self.campaigns.c.id == test_id))
     except Exception, e:
         import warnings
         warnings.warn(str(e))
         return False
コード例 #5
0
ファイル: logger.py プロジェクト: jrconlin/campaign_manager
 def __init__(self, config, settings_file):
     global HEKA, BOTO
     settings = config.get_settings()
     self.loggername = settings.get('logging.name', 'campaign-manager')
     self.logger = logging.getLogger(self.loggername)
     self.logger.level = 1
     if HEKA and utils.strToBool(settings.get('logging.use_heka', "true")):
         self.heka = client_from_stream_config(open(settings_file, 'r'),
                                               'heka')
     else:
         HEKA = False
コード例 #6
0
ファイル: logger.py プロジェクト: jrconlin/campaign_manager
 def __init__(self, config, settings_file):
     global HEKA, BOTO
     settings = config.get_settings()
     self.loggername = settings.get('logging.name', 'campaign-manager')
     self.logger = logging.getLogger(self.loggername)
     self.logger.level = 1
     if HEKA and utils.strToBool(settings.get('logging.use_heka', "true")):
         self.heka = client_from_stream_config(
             open(settings_file, 'r'),
             'heka')
     else:
         HEKA = False
コード例 #7
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def login_page(request, error=None):
    session = request.session
    try:
        if 'javascript' in request.accept_encoding:
            # Don't display the login page for javascript requests.
            if not error:
                raise http.HTTPForbidden
            raise http.HTTPInternalServerError(str(error))
    except AttributeError:
        pass
    try:
        template = get_template('login')
        # use 'invalid@nowhere' to break persona looping on logout.
        response = Response(str(
            template.render(user=session.get('uid', 'invalid@nowhere'),
                            audience=request.environ.get('HTTP_HOST'))),
                            status=403)
        if (session.get('uid')):
            del (session['uid'])
        try:
            session.persist()
            session.save()
        except AttributeError:
            pass  # because testing
        return response
    except Exception, e:
        settings = request.registry.settings
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        request.registry['logger'].log(str(e),
                                       type='error',
                                       severity=LOG.ERROR)
        raise http.HTTPServerError
コード例 #8
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def login_page(request, error=None):
    session = request.session
    try:
        if 'javascript' in request.accept_encoding:
            # Don't display the login page for javascript requests.
            if not error:
                raise http.HTTPForbidden
            raise http.HTTPInternalServerError(str(error))
    except AttributeError:
        pass
    try:
        template = get_template('login')
        # use 'invalid@nowhere' to break persona looping on logout.
        response = Response(str(template.render(
            user=session.get('uid', 'invalid@nowhere'),
            audience=request.environ.get('HTTP_HOST'))),
            status=403)
        if (session.get('uid')):
            del(session['uid'])
        try:
            session.persist()
            session.save()
        except AttributeError:
            pass  # because testing
        return response
    except Exception, e:
        settings = request.registry.settings
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        request.registry['logger'].log(str(e), type='error',
                                       severity=LOG.ERROR)
        raise http.HTTPServerError
コード例 #9
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def admin_page(request, error=None):
    if utils.strToBool(
            request.registry.settings.get('auth.block_authoring', False)):
        raise http.HTTPNotFound()
    auth = authorizedOnly(None)
    if not auth.login(request):
        return login_page(request)
    tdata = get_all_announcements(request)
    tdata['author'] = request.session['uid']
    tdata['error'] = error
    tdata['settings'] = request.registry.settings
    try:
        if 'javascript' in request.accept_encoding:
            if not error:
                raise http.HTTPOk
            raise http.HTTPConflict(json.dumps(error))
    except AttributeError:
        pass
    template = get_template('main')
    content_type = 'text/html'
    reply = template.render(**tdata)
    response = Response(reply, content_type=content_type)
    return response
コード例 #10
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def admin_page(request, error=None):
    if utils.strToBool(request.registry.settings.get('auth.block_authoring',
                                                     False)):
        raise http.HTTPNotFound()
    auth = authorizedOnly(None)
    if not auth.login(request):
        return login_page(request)
    tdata = get_all_announcements(request)
    tdata['author'] = request.session['uid']
    tdata['error'] = error
    tdata['settings'] = request.registry.settings
    try:
        if 'javascript' in request.accept_encoding:
            if not error:
                raise http.HTTPOk
            raise http.HTTPConflict(json.dumps(error))
    except AttributeError:
        pass
    template = get_template('main')
    content_type = 'text/html'
    reply = template.render(**tdata)
    response = Response(reply, content_type=content_type)
    return response
コード例 #11
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def manage_announce(request):
    args = request.params.copy()
    args.update(request.matchdict)
    if utils.strToBool(
            request.registry.settings.get('auth.block_authoring', False)):
        raise http.HTTPNotFound()
    # Clean up the login info
    try:
        del args['assertion']
        del args['audience']
    except KeyError:
        pass
    storage = request.registry.get('storage')
    settings = request.registry.settings
    session = request.session
    err = None
    if 'delete' in args or 'delete[]' in args:
        try:
            del_announce(request)
        except http.HTTPOk:
            pass
        except http.HTTPNotFound, e:
            pass
        return admin_page(request)
コード例 #12
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
def manage_announce(request):
    args = request.params.copy()
    args.update(request.matchdict)
    if utils.strToBool(request.registry.settings.get('auth.block_authoring',
                                                     False)):
        raise http.HTTPNotFound()
    # Clean up the login info
    try:
        del args['assertion']
        del args['audience']
    except KeyError:
        pass
    storage = request.registry.get('storage')
    settings = request.registry.settings
    session = request.session
    err = None
    if 'delete' in args or 'delete[]' in args:
        try:
            del_announce(request)
        except http.HTTPOk:
            pass
        except http.HTTPNotFound, e:
            pass
        return admin_page(request)
コード例 #13
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
    err = None
    if 'delete' in args or 'delete[]' in args:
        try:
            del_announce(request)
        except http.HTTPOk:
            pass
        except http.HTTPNotFound, e:
            pass
        return admin_page(request)
    try:
        if args is not None and len(args) > 0:
            if not args.get('author'):
                args['author'] = session.get('uid')
            storage.put_announce(args)
    except Exception, e:
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        # display error page.
        err = {'code': 1, 'error': str(e)}
        pass
    return admin_page(request, err)


@author.delete()
@authorizedOnly
def del_announce(request):
    storage = request.registry.get('storage')
コード例 #14
0
ファイル: views.py プロジェクト: jrconlin/campaign_manager
    err = None
    if 'delete' in args or 'delete[]' in args:
        try:
            del_announce(request)
        except http.HTTPOk:
            pass
        except http.HTTPNotFound, e:
            pass
        return admin_page(request)
    try:
        if args is not None and len(args) > 0:
            if not args.get('author'):
                args['author'] = session.get('uid')
            storage.put_announce(args)
    except Exception, e:
        if utils.strToBool(settings.get('dbg.traceback', False)):
            import traceback
            traceback.print_exc()
        if utils.strToBool(settings.get('dbg.break_unknown_exception', False)):
            import pdb
            pdb.set_trace()
        # display error page.
        err = {'code': 1,
               'error': str(e)}
        pass
    return admin_page(request, err)


@author.delete()
@authorizedOnly
def del_announce(request):