Exemple #1
0
    def execute(self):
        tags = []
        locations = []
        status = ''

        util = NgoWikiUtil(self.request)
        util.open_database()
        try:
            isActivityPage = False
            tag_records = util.select_page_tags_by_path(self.page.page_name)

            for record in tag_records:
                if record["type"] == 1:
                    tags.append(record["tag"])
                    if record["tag"] == u'志愿活动类':
                        isActivityPage = True
                if record["type"] == 2:
                    locations.append(record["tag"])

            if isActivityPage:
                status = util.select_idea_status(
                    util.select_page_by_path(self.page.page_name)['id'])
        finally:
            util.close_database(True)
        html = []
        html.append('<script language="javascript">' + 'window.__page_meta=' +
                    json.dumps({
                        "tags": tags,
                        "locations": locations,
                        "status": status
                    }) + '</script>')
        return self.formatter.rawHTML('\n'.join(html))
Exemple #2
0
def execute(pagename, request):
    util = NgoWikiUtil(request)

    if not util.is_super_user():
        return

    util.open_database()

    try:
        util.fixup_database_001()
    finally:
        util.close_database(True)
Exemple #3
0
def execute(pagename, request):
    attach_dir = getAttachDir(request, pagename, create=1)
    form = request.values
    img_id = form['name']
    layout = json.loads(form['layout'])

    if len(layout['images']) == 1:
        request.write(layout['images'][0])
        return

    util = NgoWikiUtil(request)
    util.open_database()

    try:
        img_id = util.insert_spec_image(img_id, form['layout'])
    finally:
        util.close_database(True)

    width = int(layout['width'])
    height = int(layout['height'])

    cols = 2
    if len(layout['images']) > 4:
        cols = 3
    rows = int(math.ceil((len(layout['images']) + 0.0) / (cols + 0.0)))
    picWidth = int(math.floor((width - (cols - 1.0) * 3.0) / cols))
    picHeight = int(math.floor((height - (rows - 1.0) * 3.0) / rows))

    width = picWidth * cols + 3 * (cols - 1)
    height = picHeight * rows + 3 * (rows - 1)

    new_img = Image.new('RGB', (width, height), (255, 255, 255))

    row_idx = 0
    col_idx = 0
    for img_file in layout['images']:
        img = Image.open(
            os.path.join(attach_dir, img_file).encode(config.charset))
        new_img.paste(image_resize(img, (picWidth, picHeight)),
                      (col_idx * picWidth + col_idx * 3,
                       row_idx * picHeight + row_idx * 3))

        col_idx = col_idx + 1
        if col_idx >= cols:
            col_idx = 0
            row_idx = row_idx + 1

    new_img.save(
        os.path.join(attach_dir, img_id + '.jpg').encode(config.charset))
    request.write(img_id + '.jpg')
Exemple #4
0
def execute(pagename, request):
    ngowikiutil = NgoWikiUtil(request)
    ngowikiutil.open_database()
    try:
        form = request.values
        tags = form.get('tags').split(",")
        relatedtags = ngowikiutil.select_related_tags(tags)
        for tag in tags:
            for relatedtag in relatedtags:
                if relatedtag["tag"] == tag:
                    relatedtags.remove(relatedtag)
                    break
        request.write(json.dumps(relatedtags))
    finally:
        ngowikiutil.close_database(True)
    def execute(self):

        if JoinUsPageMacro.lastupdated == None or long(
                time.time()) - JoinUsPageMacro.lastupdated > 3600L:
            ngowikiutil = NgoWikiUtil(self.request)
            try:
                ngowikiutil.open_database()
            finally:
                ngowikiutil.close_database(True)
            JoinUsPageMacro.lastupdated = long(time.time())

        context = {}

        engine = tenjin.Engine(path=[os.path.dirname(__file__) + '/views'])
        html = engine.render('JoinUsPage.pyhtml', context)

        return self.formatter.rawHTML(html)
Exemple #6
0
def execute(pagename, request):
    form = request.values
    img_id = form['name'][0:-4]

    imgs = []

    util = NgoWikiUtil(request)
    util.open_database()

    try:
        data = util.select_spec_image_by_id(img_id)
        if data == None:
            imgs.append(form['name'])
        else:
            imgs = json.loads(data['definition'])['images']
    finally:
        util.close_database(True)

    request.write(json.dumps(imgs))
