Пример #1
0
def json_structure(points):
    json = []
    for point in points:
        topic = point.first_project
        if topic is None:
            continue
        json.append({
            "info":
            dict(
                point_id=point.id,
                point_name=point.title,
                href_point_page=pc_links('point', topic.id, point.id),
                date_creation=view.rel_date(point.added),
                creator_user_id=point.user_id,
                creator_user_name=point.author,
                lon=point.repr_lon,
                lat=point.repr_lat,
            ),
            "content":
            dict(
                textual=point.first.text,
                images=[],
            ),
            "tags":
            point.tags.for_str().split(" "),
            "topics": [
                dict(
                    topic_id=topic.id,
                    topic_name=topic.title,
                    href_topic_page=pc_links('topic', topic.id),
                ),
            ],
        })
    return json
Пример #2
0
def json_structure(points):
    json = []
    for point in points:
        topic = point.first_project
        if topic is None:
            continue
        json.append({"info": dict(
           point_id=point.id,
           point_name=point.title,
           href_point_page=pc_links('point', topic.id, point.id),
           date_creation=view.rel_date(point.added),
           creator_user_id=point.user_id,
           creator_user_name=point.author,
           lon=point.repr_lon,
           lat=point.repr_lat,
        ),
        "content": dict(
           textual=point.first.text,
           images=[],
        ),
        "tags": point.tags.for_str().split(" "),
        "topics":
            [dict(
                topic_id=topic.id,
                topic_name=topic.title,
                href_topic_page=pc_links('topic', topic.id),
                ),
            ],
        })
    return json
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
0
    def GET(self, format, topic_id, point_id):
        i = web.input(ol="")
        topics, topic, points, point = model.t_p_helper(topic_id, point_id)
        if not topics:
            redirect(5, _("No such topic. Delete from your bookmarks: ") + request_uri(), 
                links.index)
            return

        if not points:
            redirect(5, _("No such point. Delete from your bookmarks: ") + request_uri(), 
                links("topic", topic.id))
            return

        points.annotate_by_comments()

        comments = point.comments
        comments.annotate_by_profiles(default=DEFAULT_COMMENT_PROFILE)

        context = Storage(
            title=_("Point: ") + point.title,
        )

        comments.last_active = point.added
        for c in comments:
            comments.last_active = max(comments.last_active, c.added)
            c.title = util.first_line(c.text, length=64)
            c.summary = c.text
            c.tags = []

        uri_pref = pc_links('point', topic.id, point.id) + "#comment"
        get_feed_helper(context, comments,
            summary=lambda c: c.summary,  #???
            link=lambda c: uri_pref + str(c.id),
            format=format,
            with_content=(not i.ol))
Пример #7
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)
Пример #8
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),
        )
Пример #9
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
Пример #10
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
Пример #11
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),
        )
Пример #12
0
 def render(self):
     import fckeditor, view, links, i18n
     sBasePath = links.pc_links.fckeditor_base
     oFCKeditor = fckeditor.FCKeditor(self.name)
     oFCKeditor.BasePath = sBasePath
     oFCKeditor.Value = view.render_text(self.value or "")
     oFCKeditor.Config = {"CustomConfigurationsPath": 
         links.pc_links("editor_base_url", 
             AutoDetectLanguage="false",
             DefaultLanguage=i18n.getLanguage())
         }
     return oFCKeditor.Create()
Пример #13
0
def render_editor(name, value):
    import fckeditor, i18n
    sBasePath = links.pc_links.fckeditor_base

    oFCKeditor = fckeditor.FCKeditor(name)
    oFCKeditor.BasePath = sBasePath
    oFCKeditor.Value = render_text(value or "")
    oFCKeditor.Config = {
        "CustomConfigurationsPath":
        links.pc_links("editor_base_url",
                       AutoDetectLanguage="false",
                       DefaultLanguage=i18n.getLanguage())
    }
    return oFCKeditor.Create()
Пример #14
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", _("Points")),
            desturl=pc_links("topic", int(topic_id), **presets),
#            submitform=pc_links("topic_newpoint", int(topic_id)),
        )

        topics, topic = model.t_helper(topic_id)

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

        topics.annotate_by_datasources()
        topics.annotate_by_points()

        number_of_points = int(presets.get("number_of_points",
            config.points_per_page))

        points = model.Points(project=topic, external=None)
        
        model.order_helper(points, presets.get('order', 
            config.main_page_point_orders[0]))

        points.limit_by_page(1, length=number_of_points)
        points.annotate_by_comments()
        points.annotate_by_tags()
        points.annotate_by_profiles(default=DEFAULT_POINT_PROFILE)


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

        get_widget('topic_points', context, presets, points, topic)
