예제 #1
0
    def test_save_with_title(self):
        page = Page("index.md", "hello world!", title="Hello")
        self.repo.save(page)

        blob = self.bucket.get_blob('index.md')
        self.assertEqual('hello world!', blob.download_as_string())
        self.assertEqual({"title": "Hello"}, blob.metadata)
예제 #2
0
    def test_get(self):
        blob = self.bucket.blob('index.md')
        blob.upload_from_string(b'hello world!')

        page = self.repo.get('index.md')

        expected_page = Page("index.md", "hello world!")
        self.assertEqual(expected_page, page)
예제 #3
0
    def test_get_with_title(self):
        blob = self.bucket.blob('index.md')
        blob.metadata = {"title": "Hello"}
        blob.upload_from_string(b'hello world!')

        page = self.repo.get("index.md")

        expected_page = Page("index.md", "hello world!", title="Hello")
        self.assertEqual(expected_page, page)
예제 #4
0
    def get(self, page_name: str) -> Page:
        blob = self._bucket.get_blob(page_name)
        if blob is None:
            raise PageNotFound

        blob_bytes = blob.download_as_string()
        page_contents = blob_bytes.decode('utf-8')

        metadata = blob.metadata or {}
        title = metadata.get(self.TITLE, self.UNTITLED)

        return Page(page_name, page_contents, title=title)
예제 #5
0
def save_document():
    page = Page(
        name=request.form['file_name'],
        title=request.form['file_title'],
        contents=request.form['editor']
    )

    page_repo.save(page)

    encoded_id = base64.b64encode(page.name.encode('utf-8')).decode('utf-8')
    elasticsearch_client.index('pages', id=encoded_id, body={"text": page.contents, "title": page.title})

    return redirect(f"/index.html#!{page.name}")
예제 #6
0
def new_document(file_name=""):
    page = Page(name=file_name, contents="")
    return render_template("edit.html", page=page)
예제 #7
0
    def test_save(self):
        page = Page("index.md", "hello world!")
        self.repo.save(page)

        blob = self.bucket.get_blob('index.md')
        self.assertEqual('hello world!', blob.download_as_string())