コード例 #1
0
 def test_admin_edits(self):
     settings.change({
         'open-editing': 'no',
         'page-blacklist': '.*',
         'parents-must-exist': 'yes'
     })
     self.assertEquals(access.can_edit_page('foo/bar'), False)
     self.assertEquals(access.can_edit_page('foo/bar', is_admin=True), True)
コード例 #2
0
ファイル: view.py プロジェクト: verystrongjoe/gaewiki
def view_diff(r1, r2, user, is_admin):
    a = r1.revision_body
    if hasattr(r2, "revision_body"):
        b = r2.revision_body
    else:
        b = r2.body
    seqm = difflib.SequenceMatcher(None, a, b)
    output = []
    for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
        if opcode == "equal":
            output.append(seqm.a[a0:a1])
        elif opcode == "insert":
            output.append("<ins>" + seqm.b[b0:b1] + "</ins>")
        elif opcode == "delete":
            output.append("<del>" + seqm.a[a0:a1] + "</del>")
        elif opcode == "replace":
            output.append("<del>" + seqm.a[a0:a1] + "</del>")
            output.append("<ins>" + seqm.b[b0:b1] + "</ins>")
        else:
            raise RuntimeError, "unexpected opcode"
    data = {
        "r1": r1,
        "r2": r2,
        "r1updated": r1.updated if hasattr(r1, "updated") else r1.created,
        "r2updated": r2.updated if hasattr(r2, "updated") else r2.created,
        "page_title": r2.title,
        "diff_html": "".join(output),
        "user": user,
        "is_admin": is_admin,
        "can_edit": access.can_edit_page(r2.title, user, is_admin),
    }
    return render("diff.html", data)
コード例 #3
0
ファイル: view.py プロジェクト: verystrongjoe/gaewiki
def view_page(page, user=None, is_admin=False, revision=None):
    page = page.get_redirected()

    if page.title.startswith("Label:") and not page.body:
        page.body = DEFAULT_LABEL_BODY % {"title": page.title, "label": page.title[6:]}

    data = {
        "page": page,
        "is_admin": is_admin,
        "is_plain": page.get_property("format") == "plain",
        "can_edit": access.can_edit_page(page.title, user, is_admin),
        "page_labels": page.get_property("labels", []),
        "revision": revision,
    }

    # logging.debug(data)

    if settings.get("enable-map"):
        if page.get_property("map_label"):
            data["map_url"] = "/w/pages/map?label=" + util.uurlencode(page.get_property("map_label"))
        elif data["can_edit"] or page.geopt:
            data["map_url"] = "/w/map?page=" + util.uurlencode(page.title)

    if revision:
        logging.debug(u'Viewing page "%s" (revision %s)' % (data["page"].title, revision))
    else:
        logging.debug(u'Viewing page "%s"' % data["page"].title)
    return render("view_page.html", data)
コード例 #4
0
def show_page_history(page, user=None, is_admin=False):
    return render('history.html', {
        'page_title': page.title,
        'page': page,
        'revisions': page.get_history(),
        'can_edit': access.can_edit_page(page.title, user, is_admin),
    })
コード例 #5
0
def view_diff(r1, r2, user, is_admin):
    a = r1.revision_body
    if hasattr(r2, 'revision_body'):
        b = r2.revision_body
    else:
        b = r2.body
    seqm = difflib.SequenceMatcher(None, a, b)
    output = []
    for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
        if opcode == 'equal':
            output.append(seqm.a[a0:a1])
        elif opcode == 'insert':
            output.append("<ins>" + seqm.b[b0:b1] + "</ins>")
        elif opcode == 'delete':
            output.append("<del>" + seqm.a[a0:a1] + "</del>")
        elif opcode == 'replace':
            output.append("<del>" + seqm.a[a0:a1] + "</del>")
            output.append("<ins>" + seqm.b[b0:b1] + "</ins>")
        else:
            raise RuntimeError, "unexpected opcode"
    data = {
        "r1": r1,
        "r2": r2,
        "r1updated": r1.updated if hasattr(r1, 'updated') else r1.created,
        "r2updated": r2.updated if hasattr(r2, 'updated') else r2.created,
        "page_title": r2.title,
        "diff_html": ''.join(output),
        "user": user,
        "is_admin": is_admin,
        'can_edit': access.can_edit_page(r2.title, user, is_admin),
    }
    return render("diff.html", data)