Пример #15
0
    def GET(self, format):
        topics = model.Projects()
        topics.sort_by_vitality()
        topics.last_activity()

        topics.annotate_by_tags()
        topics.annotate_by_comments()
        topics.annotate_by_latest_points()
        # topics.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE)

        context = Storage(
            title = _("Topics"),
        )

        get_feed_helper(context, topics,
            summary=lambda t: t.comments.list()[0].text,
            link=lambda t: pc_links('topic', t.id),
            format=format,
        )
Пример #16
0
    def GET(self, format):
        topics = model.Projects()
        topics.sort_by_vitality()
        topics.last_activity()

        topics.annotate_by_tags()
        topics.annotate_by_comments()
        topics.annotate_by_latest_points()
        # topics.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE)

        context = Storage(title=_("Topics"), )

        get_feed_helper(
            context,
            topics,
            summary=lambda t: t.comments.list()[0].text,
            link=lambda t: pc_links('topic', t.id),
            format=format,
        )
Пример #17
0
    def GET(self, format, topic_id, point_id):
        i = web.input(ol="")
        topics, topic, points, point = model.t_p_helper(topic_id, point_id)
        if not topics:
            redirect(
                5,
                _("No such topic. Delete from your bookmarks: ") +
                request_uri(), links.index)
            return

        if not points:
            redirect(
                5,
                _("No such point. Delete from your bookmarks: ") +
                request_uri(), links("topic", topic.id))
            return

        points.annotate_by_comments()

        comments = point.comments
        comments.annotate_by_profiles(default=DEFAULT_COMMENT_PROFILE)

        context = Storage(title=_("Point: ") + point.title, )

        comments.last_active = point.added
        for c in comments:
            comments.last_active = max(comments.last_active, c.added)
            c.title = util.first_line(c.text, length=64)
            c.summary = c.text
            c.tags = []

        uri_pref = pc_links('point', topic.id, point.id) + "#comment"
        get_feed_helper(
            context,
            comments,
            summary=lambda c: c.summary,  #???
            link=lambda c: uri_pref + str(c.id),
            format=format,
            with_content=(not i.ol))
Пример #18
0
    def POST(self, topic_id):
        
        #1a
        # wsse auth
        # user = ...
        user = get_wsse_user()
        if user is None:
            unauthorized('um')
            return

        topics, topic = model.t_helper(topic_id)
        if not topics:
            web.notfound()
            return

        # 1b authorize
        if not acl.authorize.add_point(topic):
            forbidden()
            return

        #2 parse XML and store the point
        fc = web.webapi.data()
        entry = model.Point(feed_data.parse_entry(fc))

        point = model.Points.create(
                user=user,
                name=entry.title,
                lat=entry.lat,
                lon=entry.lon,
                url='',
                origin='',
                tags=entry.tags,
                description=entry.description,
                address='',
                project_id=topic_id,
            )

        created(pc_links("point", topic_id, point.id))
Пример #19
0
    def POST(self, topic_id):

        #1a
        # wsse auth
        # user = ...
        user = get_wsse_user()
        if user is None:
            unauthorized('um')
            return

        topics, topic = model.t_helper(topic_id)
        if not topics:
            web.notfound()
            return

        # 1b authorize
        if not acl.authorize.add_point(topic):
            forbidden()
            return

        #2 parse XML and store the point
        fc = web.webapi.data()
        entry = model.Point(feed_data.parse_entry(fc))

        point = model.Points.create(
            user=user,
            name=entry.title,
            lat=entry.lat,
            lon=entry.lon,
            url='',
            origin='',
            tags=entry.tags,
            description=entry.description,
            address='',
            project_id=topic_id,
        )

        created(pc_links("point", topic_id, point.id))
Пример #20
0
    def GET(self, topic_id):
        i = web.input()
        topics, topic, comments, comment = model.t_c_helper(topic_id, i.id)

        context = Storage(title=_("Widget Editor"))

        topic.comments.filter_by_type(comment_type="widget")
        topic.comments.sort_by_order()

        # Making new order
        cnt = 0
        for c in topic.comments:
            cnt += 1
            c.ord = cnt * 2 + 2
            if int(c.id) == comment.id:
                if i.dir == 'up':
                    c.ord -= 3
                else:
                    c.ord += 3

        # Saving order
        topic.comments.store_order()

        web.seeother(pc_links("topic_widgets", topic.id))
