예제 #1
0
def getforgotform():
    innards = common.idbox() + html.br() + common.submitbutton('Submit')

    return \
        html.bold('Reset:') + html.br() + \
        html.markup('form', \
            attrs={'method': 'POST', 'action': urls.FORGOT_PASSWORD__URL}, \
            innards=innards)
예제 #2
0
def startpage(isloggedin, user):
    title = html.markup('title', innards='Let\'s be more aware!')
    meta=\
        html.markup('meta', {
            'name':'viewport',
            'content':
                'width=device-width, ' + \
                'initial-scale=1.0, ' + \
                'maximum-scale=1.0, ' + \
                'target-densitydpi=medium-dpi, ' + \
                'user-scalable=0'
        }, closetag=False)
    link=\
        html.markup('link', {
            'rel': 'stylesheet',
            'type': 'text/css',
            'href': '/style.css'}, closetag=False)

    return \
        '<!DOCTYPE html>' + \
        html.openelem('html') + \
        html.markup('head', innards=(title + meta) + link) + \
        html.openelem('body') + \
        html.markup('script', { 'src' : 'doT.js' }) + \
        html.markup('script', { 'src' : 'jquery-2.0.3.js' }) + \
        html.markup('script', { 'src' : 'beeaware.js' }) + \
        str(navbar(isloggedin, user)) + \
        ("" if not isloggedin else html.div(_MOODBAR_ID, moodbar()))
예제 #3
0
def getloginform():
    innards = comn.idbox() + comn.passbox() + comn.warningstr() + html.br() + \
        comn.submitbutton('Log In')

    return \
        html.bold('Log in:') + html.br() + \
        html.markup('form', \
            attrs={'method': 'POST', 'action': urls.LOGIN__URL}, \
            innards=innards) + html.br() + \
        html.hyperlink(urls.FORGOT_PASSWORD__URL, 'forgot password')
예제 #4
0
def submitbutton(val, btnid='', disabled=False):
    attrs = {
        'type': 'submit',
        'value': val,
        'class': 'relbutton',
        'id': ca.SUBMIT
    }
    if disabled:
        attrs.update({'disabled': 'disabled'})
    if btnid != '': attrs['id'] = btnid
    return \
        html.markup('label', attrs={'for': ca.SUBMIT}, innards='&nbsp;') + \
        html.voidelem('input', attrs)
예제 #5
0
def getcreateform(require_invite, invite_tok):
    innards = \
        comn.idbox() + comn.passbox() + comn.warningstr() + html.br() + \
        comn.submitbutton('Create')

    querystr = '' if not require_invite else urllib.urlencode(
        {create_atom.INVITE_TOKEN: invite_tok})

    action = urls.ACCOUNT_CREATE__URL + '?' + querystr

    return html.bold('Create Account:') + html.br() + \
        html.markup('form', \
            attrs = {'method': 'POST', 'action': action}, \
            innards = innards)
예제 #6
0
def getresetform(reset_token):
    innards = comn.passbox() + comn.warningstr() + html.br() + \
        comn.submitbutton('Set Password')

    url = urls.RESET_PASSWORD__URL
    query = urllib.urlencode(
        {pages.reset_password_atom.RESET_TOKEN: reset_token})

    return \
        html.bold('Set Password:'******'form', \
            attrs={
                'method': 'POST',
                'action': url + '?' + query
            }, \
            innards=innards) + html.br()
예제 #7
0
def navbar(isloggedin, userscreenname):
    ret = ''

    ret += html.markup('div', {
        'id': 'notification',
        'display': 'none'
    }, html.hyperlink(urls.MESSAGES__URL, 'New Message'))

    if isloggedin:
        ret += \
            'welcome ' + \
            hyperlink_to_profile(None, userscreenname) + \
            ', when done ' + \
            html.hyperlink(urls.LOGOUT__URL, 'sign off') + \
            html.br()
    else:
        ret += 'Welcome to Beeaware! Please [ ' + \
            html.hyperlink(urls.LOGIN__URL, 'log in') + ' ] '

    linkdelim = ' | '

    #        html.hyperlink(urls.LOCATION__URL + '?' + \
    #            location_atom.DISPLAY, 'location') + linkdelim + \
    if isloggedin:
        ret += \
            html.hyperlink(urls.MESSAGES__URL, 'messages') + \
                linkdelim + \
            html.hyperlink(urls.RELATIONSHIPS__URL, 'people') + \
                linkdelim + \
            html.hyperlink(urls.VISIT_HISTORY_ROLLUP__URL, 'places') + \
                linkdelim + \
            html.hyperlink(urls.TOKENS__URL, 'wordle')
    else:
        if not auth.require_invite:
            ret += linkdelim + \
                html.hyperlink(urls.ACCOUNT_CREATE__URL, 'create account')

    return html.div(_NAVBANNER_ID, ret)
