Example #1
0
    def GET(self, username):
        # auth?

        try:
            users = model.Users(username=username)
            user = users.list()[0]
        except:
            context = Storage(title=_("No such user"))
            print render.collections(context, [])
            return

        topics_subs = model.Projects(by_user_role=(user, "subscribed"))
        #        topics_subs.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE)
        #        topics_subs.annotate_by_points()
        #        topics_subs.annotate_by_comments()

        topics_highlighted = model.Projects(
            tags=model.Tags("official:highlighted"))
        #        topics_highlighted.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE)
        #        topics_highlighted.annotate_by_latest_points()
        #        topics_highlighted.annotate_by_comments()

        topics_subs.add(topics_highlighted)
        topics_subs.sort_by_title()

        context = Storage(title=_("User") + " " + username, )
        web.header("content-type", feed_content_type['atomserv'])
        print render.collections(context, topics_subs)
Example #2
0
    def GET(self, topic_id):
        topics, topic = model.t_helper(topic_id)

        webinput = web.input()

        context = Storage(
            title=_(self.title),
            widgetizer_link=pc_links(self.widgetizer_link, topic_id),
            help_link=pc_links('guide', 'help_' + self.widget_link),
        )
        form = self.get_form(topic=topic)

        if not webinput.has_key("from_widget") or not form.validates():
            get_page("widgetize", context, topic, form)
        else:
            #d = Storage()
            #for k in form.d:
            #    if form.d[k]:
            #        d[k] = form.d[k]
            widget_link = widget_links(self.widget_link, topic.id, **form.d)
            result = Storage(
                link=widget_link,
                link_len=len(widget_link),
                height=form.d.height,
                width=form.d.width,
            )
            result.id = form.d.get("id", "")
            get_page("widgetize", context, topic, form, result=result)
Example #3
0
def nav_data(**links):
    return [
        #    Storage(key='add', label=_('label_Add'), link=links['add']),
        Storage(key='loc', label=_('label_Place'), link=links['loc']),
        #    Storage(key='hom', label=_('label_Home'), link=links['hom']),
        Storage(key='sea', label=_('label_Search'), link=links['sea']),
        Storage(key='inf', label=_('label_Info'), link=links['inf']),
    ]
Example #4
0
    def GET(self):

        i = web.input(topic_hint=None)

        user = get_user()
        if user is None:
            Login().GET(webinput=Storage(come_back=links.add_point))
            return

        user_loc = user_location()
        if not user_loc[0]:
            MobileMap().GET()
            return

        context = Storage(
            title=_("List of points"),
            status=Storage(
                add="add",
                loc=location_indicator(),  # !!! define better later
                hom="home",
                sea="search",
                inf="info",
            ),
        )

        page_nav_data = Storage(nav_data=nav_data(
            add=None,
            loc=links.place,
            hom=links.home,
            sea=links.search,
            inf=links.info,
        ), )

        context.page_nav_data = page_nav_data

        topics_subs = model.Projects(by_user_role=(user, "subscribed"))

        topics_highlighted = model.Projects(
            tags=model.Tags("official:highlighted"))

        topics_subs.add(topics_highlighted)

        topics_subs.annotate_by_profiles()
        topics_subs.filter_by_func(acl.authorize.add_point)

        topics_subs.sort_by_title()

        get_page('add_point', context, topics_subs)
Example #5
0
    def GET(self):
        try:
            cfg_locals = {}
            execfile(LOCAL_CONFIG_FILE_NAME, globals(), cfg_locals)  # local config overrides
        except IOError:
            print LOCAL_CONFIG_FILE_NAME ," not found"
        except:
            raise
            print "ERROR reading config"

        missing_prereqs = check_prereqs()

        if missing_prereqs:
            print "Please install missing software first:"
            print ", ".join(missing_prereqs)
            return

        if "db_parameters" not in cfg_locals:
            form = setup_db_form()
            context = Storage(title=_("Setting database"),
                          description=_("Enter some values to start with the database setup"))
            get_page("setupdb", context, form)
            return

        if "autoconfigured" in cfg_locals:
            print "Already autoconfigured. Edit ", LOCAL_CONFIG_FILE_NAME

        print "This instance seems to be configured. Revise ", LOCAL_CONFIG_FILE_NAME