Пример #21
0
    def GET(self, topic_id):
        i = web.input()
        topics, topic, comments, comment = model.t_c_helper(topic_id, i.id)

        context = Storage(title=_("Widget Editor"))

        topic.comments.filter_by_type(comment_type="widget")
        topic.comments.sort_by_order()

        # Making new order
        cnt = 0
        for c in topic.comments:
            cnt += 1
            c.ord = cnt * 2 + 2
            if int(c.id) == comment.id:
                if i.dir == 'up':
                    c.ord -= 3
                else:
                    c.ord += 3

        # Saving order
        topic.comments.store_order()

        web.seeother(pc_links("topic_widgets", topic.id))
Пример #22
0
    def GET(self, topic_id):
        topics, topic = model.t_helper(topic_id)

        webinput = web.input()

        context = Storage(title=_("Widget Editor"))

        q = webutil.get_query(webinput.url)
        q.id = webinput.id  # comment id

        # !!! ugly! make better
        if "/submit" in webinput.url:
            web.seeother(pc_links("tools_submit_widgetize", topic.id, q))
        elif "/note" in webinput.url:
            web.seeother(pc_links("tools_note_widgetize", topic.id, q))
        elif "/container" in webinput.url:
            web.seeother(pc_links("tools_container_widgetize", topic.id, q))
        elif "/topic_points" in webinput.url:
            web.seeother(pc_links("tools_topic_points_widgetize", topic.id, q))
        elif "/topic_links" in webinput.url:
            web.seeother(pc_links("tools_topic_links_widgetize", topic.id, q))
        elif "/map" in webinput.url:
            web.seeother(pc_links("tools_map_widgetize", topic.id, q))
Пример #23
0
    def GET(self, topic_id): 
        topics, topic = model.t_helper(topic_id)

        webinput = web.input()

        context = Storage(title=_("Widget Editor"))

        q = webutil.get_query(webinput.url)
        q.id = webinput.id  # comment id

        # !!! ugly! make better
        if "/submit" in webinput.url:
            web.seeother(pc_links("tools_submit_widgetize", topic.id, q))
        elif "/note" in webinput.url:
            web.seeother(pc_links("tools_note_widgetize", topic.id, q))
        elif "/container" in webinput.url:
            web.seeother(pc_links("tools_container_widgetize", topic.id, q))
        elif "/topic_points" in webinput.url:
            web.seeother(pc_links("tools_topic_points_widgetize", topic.id, q))
        elif "/topic_links" in webinput.url:
            web.seeother(pc_links("tools_topic_links_widgetize", topic.id, q))
        elif "/map" in webinput.url:
            web.seeother(pc_links("tools_map_widgetize", topic.id, q))
Пример #24
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", _("Points")),
            desturl=pc_links("topic", int(topic_id), **presets),
#            submitform=pc_links("topic_newpoint", int(topic_id)),
        )

        topics, topic = model.t_helper(topic_id)

        topics.annotate_by_datasources()
        topics.annotate_by_points()

        number_of_points = int(presets.get("number_of_points",
            config.points_per_page))

        points = model.Points(project=topic, external=None)
        points.limit_by_page(1, length=number_of_points)
        points.annotate_by_comments()
        points.annotate_by_tags()
        points.annotate_by_profiles(default=DEFAULT_POINT_PROFILE)

        feed_link = feed_links("topic_points",
            topic.id, presets, page=None)

        if "zoom" in topic.profile and topic.profile.zoom != "auto":
            c_lat, c_lon, c_zoom = \
                topic.lat, topic.lon, topic.profile.zoom
            c_zoom = int(c_zoom)
        else:
            c_lat, c_lon, c_zoom = points.central_point(
                config.center_lat, config.center_lon, 14)

        map_context = Storage(
            getmap_url=pc_links.getmap,
            getmap_layers=config.getmap_layers,
            getmap_layers1=config.getmap_layers1,
            getmap_layers2=config.getmap_layers2,
            map_params=config.getmap_params,
            getmap_custom=config.getmap_custom,
            getmap_custom_init=config.getmap_custom_init,
            lat=c_lat,
            lon=c_lon,
            zoom=c_zoom + config.getmap_zoomshift,
            initial_feed=feed_link,
            has_new_point="false",
            getmap_zoom1=config.getmap_zoom1 + config.getmap_zoomshift,
            getmap_zoom2=config.getmap_zoom2 + config.getmap_zoomshift,
        )
        model.encode_coordinates(map_context)

        context.map_context = map_context
        context.page_specific_js = macros.map_js(map_context)

        if onlycode:
            presets.referer = ''
            # !!! map widget can't be part of combo
            self_link = links('map', topic_id, **presets)
            return """<iframe src="%s" style="height:%spx;width:%spx;border:none;"></iframe>""" % \
                (self_link, presets.height, presets.width)


        get_widget('map', context, topic, presets)