Exemple #7
0
def execute(pagename, request):
    ngowikiutil = NgoWikiUtil(request)
    ngowikiutil.open_database()
    try:
        form = request.values
        tags = form.get('tags').split(",")
        favorite = None
        if 'favorite' in form and form[
                'favorite'] != "false" and request.user != None and request.user.valid:
            favorite = request.user.id

        relatedtags = ngowikiutil.select_related_tags(tags, favorite)
        for tag in tags:
            for relatedtag in relatedtags:
                if relatedtag["tag"] == tag:
                    relatedtags.remove(relatedtag)
                    break
        request.write(json.dumps(relatedtags))
    finally:
        ngowikiutil.close_database(True)
Exemple #8
0
def execute(pagename, request):
    form = request.values
    img_id = form['name'][0:-4]

    imgs = []

    util = NgoWikiUtil(request)
    util.open_database()

    try:
        data = util.select_spec_image_by_id(img_id)
        if data == None:
            imgs.append(form['name'])
        else:
            imgs = json.loads(data['definition'])['images']
    finally:
        util.close_database(True)

    for img_file in imgs:
        request.write('<img class="logo" src="' + getAttachUrl(pagename, img_file, request) + '">' + '<BR><BR>')    
Exemple #9
0
def execute(pagename, request):
    util = NgoWikiUtil(request)

    if not util.is_super_user():
        return

    util.open_database()

    try:
        util.init_database()

        pages = request.rootpage.getPageList(user='', exists='')
        for name in pages:
            if name.find(u'Category') == -1:
                page = Page(request, name)
                page_uuid = util.insert_page(page)["id"]

                pageinfo = util.parse_page(page)
                pageinfo["id"] = page_uuid
                util.update_page_meta(pageinfo)
    finally:
        util.close_database(True)
Exemple #10
0
    def do_action_finish(self, success):
        if success:
            pg = Page(self.request, self.newpagename)

            ngowikiutil = NgoWikiUtil(self.request)
            ngowikiutil.open_database()
            try:
                pageinfo = ngowikiutil.parse_page(pg)
                pagerecord = ngowikiutil.select_page_by_path(self.pagename)
                page_uuid = None
                if pagerecord == None:
                    page_uuid = ngowikiutil.insert_page(pg)["id"]
                else:
                    page_uuid = pagerecord["id"]
                    ngowikiutil.update_page(page_uuid, pg)
                pageinfo["id"] = page_uuid
                ngowikiutil.update_page_meta(pageinfo)
            finally:
                ngowikiutil.close_database(True)

            url = pg.url(self.request)
            self.request.http_redirect(url, code=301)
        else:
            self.render_msg(self.make_form(), "dialog")
Exemple #11
0
    def do_action(self):
        """ Delete pagename """
        form = self.form
        comment = form.get('comment', u'')
        comment = wikiutil.clean_input(comment)

        ngowikiutil = NgoWikiUtil(self.request)
        ngowikiutil.open_database()
        try:

            # Create a page editor that does not do editor backups, because
            # delete generates a "deleted" version of the page.
            self.page = PageEditor(self.request,
                                   self.pagename,
                                   do_editor_backup=0)
            success, msgs = self.page.deletePage(comment)
            ngowikiutil.remove_page_by_path(self.pagename)

            delete_subpages = 0
            try:
                delete_subpages = int(form['delete_subpages'])
            except:
                pass

            if delete_subpages and self.subpages:
                for name in self.subpages:
                    self.page = PageEditor(self.request,
                                           name,
                                           do_editor_backup=0)
                    success_i, msg = self.page.deletePage(comment)
                    ngowikiutil.remove_page_by_path(name)
                    msgs = "%s %s" % (msgs, msg)
        finally:
            ngowikiutil.close_database(True)

        return success, msgs