Example #6
0
def db_execute(path, sql, args=None):
    db = sqlite3.connect(path)
    cursorobj = db.cursor()
    kv_result = []
    try:
        print(sql)
        if args is None:
            cursorobj.execute(sql)
        else:
            cursorobj.execute(sql, args)
        result = cursorobj.fetchall()
        # result.rowcount
        db.commit()
        for single in result:
            resultMap = Storage()
            for i, desc in enumerate(cursorobj.description):
                name = desc[0]
                resultMap[name] = single[i]
            kv_result.append(resultMap)

    except Exception as e:
        raise e
    finally:
        db.close()
    return kv_result
Example #7
0
def get_widget(template_name, context, *args, **kwargs):
    context = context or Storage()
    #    if not context.has_key("user"):
    #        context.setdefault("user", get_user())
    if not context.has_key("feeds"):
        context.setdefault("feeds", [])
    context.setdefault("widget", True)
    context.setdefault("linktarget",
                       ' target="_top" ')  # optional link targets
    context.setdefault("lnktgt", ' target="_top" ')  # all links have this

    context.setdefault("onlycode", False)
    context.setdefault("title", '')
    context.setdefault("page_specific_js", '')
    context.setdefault("page_specific_styles", styles.get(template_name, []))
    context.setdefault("nocache", True)
    context.setdefault("debug", config.debug_mode)
    context.setdefault("message", web.input().get('message', ''))
    try:
        page = getattr(widget_render, template_name)
    except:
        page = getattr(widget_render, "old_" + template_name)

    if context.onlycode:  # for internal inline HTML widget no base needed
        return page(context, cache=config.cache, *args, **kwargs)

    print widget_render.base(page(context, cache=config.cache, *args,
                                  **kwargs),
                             context,
                             cache=config.cache)
Example #8
0
    def post(self):
        username = self.get_argument('username', '')
        password_hashed = hashlib.sha1(self.get_argument('password',
                                                         '')).hexdigest()

        f = login_form()
        user = User.one({
            'username': username,
            'password_hashed': password_hashed
        })
        f.add_notnull_validator(
            user, "The username or password you entered is incorrect")

        next = self.get_argument('next', '/dashboard')
        if f.validates(Storage(self.get_arguments())):
            if user.status != 'active':
                self.set_flash(
                    self.
                    _("Your login has been disabled/deleted. Please contact admin."
                      ))
                self.redirect("/")
                return

            expire = 14 if self.get_argument('rememberme', None) else None
            self.set_secure_cookie("username", username, expire)

            from datetime import datetime
            user.last_login = datetime.now()
            user.save()
            self.redirect(next)
        else:
            self.render("login-form", f=f, next=next)
Example #9
0
    def GET(self, topic_id, onlycode=False, webinput=None):
        presets = webinput or web.input()
        try:
            presets.referer = web.ctx.environ["HTTP_REFERER"]
        except KeyError:
            presets.referer = 0

        ### compat only !!! remove 
        if "disabled_text" not in presets:
            presets.disabled_text = _("Point addition disabled.")
        ###

        context = Storage(
            presets=presets,
            offset = 14,
            framed = 0,
            onlycode=onlycode,
            title=presets.get("title", _("Add point")),
            desturl=pc_links("topic_newpoint", int(topic_id), **presets),
            submitform=pc_links("topic_newpoint", int(topic_id)),
        )

        topics, topic = model.t_helper(topic_id)

        if onlycode:
            presets.referer = ''
            return get_widget('submit', context, topic, presets)

        get_widget('submit', context, topic, presets)
Example #10
0
    def GET(self, topic_id, onlycode=False, webinput=None):

        presets = webinput or web.input()
        try:
            presets.referer = web.ctx.environ["HTTP_REFERER"]
        except KeyError:
            presets.referer = 0

        context = Storage(
            presets=presets,
            offset = 10,
            framed = 1,
            onlycode=onlycode,
            title=presets.get("title", _("Links")),
            desturl=pc_links("topic", int(topic_id), **presets),
        )

        topics, topic = model.t_helper(topic_id)

        topics.annotate_by_datasources()
        topics.annotate_by_points()

        number_of_points = int(presets.get("number_of_links",
            config.links_per_page))

        if onlycode:
            presets.referer = ''
            return get_widget('topic_links', context, presets, topic)

        get_widget('topic_links', context, presets, topic)