コード例 #6
0
def view_page(page, user=None, is_admin=False, revision=None):
    page = page.get_redirected()

    if page.title.startswith("Label:") and not page.body:
        page.body = DEFAULT_LABEL_BODY % {"title": page.title, "label": page.title[6:]}

    data = {
        'page': page,
        'is_admin': is_admin,
        'is_plain': page.get_property('format') == 'plain',
        'can_edit': access.can_edit_page(page.title, user, is_admin),
        'page_labels': page.get_property('labels', []),
        'revision': revision,
    }

    # logging.debug(data)

    if settings.get('enable-map'):
        if page.get_property('map_label'):
            data['map_url'] = '/w/pages/map?label=' + util.uurlencode(page.get_property('map_label'))
        elif data['can_edit'] or page.geopt:
            data['map_url'] = '/w/map?page=' + util.uurlencode(page.title)

    if revision:
        logging.debug(u'Viewing page "%s" (revision %s)' % (data['page'].title, revision))
    else:
        logging.debug(u'Viewing page "%s"' % data['page'].title)
    return render('view_page.html', data)
コード例 #7
0
ファイル: view.py プロジェクト: blacktw/AscendantLibrary
def view_page(page, user=None, is_admin=False, revision=None):
    page = page.get_redirected()

    if page.title.startswith("Label:") and not page.body:
        page.body = DEFAULT_LABEL_BODY % {"title": page.title, "label": page.title[6:]}

    data = {
        'page': page,
        'is_admin': is_admin,
        'is_plain': page.get_property('format') == 'plain',
        'can_edit': access.can_edit_page(page.title, user, is_admin),
        'page_labels': page.get_property('labels', []),
        'revision': revision,
    }

    # logging.debug(data)

    if settings.get('enable-map'):
        if page.get_property('map_label'):
            data['map_url'] = '/w/pages/map?label=' + util.uurlencode(page.get_property('map_label'))
        elif data['can_edit'] or page.geopt:
            data['map_url'] = '/w/map?page=' + util.uurlencode(page.title)

    if revision:
        logging.debug(u'Viewing page "%s" (revision %s)' % (data['page'].title, revision))
    else:
        logging.debug(u'Viewing page "%s"' % data['page'].title)
    return render('view_page.html', data)
コード例 #8
0
ファイル: view.py プロジェクト: ilkerde/gaewiki
def show_page_history(page, user=None, is_admin=False):
    return render('history.html', {
        'page_title': page.title,
        'page': page,
        'revisions': page.get_history(),
        'can_edit': access.can_edit_page(page.title, user, is_admin),
    })
コード例 #9
0
ファイル: view.py プロジェクト: verystrongjoe/gaewiki
def show_page_history(page, user=None, is_admin=False):
    return render(
        "history.html",
        {
            "page_title": page.title,
            "page": page,
            "revisions": page.get_history(),
            "can_edit": access.can_edit_page(page.title, user, is_admin),
        },
    )
コード例 #10
0
ファイル: handlers.py プロジェクト: BauweBijl/gaewiki
 def edit_page(self, title, body=None):
     page = model.WikiContent.get_by_title(title)
     if body:
         page.body = body
     user = users.get_current_user()
     is_admin = users.is_current_user_admin()
     if not access.can_edit_page(title, user, is_admin):
         raise Forbidden
     if not body and not page.is_saved():
         page.load_template(user, is_admin)
     self.reply(view.edit_page(page), 'text/html')
コード例 #11
0
ファイル: handlers.py プロジェクト: vladiuz1/bgaewiki
 def edit_page(self, title, body=None):
     page = model.WikiContent.get_by_title(title)
     if body:
         page.body = body
     user = users.get_current_user()
     is_admin = users.is_current_user_admin()
     if not access.can_edit_page(title, user, is_admin):
         raise Forbidden
     if not body and not page.is_saved():
         page.load_template(user, is_admin)
     self.reply(view.edit_page(page), 'text/html')
コード例 #12
0
ファイル: handlers.py プロジェクト: BauweBijl/gaewiki
 def post(self):
     """Processes requests to move the pointer.  Expects arguments
     'page_name' and 'll'."""
     page = model.WikiContent.get_by_title(self.request.get('page_name'))
     if page is None:
         raise NotFound('Page not found.')
     if access.can_edit_page(page.title, users.get_current_user(), users.is_current_user_admin()):
         geo = self.request.get('lat') + ',' + self.request.get('lng')
         page.set_property('geo', geo)
         page.put()
     response = [l.strip() for l in page.get_property('geo').split(',')]
     self.reply(simplejson.dumps(response), 'application/json')