Exemple #12
0
class DiscussionBoard:
    
    def __init__(self, request, pagename):
        self.request = request
        self.user = request.user
        self.pagename = pagename
        self.page = Page(self.request, self.pagename)
        self.ngowikiutil = NgoWikiUtil(self.request)
        self.ngowikiutil.open_database()
        self.pageid = self.ngowikiutil.select_page_by_path(self.pagename)["id"]

    def release(self):
        self.ngowikiutil.close_database(True)

    def like(self, sessionId):
        userId = 'anonymous-' + sessionId
        if self.user != None and self.user.valid:
            userId = self.user.id
        if not self.ngowikiutil.has_user_liked_page(userId, self.page):
            self.ngowikiutil.insert_like(self.page, userId, '')
            self.ngowikiutil.commit_database()

    def unlike(self, sessionId):
        userId = 'anonymous-' + sessionId
        if self.user != None and self.user.valid:
            userId = self.user.id
        like_info = self.ngowikiutil.select_like_by_page_and_userid(self.pageid, userId)
        if like_info != None:
            self.ngowikiutil.remove_likes_by_id(like_info["id"])
            self.ngowikiutil.commit_database()

    def comment(self, comment):
        if self.user == None or not self.user.valid:
            return
        self.ngowikiutil.insert_comment(self.page, self.user.id, comment)
        self.ngowikiutil.commit_database()

    def superrecommend(self, comment):
        if self.user == None or not self.user.valid:
            return
        if not self.user.isSuperUser():
            return
        self.ngowikiutil.super_recommend(self.page, comment)
        self.ngowikiutil.commit_database()

    def removecomment(self, commentid):
        if self.user == None or not self.user.valid:
            return
        comment_info = self.ngowikiutil.select_comment_by_id(commentid)
        if comment_info == None:
            return
        if not self.user.isSuperUser() and self.user.id != comment_info["user_id"]:
            return
        self.ngowikiutil.remove_comments_by_id(commentid)
        self.ngowikiutil.commit_database()

    def view(self, offset, length, sessionId):
        page_info = self.ngowikiutil.select_page_by_id(self.pageid)
        comment_list = self.ngowikiutil.select_comments_by_page(self.page, offset, length)
        if comment_list == None:
            comment_list = []
        for comment in comment_list:
            user = User(self.request, id=comment["user_id"])
            comment["user_name"] = user.name
            comment["comment"] = comment["comment"].replace("\n", "<br>")
            if self.user == None or not self.user.valid or (not self.user.isSuperUser() and self.user.id != comment["user_id"]):
                continue
            comment["_delete_"] = True
        isSuperUser = False
        if self.user != None and self.user.valid and self.user.isSuperUser():
            isSuperUser = True
        has_user_liked_page = False
        if self.user != None and self.user.valid:
            has_user_liked_page = self.ngowikiutil.has_user_liked_page(self.user.id, self.page)
        else: 
            has_user_liked_page = self.ngowikiutil.has_user_liked_page('anonymous-' + sessionId, self.page)
        return {"commentcount": page_info["commentcount"], "likecount": page_info["likecount"], "hasUserLikedPage": has_user_liked_page, "comments": {"offset": offset, "length": length, "items": comment_list}, "isSuperUser": isSuperUser, "superrecommend": page_info["superrecommend"]}
Exemple #13
0
            request.theme.add_msg(unicode(msg), "error")
            # And show the editor again
            pg.sendEditor(preview=savetext, comment=comment, staytop=1)
            return

        # Send new page after successful save
        request.reset()
        pg = Page(request, pagename)

        ngowikiutil = NgoWikiUtil(request)
        ngowikiutil.open_database()
        try:
            pageinfo = ngowikiutil.parse_page(pg)
            pagerecord = ngowikiutil.select_page_by_path(pg.page_name)
            page_uuid = None
            if pagerecord == None:
                page_uuid = ngowikiutil.insert_page(pg)["id"]
            else:
                page_uuid = pagerecord["id"]
                ngowikiutil.update_page(page_uuid, pg)
            pageinfo["id"] = page_uuid
            ngowikiutil.update_page_meta(pageinfo)
            ngowikiutil.update_idea_status(page_uuid, ideastatus)
        finally:
            ngowikiutil.close_database(True)

        # sets revision number to default for further actions
        request.rev = 0
        request.theme.add_msg(savemsg, "info")
        pg.send_page()