Example #11
0
def mobile_get_page(template_name, context, *args, **kwargs):
    context = context or Storage()
    if not context.has_key("user"):
        context.setdefault("user", get_user())

    context.setdefault("widget", False)
    context.setdefault("linktarget", '')
    context.setdefault("lnktgt", '')  # all links have this

    context.setdefault("disallow_robots", config.disallow_robots)

    context.setdefault("title", '')
    context.setdefault("page_specific_js", '')
    context.setdefault("page_specific_styles", styles.get(template_name, []))
    context.setdefault("nocache", True)
    context.setdefault("debug", config.debug_mode)
    context.setdefault("message", web.input().get('message', ''))
    try:
        page = getattr(mobile_render, template_name)
    except:
        raise
        page = getattr(mobile_render, "old_" + template_name)
    print mobile_render.base(page(context, cache=config.cache, *args,
                                  **kwargs),
                             context,
                             cache=config.cache)
Example #12
0
def parse_json_obj(obj):
    if isinstance(obj, dict):
        return Storage(obj)
    if isinstance(obj, list):
        for i in range(len(obj)):
            obj[i] = parse_json_obj(obj[i])
    return obj
Example #13
0
    def GET(self, format, topic_id):

        i = web.input(order="", search="", search_tags="", ol="")

        topics, topic = model.t_helper(topic_id)
        if not topics:
            # web.seeother(links("index", message=_("No such topic. Update your bookmarks.")))
            # ???
            return

        points = model.search_helper(i, topic)
        model.order_helper(points, i.order)

        points.annotate_by_comments()
        points.annotate_by_tags()
        points.annotate_by_profiles(default=DEFAULT_POINT_PROFILE)

        context = Storage(title=_("Topic points"), )

        points.last_activity()

        get_feed_helper(
            context,
            points,
            summary=lambda p: p.comments.list()[0].text,
            link=lambda p: pc_links('point', topic.id, p.id),
            format=format,
            with_content=(not i.ol),
        )
Example #14
0
 def GET(self):
     i = web.input(lat=None,
                   lon=None,
                   zoom=None,
                   mapx=200,
                   mapy=200,
                   draft="0",
                   marker="1")
     if i.lat and i.lon:
         point = Storage(lat=float(i.lat), lon=float(i.lon))
         model.encode_coordinates(point)
     i.zoom = float(i.zoom
                    or (config.mobile_zoom + config.getmap_zoomshift))
     if config.getmap_custom_wms == "wms":
         mobile_map.serve_map_repr(
             point,
             zoom=int(i.zoom),
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             marker=(i.marker == "1")
             and config.static_dir + '/img/cross-hair.png' or None,
             draft=int(i.draft),
         )
     else:
         mobile_map.serve_osm_map(
             point,
             zoom=int(i.zoom),
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             marker=(i.marker == "1")
             and config.static_dir + '/img/cross-hair.png' or None,
             draft=int(i.draft),
         )
Example #15
0
 def GET(self):
     i = web.input(repr_lat=None,
                   repr_lon=None,
                   zoom=None,
                   mapx=300,
                   mapy=300,
                   draft="0")
     if i.repr_lat and i.repr_lon:
         point = Storage(repr_lat=float(i.repr_lat),
                         repr_lon=float(i.repr_lon))
         model.decode_coordinates(point)
     i.zoom = float(i.zoom
                    or (config.mobile_zoom + config.getmap_zoomshift))
     if config.getmap_custom_wms == "wms":
         mobile_map.serve_map_repr(
             point,
             zoom=int(i.zoom),
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             #    marker='static/pc_files/img/icons/point_medium.png'
             draft=int(i.draft),
         )
     else:
         mobile_map.serve_osm_map(
             point,
             zoom=int(i.zoom),
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             marker=config.static_dir + '/img/cross-hair.png',
             draft=int(i.draft),
         )
Example #16
0
 def GET(self):
     i = web.input(lat=None,
                   lon=None,
                   zoom=None,
                   mapx=300,
                   mapy=300,
                   draft="0")
     if i.lat and i.lon:
         point = Storage(lat=float(i.lat), lon=float(i.lon))
         model.encode_coordinates(point)
     i.zoom = float(i.zoom
                    or (config.mobile_zoom + config.getmap_zoomshift))
     if config.getmap_custom_wms == "wms":
         mobile_map.serve_map(
             point,
             zoom=i.zoom,
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             #    marker='static/pc_files/img/icons/point_medium.png'
             draft=int(i.draft),
         )
     else:
         # osm
         mobile_map.serve_osm_map(
             point,
             zoom=int(i.zoom),
             mapx=int(i.mapx),
             mapy=int(i.mapy),
             #    marker='static/pc_files/img/icons/point_medium.png'
             draft=int(i.draft),
         )