コード例 #13
0
ファイル: handlers.py プロジェクト: kamawanu/bgaewiki
 def post(self):
     """Processes requests to move the pointer.  Expects arguments
     'page_name' and 'll'."""
     page = model.WikiContent.get_by_title(self.request.get('page_name'))
     if page is None:
         raise NotFound('Page not found.')
     if access.can_edit_page(page.title, users.get_current_user(), users.is_current_user_admin()):
         geo = self.request.get('lat') + ',' + self.request.get('lng')
         page.set_property('geo', geo)
         page.put()
     response = [l.strip() for l in page.get_property('geo').split(',')]
     self.reply(simplejson.dumps(response), 'application/json')
コード例 #14
0
ファイル: handlers.py プロジェクト: BauweBijl/gaewiki
    def post(self):
        title = urllib.unquote(str(self.request.get('name'))).decode('utf-8')
        if self.request.get('Preview'):
            self.edit_page(title, self.request.get('body'))
            return

        user = users.get_current_user()
        if not access.can_edit_page(title, user, users.is_current_user_admin()):
            raise Forbidden
        page = model.WikiContent.get_by_title(title)
        page.update(body=self.request.get('body'), author=user, delete=self.request.get('delete'))
        self.redirect('/' + urllib.quote(page.title.encode('utf-8').replace(' ', '_')))
        taskqueue.add(url="/w/cache/purge", params={})
コード例 #15
0
ファイル: handlers.py プロジェクト: kamawanu/bgaewiki
    def post(self):
        title = urllib.unquote(str(self.request.get('name'))).decode('utf-8')
        if self.request.get('Preview'):
            self.edit_page(title, self.request.get('body'))
            return

        user = users.get_current_user()
        if not access.can_edit_page(title, user, users.is_current_user_admin()):
            raise Forbidden
        page = model.WikiContent.get_by_title(title)
        page.update(body=self.request.get('body'), author=user, delete=self.request.get('delete'))
        self.redirect('/' + urllib.quote(page.title.encode('utf-8').replace(' ', '_')))
        taskqueue.add(url="/w/cache/purge", params={})
コード例 #16
0
ファイル: handlers.py プロジェクト: blacktw/AscendantLibrary
    def post(self):
        title = urllib.unquote(str(self.request.get('name'))).decode('utf-8')
        if self.request.get('Preview'):
            self.edit_page(title, self.request.get('body'))
            return

        user = users.get_current_user()
        if not access.can_edit_page(title, user, users.is_current_user_admin()):
            raise Forbidden
        page = model.WikiContent.get_by_title(title)
        new_content = self.request.get('body')
        page.update(body=new_content, author=user, delete=self.request.get('delete'))

        memcache_key = 'Page:' + title
        memcache.set(memcache_key, new_content)
        self.redirect('/' + urllib.quote(page.title.encode('utf-8').replace(' ', '_')))
コード例 #17
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
    def test_logged_in_page_editing(self):
        alice = users.User('*****@*****.**')

        settings.change({'open-editing': 'no'})
        self.assertFalse(access.can_edit_page("some page", user=None))
        self.assertFalse(access.can_edit_page("some page", user=alice))

        settings.change({'open-editing': 'yes'})
        self.assertTrue(access.can_edit_page("some page", user=None))
        self.assertTrue(access.can_edit_page("some page", user=alice))

        settings.change({'open-editing': 'login'})
        self.assertFalse(access.can_edit_page("some page", user=None))
        self.assertTrue(access.can_edit_page("some page", user=alice))
コード例 #18
0
    def test_logged_in_page_editing(self):
        alice = users.User('*****@*****.**')

        settings.change({'open-editing': 'no'})
        self.assertFalse(access.can_edit_page("some page", user=None))
        self.assertFalse(access.can_edit_page("some page", user=alice))

        settings.change({'open-editing': 'yes'})
        self.assertTrue(access.can_edit_page("some page", user=None))
        self.assertTrue(access.can_edit_page("some page", user=alice))

        settings.change({'open-editing': 'login'})
        self.assertFalse(access.can_edit_page("some page", user=None))
        self.assertTrue(access.can_edit_page("some page", user=alice))