예제 #8
0
def get_location_gen(usrid, view, time, length, display):
    displaydefined = display is not None
    accuracythresh = '500'
    epoch = datetime.utcfromtimestamp(0)
    now = datetime.utcnow()
    nowdelta = now - epoch
    onedayms = 1000 * 60 * 60 * 24
    deltanum = onedayms
    if length and length.isdigit(): deltanum = long(length)
    rangedelta = timedelta(milliseconds=deltanum)
    yesterdaydelta = nowdelta - rangedelta
    seconds = yesterdaydelta.seconds
    seconds += yesterdaydelta.days * 24 * 60 * 60
    millis = seconds * 1000
    time = str(millis) if time is None else time

    begtimestr = ''
    endtimestr = ''
    timephrase = ''
    timenum = 0 if time is None or time == 'all' else long(time)
    view = view if view else view

    if not time is None and time.isdigit():
        delta = timedelta(milliseconds=timenum)

        begtimestr = str(delta + epoch)
        endtimestr = str(delta + epoch + rangedelta)

        timephrase = \
            '''and (time > '%(b)s' and time < '%(e)s')''' % \
                { 'b':begtimestr, 'e':endtimestr }

    selectphrase = 'loc.sess_id, latitude, longitude, altitude, accuracy, time'
    orderphrase = 'order by time asc'

    query = \
        ''' select ''' + \
        selectphrase + \
        '''
        from location as loc
        join _user_session as us on us.sess_id = loc.sess_id
        join _user as u on u.u_id = us.u_id
        where u.u_id = %(usrid)s and accuracy < ''' + \
            accuracythresh + ' ' + \
            timephrase + ' ' + \
            orderphrase

    filterquery = \
    '''with filter as (''' + query + ''')
    select distinct on (latitude, longitude)
    latitude, longitude from filter'''

    cur = db.sendtodb(filterquery if view == 'latlon' else query,
                      {'usrid': usrid})

    if displaydefined:

        yield \
            html.hyperlink(urls.PLACES__URL, 'My Places') + ' | ' + \
            html.br() + html.br()

        if time != None:
            lastframe = \
                html.urlencode(urls.LOCATION__URL,
                {
                    loc_atom.DISPLAY : '',
                    loc_atom.TIME : str(timenum - deltanum),
                    loc_atom.LEN : length,
                    loc_atom.EXPORT : view
                })

            nextframe = \
                html.urlencode(urls.LOCATION__URL,
                {
                    loc_atom.DISPLAY : '',
                    loc_atom.TIME : str(timenum + deltanum),
                    loc_atom.LEN : length,
                    loc_atom.EXPORT : view
                })

            yield \
                '[' + html.hyperlink(lastframe, '<<<') +  '] ' + \
                begtimestr + ' - ' + endtimestr + \
                ' [' + html.hyperlink(nextframe , '>>>') + ']' + html.br()

        viewframe = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.TIME : time,
                loc_atom.LEN : length,
                loc_atom.DISPLAY : ''
            })

        viewcsvframe = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.EXPORT : 'csv',
                loc_atom.TIME : time,
                loc_atom.LEN : length,
                loc_atom.DISPLAY : ''
            })

        viewlatlonframe = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.EXPORT : 'latlon',
                loc_atom.TIME : time,
                loc_atom.LEN : length,
                loc_atom.DISPLAY : ''
            })

        downloadcsvframe = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.EXPORT : 'csv',
                loc_atom.TIME : time,
                loc_atom.LEN : length,
            })

        downloadlatlonframe = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.EXPORT : 'latlon',
                loc_atom.TIME : time,
                loc_atom.LEN : length,
            })

        downloadcsvall = \
            html.urlencode(urls.LOCATION__URL,
            {
                loc_atom.EXPORT : 'csv',
                loc_atom.TIME : 'all'
            })

        links = [
            html.hyperlink(viewframe, 'view frame'),
            html.hyperlink(viewlatlonframe, 'view frame latlon'),
            html.hyperlink(viewcsvframe, 'view frame csv'),
            html.hyperlink(downloadcsvframe, 'download frame csv'),
            html.hyperlink(downloadlatlonframe, 'download frame latlon'),
            html.hyperlink(downloadcsvall, 'download all csv')
        ]

        yield " | ".join(links) + html.br() + html.br()

        if view == 'csv' or view == 'latlon':
            timepair = \
                { loc_atom.TIME : str(timenum) } if timenum else {}
            lenpair = \
                { loc_atom.LEN : deltanum } if length else {}

            exporturl = html.urlencode(
                urls.LOCATION__URL,
                dict(timepair.items() + lenpair.items() +
                     {loc_atom.EXPORT: view}.items()))

            if displaydefined:
                yield '<pre>'

    if view == 'csv':
        yield 'sess,time,lat,lon,alt,acc\n'

    for row in cur:
        if view == 'csv':
            time = str(row['time'])
            sess = str(row['sess_id'])
            lat = str(row['latitude'])
            lon = str(row['longitude'])
            alt = str(row['altitude'])
            acc = str(row['accuracy'])
            yield sess + ',' + time + ',' + lat + ',' + lon + ',' + alt + \
                ',' + acc + '\n'
        elif view == 'latlon':
            lat = str(row['latitude'])
            lon = str(row['longitude'])
            yield lat + ',' + lon + '\n'
        else:
            time = str(row['time'])
            sess = str(row['sess_id'])
            lat = str(row['latitude'])
            lon = str(row['longitude'])
            alt = str(row['altitude'])
            acc = str(row['accuracy'])

            maplink = html.hyperlink(
                html.urlencode('http://maps.google.com/maps',
                               {'q': lat + ',' + lon}), 'map')

            revlookuplink = html.hyperlink(
                html.urlencode(
                    'http://nominatim.openstreetmap.org/reverse', {
                        'format': 'json',
                        'lat': lat,
                        'lon': lon,
                        'zoom': '18',
                        'addressdetails': '1'
                    }), 'lookup')

            markurl = html.urlencode(
                urls.PLACES__URL, {
                    loc_atom.ORIGIN: urls.LOCATION__URL,
                    loc_atom.LATITUDE: lat,
                    loc_atom.LONGITUDE: lon
                })

            markform = \
                html.markup('form', {
                    'action' : markurl,
                    'method' : 'post',
                    'style' : 'display:inline'},
                    comn.submitbutton('Mark'))

            yield \
                time + ': ' + \
                lat + ', ' + lon + \
                ' [' + maplink + '] | ' + \
                '[' + revlookuplink + '] ' + \
                html.br()

    if displaydefined and (view == 'csv' or view == 'latlon'):
        yield '</pre>'