Example #17
0
    def GET(self, format):
        i = web.input(order="", search="", search_tags="", ol="")

        user = get_user()

        points = model.search_helper(i)
        model.order_helper(points, i.order)

        points.annotate_by_comments()
        points.annotate_by_projects()
        points.annotate_by_tags()

        context = Storage(title=_("Search for '%s'") % i.search, )

        points.last_activity()

        if format != 'json':
            get_feed_helper(
                context,
                points,
                summary=lambda p: p.comments.list()[0].text,
                link=lambda p: pc_links('point', p.first_project.id, p.id),
                format=format,
                with_content=(not i.ol))
            return
        else:
            import simplejson_encoder
            print simplejson_encoder.JSONEncoder(indent=2).encode(
                json_structure(points))
            return
Example #18
0
    def GET(self, onlycode=False, webinput=None):
        presets = webinput or web.input()
        try:
            presets.referer = web.ctx.environ["HTTP_REFERER"]
        except KeyError:
            presets.referer = 0
        context = Storage(
            presets=presets,
            offset = 14,
            framed = 0,
            onlycode=onlycode,
            title=presets.get("title", _("Add point")),
        )

        widget_urls = []
        for n in range(MAX_NUMBER_OF_ITEMS_IN_CONTAINER):
            urln = "u%i" % n
            if urln in presets:
                widget_urls.append(presets[urln])

        if onlycode:
            presets.referer = ''
            return get_widget('container', context, presets, widget_urls)

        get_widget('container', context, presets, widget_urls)
Example #19
0
    def GET(self, c_lat, c_lon, zoom, map_width, map_height):
        x = int(int(map_width) / 2)
        y = int(int(map_height) / 2)
        for k in web.input():
            if "," in k:
                x, y = map(int, k.split(","))

        # !!! refactor
        if config.getmap_custom_wms == "wms":
            lat, lon = mobile_map.click_coord_hybrid(x,
                                                     y,
                                                     c_lat=float(c_lat),
                                                     c_lon=float(c_lon),
                                                     zoom=float(zoom),
                                                     mapx=int(map_width),
                                                     mapy=int(map_height))
        else:
            lat, lon = mobile_map.click_coord_hybrid_osm(x,
                                                         y,
                                                         c_lat=float(c_lat),
                                                         c_lon=float(c_lon),
                                                         zoom=float(zoom),
                                                         mapx=int(map_width),
                                                         mapy=int(map_height))

        MobileMap().GET(
            webinput=Storage(lat=str(lat), lon=str(lon), zoom=str(zoom)))
Example #20
0
def autologin(i):
    if i.get("username", None) and i.get("password", None):
        credentials = Storage(username=i.username, password=i.password)

        user = userbase.authenticate(credentials)
        if user:
            bind_user(user)
            return user, "logged in"
    return None, "no login or invalid login"
Example #21
0
def load_settings():
    f = None
    setting = None
    try:
        f = codecs.open(SETTING_FILE, encoding='utf-8')
        t = f.read()
        setting = json.loads(t)
        setting = Storage(dict(list(defaults.items()) + list(setting.items())))
    except Exception:
        log('settings file is invalid, load default settings')
        setting = Storage(defaults)
    finally:
        if f:
            f.close()
    if not (len(setting.auth_password) > 0
            and setting.auth_password[0] == '{'):
        setting.auth_password = hash_password(setting.auth_password)
    return setting
Example #22
0
    def GET(self):
        categories = model.Categories()
        categories.annotate_by_projects()
        for category in categories:
            category.projects.annotate_by_comments()
            category.projects.annotate_by_points()

        context = Storage()
        print render.opml(context, categories)
Example #23
0
def add_user(name, password):
    users = _get_users()
    user = Storage(name=name, password=password)
    users[name] = user
    db = xtables.get_user_table()
    exist = db.select_one(where=dict(name=name))
    if exist is None:
        db.insert(name=name,password=password,ctime=xutils.format_time(),mtime=xutils.format_time())
    else:
        db.update(where=dict(name=name), password=password,mtime=xutils.format_time())