コード例 #19
0
ファイル: view.py プロジェクト: Aswanthsb/aguaviva-libs
def view_page(page, user=None, is_admin=False):
    page = page.get_redirected()
    data = {
        'page': page,
        'is_admin': is_admin,
        'is_plain': page.get_property('format') == 'plain',
        'can_edit': access.can_edit_page(page.title, user, is_admin),
        'page_labels': page.get_property('labels', []),
    }

    logging.debug(data)

    if settings.get('enable-map'):
        if page.get_property('map_label'):
            data['map_url'] = '/w/pages/map?label=' + util.uurlencode(page.get_property('map_label'))
        elif data['can_edit'] or page.geopt:
            data['map_url'] = '/w/map?page=' + util.uurlencode(page.title)

    logging.debug(u'Viewing page "%s"' % data['page'].title)
    return render('view_page.html', data)
コード例 #20
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_admin_edits(self):
     settings.change({'open-editing': 'no', 'page-blacklist': '.*', 'parents-must-exist': 'yes'})
     self.assertEquals(access.can_edit_page('foo/bar'), False)
     self.assertEquals(access.can_edit_page('foo/bar', is_admin=True), True)
コード例 #21
0
 def test_open_editing(self):
     self.assertEquals(access.can_edit_page('foo'), False)
     settings.change({'open-editing': 'yes'})
     self.assertEquals(access.can_edit_page('foo'), True)
     settings.change({'page-blacklist': '^foo'})
     self.assertEquals(access.can_edit_page('foo'), False)
コード例 #22
0
 def test_edit_orphan_page(self):
     settings.change({'open-editing': 'yes'})
     self.assertEquals(access.can_edit_page('foo/bar'), True)
     settings.change({'parents-must-exist': 'yes'})
     self.assertEquals(access.can_edit_page('foo/bar'), False)
コード例 #23
0
 def test_editor_access(self):
     user = users.User('*****@*****.**')
     self.assertEquals(access.can_edit_page('foo'), False)
     self.assertEquals(access.can_edit_page('foo', user), False)
     settings.change({'editors': user.email()})
     self.assertEquals(access.can_edit_page('foo', user), True)
コード例 #24
0
 def test_edit_locked_page(self):
     """Make sure that locked pages aren't editable."""
     model.WikiContent(title='foo', body='locked: yes\n---\n# foo').put()
     settings.change({'open-editing': 'yes', 'open-reading': 'yes'})
     self.assertEquals(access.can_edit_page('foo', is_admin=False), False)
コード例 #25
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_edit_system_pages(self):
     self.assertEquals(access.can_edit_page('gaewiki:settings', is_admin=True), True)
     self.assertEquals(access.can_edit_page('gaewiki:settings', is_admin=False), False)
コード例 #26
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_open_editing(self):
     self.assertEquals(access.can_edit_page('foo'), False)
     settings.change({'open-editing': 'yes'})
     self.assertEquals(access.can_edit_page('foo'), True)
     settings.change({'page-blacklist': '^foo'})
     self.assertEquals(access.can_edit_page('foo'), False)
コード例 #27
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_edit_orphan_page(self):
     settings.change({'open-editing': 'yes'})
     self.assertEquals(access.can_edit_page('foo/bar'), True)
     settings.change({'parents-must-exist': 'yes'})
     self.assertEquals(access.can_edit_page('foo/bar'), False)
コード例 #28
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_editor_access(self):
     user = users.User('*****@*****.**')
     self.assertEquals(access.can_edit_page('foo'), False)
     self.assertEquals(access.can_edit_page('foo', user), False)
     settings.change({'editors': user.email()})
     self.assertEquals(access.can_edit_page('foo', user), True)
コード例 #29
0
 def test_edit_system_pages(self):
     self.assertEquals(
         access.can_edit_page('gaewiki:settings', is_admin=True), True)
     self.assertEquals(
         access.can_edit_page('gaewiki:settings', is_admin=False), False)
コード例 #30
0
ファイル: tests.py プロジェクト: BauweBijl/bgaewiki
 def test_edit_locked_page(self):
     """Make sure that locked pages aren't editable."""
     model.WikiContent(title='foo', body='locked: yes\n---\n# foo').put()
     settings.change({'open-editing': 'yes', 'open-reading': 'yes'})
     self.assertEquals(access.can_edit_page('foo', is_admin=False), False)