Beispiel #1
0
def join(request):
    dbsession = DBSession()
    userid = request.params.get('userid')
    user = dbsession.query(User).filter_by(userid=userid).first()
    password = request.params.get('password')
    confirm = request.params.get('confirm')
    fullname = request.params.get('fullname')
    about = request.params.get('about')
    if user:
        return {'app_url': request.application_url,
                'static_url': request.static_url,
                'message': "The userid %s already exists." % userid,
                'userid': userid,
                'fullname': fullname,
                'about': about}
    if confirm != password:
        return {'app_url': request.application_url,
                'static_url': request.static_url,
                'message': "The passwords don't match.",
                'userid': userid,
                'fullname': fullname,
                'about': about}
    if len(password) < 6:
        return {'app_url': request.application_url,
                'static_url': request.static_url,
                'message': "The password is too short. Minimum 6 characters.",
                'userid': userid,
                'fullname': fullname,
                'about': about}
    user = User(userid, password, fullname, about)
    dbsession.add(user)
    headers = remember(request, userid)
    return HTTPFound(location='/',
                     headers=headers)
Beispiel #2
0
def status_post(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).one()
    chirp = request.params.get('chirp')
    author = user
    timestamp = datetime.now()
    new_chirp = Signal(chirp, author, timestamp)
    dbsession.add(new_chirp)
    return HTTPFound(location='/status')
Beispiel #3
0
def status_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    #if userid is None:
    #    raise Forbidden()
    user = dbsession.query(User).filter_by(userid=userid).first()
    signals = dbsession.query(Signal).filter(Signal.author_id == userid)
    signals = signals.order_by(Signal.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'userid': userid,
            'user': user,
            'elapsed': get_elapsed,
            'user_chirps': False,
            'signals': signals.all()}
Beispiel #4
0
def signals_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    users = []
    if userid:
        users.append(user.id)
    signals = dbsession.query(Signal)
    results = []
    for k in range(8):
        start = datetime.now() - timedelta(k)
        end = datetime.now() - timedelta(k - 1)
        items = dbsession.query(Signal).filter(
            Signal.timestamp >= start, Signal.timestamp <= end)
        if len(items.all()) > 0:
            sigs = items.all()
            for sig in sigs:
                item = {}
                item['date'] = start.strftime("%d.%m.%Y")
                item['status'] = 'Warnung!'
                item['klass'] = 'warning'
                item['signal'] = sig.signal
                item['timestamp'] = sig.timestamp
        else:
            item = {}
            item['date'] = start.strftime("%d.%m.%Y")
            item['status'] = 'All systems go!'
            item['klass'] = 'success'
            item['signal'] = '24h Uptime'
            item['timestamp'] = start
        results.append(item)
    ordered_signals = signals.order_by(Signal.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'userid': userid,
            'user': user,
            'elapsed': get_elapsed,
            'user_chirps': False,
            'signals': ordered_signals.all(),
            'results': results}