Example #24
0
def get_feed(context, template_name="feed", *args, **kwargs):
    context = context or Storage()
    context.setdefault("self_url", request_uri())
    if not context.has_key("user"):
        context.setdefault("user", get_user())
    context.setdefault("title", "no title")
    context.setdefault("subtitle", "no subtitle")
    context.setdefault("debug", False)
    page = getattr(feed_render, template_name)
    print page(context, *args, **kwargs)
Example #25
0
    def GET(self, webinput=None):
        i = webinput or web.input(
            t_id=None, p_id=None, search="", topic_id=None)

        topics, topic, points, point = model.t_p_helper(i.t_id, i.p_id)
        if not topics:
            print "ERROR"  #!!! should not occur often
            return

        user_lat, user_lon = user_location()
        if user_lat:
            points.annotate_by_distance(user_lat, user_lon)

        context = Storage(
            title=_("Point: details"),
            search=i.get("search", ""),  # for point page
            topic_id=i.topic_id,  # to know where to return to
            status=Storage(
                add="add",
                loc=location_indicator(),  # !!! define better later
                hom="home",
                sea="search",
                inf="info",
            ),
            map_context=Storage(
                zoom=config.mobile_point_zoom + config.getmap_zoomshift,
                map_width=config.mobile_map_width,
                map_height=config.mobile_map_height,
            ),
        )

        page_nav_data = Storage(nav_data=nav_data(
            add=links.add_point,
            loc=links.place,
            hom=links.point_list,
            sea=links.search,
            inf=links.info,
        ), )

        context.page_nav_data = page_nav_data

        get_page('point', context, topic, point)
Example #26
0
 def POST(self): 
     form = setup_db_form()
     if not form.validates() or form.d.passwd1 != form.d.passwd2:
         context = Storage(title=_("Setting database"),
                       description=_("Enter some values to start with the database setup"))
         get_page("setupdb", context, form)
         return
     else:
         res = create_dbs(form.d)
         if res:
             print "Database and tables creation done"
Example #27
0
def pc_page_context(context=None):
    context = context or Storage()
    if not context.has_key("user"):
        context.user = get_user()
    if not context.has_key("user_location"):
        context.user_location = session.get_user_location()

    context.setdefault("disallow_robots", config.disallow_robots)

    context.setdefault("title", '')
    context.setdefault("message", web.input().get('message', ''))
    return context
Example #28
0
def point_from_message(rfcmessage):
    msg = getAttachements(rfcmessage)
    sender = msg.sender[0][1]  #!!!
    point = Storage(
        _recepients=msg.recepients,
        author=sender,
        author_name=msg.sender[0][0],
        id=msg.message_id,
        uuid="mail " + msg.message_id,
    )
    attachments = []
    lmxpoints = []
    for ct, name, payload in msg.container:
        if "nokia.landmark" in ct or "text/xml" in ct:
            try:
                lmxfile = StringIO.StringIO(payload)
                lmxpoints = lmx_parser.parse_lmx(lmxfile)
            except:
                continue
        else:
            attachment = Storage(
                content=payload,
                content_type=ct,
                filename=name,
                author=sender,
            )
            attachments.append(attachment)

    try:
        point.update(lmxpoints[0])
    except:
        point.lat = point.lon = 0.0  # !!! not a point?
    point.attachments = attachments
    point.added = util.now()  #!!!?

    if msg.subject.strip():
        point.title = msg.subject
    # else title comes from landmark's name
    return point
Example #29
0
def start(info):
    """ Starts a session. Remember not to redirect after this. """
    session_id = _new_session_id()
    session_key = SESSION_DIR + session_id
    info = Storage(info)
    info.id = session_id
    info.added = time.time()
    info.referer = web.ctx.environ.get("HTTP_REFERER", "")
    info.entry = request_uri()
    file_storage.setItem(session_key, info)
    web.setcookie(COOKIE_NAME, session_id)
    web.ctx.current_session_id = session_id
    # !!!TODO: session own log? (take care of UM instances with shared fsstorage)
    return info
Example #30
0
    def GET(self):
        context = Storage(
            title=_("List of points"),
            status=Storage(
                add="add",
                loc=location_indicator(),  # !!! define better later
                hom="home",
                sea="search",
                inf="info",
            ),
        )

        page_nav_data = Storage(nav_data=nav_data(
            add=links.add_point,
            loc=links.place,
            hom=links.home,
            sea=None,
            inf=links.info,
        ), )

        context.page_nav_data = page_nav_data

        get_page('search', context)