예제 #9
0
def footer(isloggedin):
    location_push_control_buttons=\
        html.markup('button', {
            'id': _CONTROL_TRACKING_BUTTON_ID ,
            'onclick': 'trackingClicked()',
            'type': 'button' })

    location_samplepush_div = html.div(
        _SAMPLE_PUSH_CONTROL_ID, location_push_control_buttons +
        html.div(_LOCATION_ID, '')) if isloggedin else ''

    location_settings_div = html.div(
        _LOCATION_SETTINGS_ID,
        html.hyperlink(urls.LOCATION_RECORDER__URL, 'Beacon Setup'))

    ret='<div style="clear:both"></div> ' + \
        html.div(_FOOTER_ID,
            location_settings_div + \
            html.div(_TOU_ID, html.hyperlink(urls.TOU__URL, 'Terms of Use')))

    if isloggedin:
        ret += html.script('''

        latestLocation=null;

        function createCookie(name,value,days) {
            if (days) {
                var date=new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires="; expires="+date.toGMTString();
            }
            else var expires="";
            document.cookie=name+"="+value+expires+"; path=/";
        }

        function readCookie(name) {
            var nameEQ=name + "=";
            var ca=document.cookie.split(';');
            for(var i=0;i < ca.length;i++) {
                var c=ca[i];
                while (c.charAt(0)==' ') c=c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) {
                    return c.substring(nameEQ.length,c.length);
                }
            }
            return null;
        }

        function eraseCookie(name) {
            createCookie(name,"",-1);
        }

        trackingLocation=readCookie('trackingLocation') === 'true';

        function samplePositionSuccessHandler(location) {
            latestLocation=location;
            updateFooterSampleLocation(location);
        }

        function doNavPush() {
            trackingLocation = 'true';
            if(trackingLocation) {
                if(latestLocation != null) {
                    var location=latestLocation;
                    var url="''' + urls.LOCATION__URL + '''";
                    var params =
                        "''' + location_atom.LATITUDE + \
                             '''=" + location.coords.latitude +
                        "&''' + location_atom.LONGITUDE + \
                             '''=" + location.coords.longitude +
                        "&''' + location_atom.ALTITUDE + \
                             '''=" + location.coords.altitude +
                        "&''' + location_atom.ACCURACY + \
                             '''=" + location.coords.accuracy

                    $.post(url, params, function() {});

                    //console.log(url);
                    //console.log(params);
                }
            }
        }

        function samplePositionErrorHandler(error) {

            latestLocation=null;

            var div=$("#''' + _LOCATION_ID + '''");
            div.html("Cannot determine location. " +
                "Location features will not work.");
        }

        function doNavSample() {
            trackingLocation = 'true';
            if(trackingLocation) {
                navigator.geolocation.getCurrentPosition(
                    samplePositionSuccessHandler,
                    samplePositionErrorHandler,
                    { enableHighAccuracy:true });
            } else {
                var div=$("#''' + _LOCATION_ID + '''")
                div.html("Location Tracking Disabled.");
            }
        }

        function updateFooterSampleLocation(location) {
            var div=$("#''' + _LOCATION_ID + '''");
            div.html(
                "Position: " +
                    location.coords.latitude.toFixed(7) + ", " +
                    location.coords.longitude.toFixed(7) + ", " +
                " (+/-" + location.coords.accuracy.toFixed(2) + "m)"
            );
        }

        function doTrackingLoop() {
            doNavSample();
            doNavPush();
            setTimeout(doTrackingLoop, 60000);
        }

        function setTrackingButton() {
            trackingButton=
                $("#''' + _CONTROL_TRACKING_BUTTON_ID + '''");

            text=trackingLocation ? 'Disable' : 'Enable';
            text += ' Tracking';
            trackingButton.html(text);

            if(!trackingLocation) {
                latestLocation=null;
            }
        }

        function trackingClicked() {
            trackingLocation=!trackingLocation;
            expirationDays=1000;
            createCookie('trackingLocation', trackingLocation, expirationDays);
            setTrackingButton();
            doNavSample();
            doNavPush();
        }

        setTrackingButton();

        doTrackingLoop();

        ''')
    return ret
예제 #10
0
    def linkfun(moodtypeid, imgfn):        return \
html.hyperlink(urls.MOOD_FORM__URL + query + moodtypeid,
        html.markup('img', { 'src':imgfn, 'width':'48', 'height':'48'}))

    cur = sys_data.do_get_sys_mood_types()
예제 #11
0
def passbox():
    return \
        html.markup('label', attrs={'for': ca.PASS}, innards='Password:'******'input', attrs={ \
            'id': ca.PASS, 'name': ca.PASS, 'type':'password'}) + \
        html.br()
예제 #12
0
def idbox():
    return \
        html.markup('label', attrs={'for': ca.USER}, innards='Name:') + \
        html.voidelem('input', attrs={ \
            'id': ca.USER, 'name': ca.USER, 'type':'text'}) + \
        html.br()