Exemple #14
0
    def execute(self):
        ngowikiutil = NgoWikiUtil(self.request)
        ngowikiutil.open_database()
        try:
            offset = 0
            length = 10
            sortby = "lastmodified"
            order = "DESC"
            filterByTags = self.filterByTags
            favorite = None

            form = self.request.values
            if 'from' in form:
                offset = int(form['from'])
            if 'length' in form:
                length = int(form['length'])
            if 'sortby' in form:
                sortby = form['sortby']
                if sortby == 'title':
                    order = "ASC"
            if 'order' in form:
                order = form['order']
            if 'favorite' in form and form[
                    'favorite'] != "false" and self.user != None and self.user.valid:
                favorite = self.user.id
            if 'filterByTags' in form:
                filterByTags = form['filterByTags'].split(",")

            for tag in filterByTags:
                ngowikiutil.update_tag_hitcount(tag)

            results = ngowikiutil.select_pages_by_tag(filterByTags, favorite,
                                                      sortby, order, offset,
                                                      length)
            total = ngowikiutil.count_pages_by_tag(filterByTags, favorite)

            buffer = []
            buffer.append(
                '''
                <script language="javascript">window.__ListPagesByTag_filterByTag = %(filterByTags)s;window.__ListPagesByTag_filterByTag_default = %(filterByTagsDefault)s;</script>
                <div id="listpagesbytag_sorter"></div>
				<div id="listpagesbytag_favorite"></div>
                <div id="listpagesbytag_filter"></div>
            ''' % {
                    "filterByTagsDefault": json.dumps(self.filterByTags),
                    "filterByTags": json.dumps(",".join(filterByTags))
                })

            template = '''
                <table class="listitem_with_logosummary">
                    <tr>
                        <!--
                        <td class="logo">
                            %(logo)s
                        </td>
                        -->
                        <td>
                           <div class="title">
                              <a href="%(link)s">%(title)s</a>
                           </div>
                           <div class="meta">
                               <span>%(lastmodified)s</span>
                               <span>%(tags)s</span>
                               <span><span class="metaitem">%(likecount)s<span></span>
                               <span><span class="metaitem">%(commentcount)s<span></span>
                               <span><span class="metaitem">%(hitcount)s<span></span>
                           </div>
                           <div class="summary">%(summary)s</div>
                        </td>
                     </tr>
                 </table>
                '''
            for result in results:
                page = Page(self.request, result["path"])
                logo = '<div class="logo defaultLogo">&nbsp;</div>'
                if len(result["logo"]) > 0 and exists(
                        self.request, result["path"], result["logo"]):
                    logo = '<img class="logo" src="' + getAttachUrl(
                        result["path"], result["logo"], self.request) + '">'
                link = page.url(self.request)
                title = result["title"]
                lastmodified = page.mtime_printable(self.request)
                summary = result["summary"].replace("'''", "").replace(
                    u"【请在此插入图片】", "").replace(u"【请在此插入图片,最多可插入9张】", "")

                tags = (", ".join(
                    map(
                        lambda x: '<a href=\'javascript:add_filter_by_tag(' +
                        json.dumps(x["tag"]) + ')\' >' + x["tag"] + '</a>',
                        filter(
                            lambda x: x["type"] == 1 or x["type"] == 2,
                            ngowikiutil.select_page_tags_by_id(
                                result["id"])))))

                if len(tags) > 0:
                    tags = '<span class="metaitem">' + tags + '</span>'

                buffer.append(
                    template % {
                        "logo":
                        logo,
                        "title":
                        title,
                        "link":
                        link,
                        "lastmodified":
                        lastmodified,
                        "tags":
                        tags,
                        "summary":
                        summary,
                        "likecount":
                        u'\u559c\u6b22\uff1a' + str(result["likecount"]),
                        "commentcount":
                        u'\u8bc4\u8bba\u6570\uff1a' +
                        str(result["commentcount"]),
                        "hitcount":
                        u'\u8bbf\u95ee\u91cf\uff1a' + str(result["hitcount"])
                    })

            buffer.append("<script language='javascript'>render_pagingbar(" +
                          str(total) + ', ' + str(length) + ');</script>')
            ret = ''.join(buffer)
            return ret
        finally:
            ngowikiutil.close_database(True)
    def execute(self):

        if FrontpageMacro.lastupdated == None or long(time.time()) - FrontpageMacro.lastupdated > 3600L:
            ngowikiutil = NgoWikiUtil(self.request)
            try:
                ngowikiutil.open_database()
                FrontpageMacro.totalcount_activities = ngowikiutil.count_pages_by_tag([u'服务产品类']) + ngowikiutil.count_pages_by_tag([u'视听产品类']) + ngowikiutil.count_pages_by_tag([u'实体产品类'])
                FrontpageMacro.totalcount_ngos = ngowikiutil.count_pages_by_tag([u'公益机构类'])
                FrontpageMacro.totalcount_enterprises = ngowikiutil.count_pages_by_tag([u'企业志愿组织类'])
                FrontpageMacro.featured_activities = ngowikiutil.select_pages_with_one_of_tags([u'服务产品类', u'视听产品类', u'实体产品类'], 'featured', 'DESC', 0, 20)
                for record in FrontpageMacro.featured_activities[0:2]:
                    record["summary"] = record["summary"].replace("'''", "")
                    record["summary"] = filter_summary(record["summary"], 50);
                    pagename = record["path"]
                    page = Page(self.request, pagename)
                    record["link"] = page.url(self.request)
                    if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]):
                        record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request)
                    else:
                        findLogo = False
                        text = page.getPageText()
                        match = re.search('\\{\\{attachment:([^\\|]+)\\|\\|.*}}', text)
                        if match != None:
                            logo = match.group(1)
                            if exists(self.request, record["path"], logo):
                                record["logo_link"] = getAttachUrl(record["path"], logo, self.request)
                                findLogo = True
                        if not findLogo:
                            record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png"
                FrontpageMacro.featured_ngos = ngowikiutil.select_pages_by_tag([u'公益机构类'], 'featured', 'DESC', 0, 2)
                for record in FrontpageMacro.featured_ngos:
                    pagename = record["path"]
                    record["summary"] = filter_summary(record["summary"], 50)
                    page = Page(self.request, pagename)
                    record["link"] = page.url(self.request)
                    if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]):
                        record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request)
                    else:
                        record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png"
                FrontpageMacro.recently_added = ngowikiutil.select_latest_created_pages([u'服务产品类', u'视听产品类', u'实体产品类', u'公益机构类', u'企业志愿组织类'], 0, 5)
                for record in FrontpageMacro.recently_added:
                    pagename = record["path"]
                    page = Page(self.request, pagename)
                    record["link"] = page.url(self.request)
                    if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]):
                        record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request)
                    else:
                        record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png"
                    if u'服务产品类' in ngowikiutil.parse_page(page)["categories"] or u'视听产品类' in ngowikiutil.parse_page(page)["categories"] or u'实体产品类' in ngowikiutil.parse_page(page)["categories"]:
                        record["recently_added_type"] = "activity"
                    elif u'公益机构类' in ngowikiutil.parse_page(page)["categories"]:
                        record["recently_added_type"] = "ngo"
                    else:
                        record["recently_added_type"] = "enterprise"
                FrontpageMacro.news_items = ngowikiutil.select_pages_by_tag([u'新闻动态类'], 'featured', 'DESC', 0, 100)
                for record in FrontpageMacro.news_items:
                    pagename = record["path"]
                    page = Page(self.request, pagename)
                    record["link"] = page.url(self.request)
                    if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]):
                        record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request)
                    else:
                        record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png"
            finally:
                ngowikiutil.close_database(True)
            FrontpageMacro.lastupdated = long(time.time())

        context = {
            'totalcount_activities': FrontpageMacro.totalcount_activities,
            'totalcount_ngos': FrontpageMacro.totalcount_ngos,
            'totalcount_enterprises': FrontpageMacro.totalcount_enterprises,
            'featured_activities': FrontpageMacro.featured_activities,
            'featured_ngos': FrontpageMacro.featured_ngos,
            'recently_added': FrontpageMacro.recently_added,
            'news_items': FrontpageMacro.news_items,
            'logo_url': self.request.cfg.url_prefix_static + "/ngowiki/img/sitelogo.png",
            'slogan_url': self.request.cfg.url_prefix_static + "/ngowiki/img/slogan2.png"
        }

        engine = tenjin.Engine(path=[os.path.dirname(__file__) + '/views'])
        html = engine.render('Frontpage.pyhtml', context)

        return self.formatter.rawHTML(html)