{"id":13446312,"url":"https://github.com/Jaza/flask-editablesite","last_synced_at":"2025-03-21T06:31:06.851Z","repository":{"id":137477891,"uuid":"43406245","full_name":"Jaza/flask-editablesite","owner":"Jaza","description":"A template for building a small marketing web site in Flask where all content is live editable.","archived":false,"fork":false,"pushed_at":"2016-08-06T08:32:58.000Z","size":1116,"stargazers_count":99,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-18T03:51:25.675Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jaza.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-09-30T02:10:04.000Z","updated_at":"2024-07-02T07:30:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8fe16d4-677d-47e6-bff0-e8964ec29670","html_url":"https://github.com/Jaza/flask-editablesite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaza%2Fflask-editablesite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaza%2Fflask-editablesite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaza%2Fflask-editablesite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaza%2Fflask-editablesite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jaza","download_url":"https://codeload.github.com/Jaza/flask-editablesite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244750589,"owners_count":20504087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:00:51.132Z","updated_at":"2025-03-21T06:31:06.401Z","avatar_url":"https://github.com/Jaza.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"Flask Editable Site\n===================\n\nA template for building a small marketing web site in `Flask\n\u003chttp://flask.pocoo.org/\u003e`_ where all content is live editable.\n\nThis app includes front- and back-end utilites for live / in-place editing of several different field types:\n\n- **Short text:** a regular text field with (AJAX-based) auto-save\n- **Rich text:** a ``textarea`` converted to WYSIWYG (powered by `Dante \u003chttp://michelson.github.io/Dante/\u003e`_) with auto-save\n- **Image:** a file field converted to a drag-and-drop live image upload widget (powered by `Dropzone.js \u003chttp://www.dropzonejs.com/\u003e`_)\n- **Date/time:** a regular text field converted to a date/time picker with auto-save\n\nIt also includes utilities for adding to, re-ordering, and deleting from lists of content items (all via in-place editing).\n\nHere's a `demo of the app in action\n\u003chttps://flask-editablesite.herokuapp.com/\u003e`_.\n\nAnd here's an `article explaining the app in more detail \u003chttp://greenash.net.au/thoughts/2015/10/introducing-flask-editable-site/\u003e`_.\n\nThe aim of this app is to demonstrate that, with the help of modern JS libraries, and with some well-thought-out server-side snippets, it's now perfectly possible to \"bake in\" live in-place editing for virtually every content element in a typical brochureware site.\n\nThis app is not a CMS. On the contrary, think of it as a proof-of-concept alternative to a CMS. An alternative where there's no \"admin area\", there's no \"editing mode\", and there's no \"preview button\". There's only direct manipulation.\n\n\"Template\" means that this is a sample app. It comes with a bunch of models that work out-of-the-box (e.g. text content block, image content block, gallery item, event). However, these are just a starting point: you can and should define your own models when building a real site. Same with the front-end templates: the home page layout and the CSS styles are just examples.\n\n|build-status| |coverage|\n\n.. |build-status| image:: https://travis-ci.org/Jaza/flask-editablesite.svg?branch=master\n   :target: https://travis-ci.org/Jaza/flask-editablesite\n   :alt: Travis CI status\n\n.. |coverage| image:: https://coveralls.io/repos/Jaza/flask-editablesite/badge.svg?branch=master\n   :target: https://coveralls.io/r/Jaza/flask-editablesite\n   :alt: Coverage status\n\n\nQuickstart\n----------\n\nFirst, set your app's secret key as an environment variable. For example, add the following to ``.bashrc`` or ``.bash_profile`` ::\n\n    export FLASK_EDITABLESITE_SECRET='something-really-secret'\n\nThen run the following commands to bootstrap your environment ::\n\n    git clone https://github.com/Jaza/flask-editablesite\n    cd flask-editablesite\n    pip install -r requirements/dev.txt\n\nBefore running the app, you'll need to either specify DB config, or enable session store mode. See instructions further down for details on either of these. Then you can run the app with this command ::\n\n    python manage.py server\n\nYou will see a pretty welcome screen.\n\n\nDynamic Secret Key\n------------------\n\nYou can have a different random secret key each time the app starts,\nif you want ::\n\n    export FLASK_EDITABLESITE_SECRET=`python -c \"import os; from binascii import hexlify; print(hexlify(os.urandom(24)))\"`; python manage.py server\n\n\nDB config and migrations\n------------------------\n\nYou must specify the DB credentials before starting the app in normal mode ::\n\n    export FLASK_EDITABLESITE_DATABASE_URI=\"postgresql://flask_editablesite:flask_editablesite@localhost:5432/flask_editablesite\"\n\nIf using your own DB models, run the following to get started with migrations ::\n\n    python manage.py db init\n\nEach time you need to create a new migration script, run the following ::\n\n    python manage.py db migrate\n\nIf using the included sample models and migrations, or if you've already initialised and created migrations for your own models, then run the following to create the DB schema ::\n\n    python manage.py db upgrade\n\nFor a full migration command reference, run ``python manage.py db --help``.\n\n\nSession store mode\n------------------\n\nThe app can be configured to store all content as session data, instead of saving it to the database. To do this, set the following environment variable ::\n\n    export FLASK_EDITABLESITE_USE_SESSIONSTORE_NOT_DB=1\n\nWhen in session store mode, all content changes are lost whenever a new session is started (e.g. if the user clears his/her cookies, or switches to a different browser). A user's edits are only visible to him/her self, not to anyone else. Session store mode is therefore very useful for running the app in a demo or test environment. It should **not** be used in production, where you want content edits to actually be persisted and shown to other users!\n\nIf session store mode is enabled, the app doesn't need a database at all (i.e. you don't even need to configure DB credentials).\n\nAlso, if session store mode is enabled, then it's highly recommended that you store session data server-side. For this purpose, the app comes with `Flask-Session \u003chttp://pythonhosted.org/Flask-Session/\u003e`_ installed. If you leave session storage as Flask's default (i.e. store client-side in a cookie), then you'll soon find your content disappearing (or errors being thrown), because `no more than 4KB of data can be stored in one cookie \u003chttp://greenash.net.au/thoughts/2015/10/cookies-cant-be-more-than-4kib-in-size/\u003e`_.\n\nFor example, to store session data on the filesystem ::\n\n    export FLASK_EDITABLESITE_SESSION_TYPE=\"filesystem\"\n    export FLASK_EDITABLESITE_SESSION_FILE_DIR=\"static/cache/sessions\"\n\nOr, to store it in Memcached ::\n\n    export FLASK_EDITABLESITE_SESSION_TYPE=\"memcached\"\n    export FLASK_EDITABLESITE_SESSION_MEMCACHED=\"your.memcached.host:11211\"\n\n\nCreating users\n--------------\n\nWhen in normal (DB) mode, you'll need to create a user in order to log in and start editing. For the sake of simplicity, and in order to maintain the \"no admin area\" ideal, this app doesn't include any GUI for creating or managing users. If you need a GUI for user management, or for anything else, there are plenty of Flask packages that can help you out, with the best candidate being `Flask-Admin \u003chttps://flask-admin.readthedocs.org/\u003e`_.\n\nTo create a user, run this command ::\n\n    python manage.py createuser\n\nAnd enter an email and password when prompted. You will then be able to log in. Also, again for simplicity, this app doesn't include any definition or management of user roles: if a user exists and is active, then he/she can log in and edit everything, end of story. For many small sites, this is all that's needed anyway.\n\nWhen in session store mode, the app makes one user account available for login purposes. The default email and password for this user is ``test@test.com`` and ``test``, respectively. You can override these by setting the ``FLASK_EDITABLESITE_SESSIONSTORE_USER_EMAIL`` and ``FLASK_EDITABLESITE_SESSIONSTORE_USER_PASSWORD`` environment variables. The login email and password are shown on the home page when logged out, so that users demo'ing the app have easy access to the credentials.\n\n\nSample content\n--------------\n\nThe app comes with some utilities for populating a site with random text and images (from configured sources). This works either in regular (database) mode, or in session store mode. It's handy for demo, prototyping, and \"placeholder content\" purposes.\n\nFor the \"sample images\" functionality, you can configure the app to scrape links to images from a URL of your choice. E.g. say the web site ``coolexamplephotos.com`` has source code that looks something like this ::\n\n    \u003chtml\u003e\n    \u003chead\u003e\n      \u003ctitle\u003eCool Example Photos\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n      \u003ch1\u003eCool Example Photos\u003c/h1\u003e\n\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"http://coolexamplephotos.com/photos/foo.jpg\"\u003efoo.jpg\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"http://coolexamplephotos.com/photos/bar.jpg\"\u003ebar.jpg\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"http://coolexamplephotos.com/photos/baz.jpg\"\u003ebaz.jpg\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/body\u003e\n    \u003c/html\u003e\n\nSet the following environment variables, and the app will randomly source images from that site and display them in image fields ::\n\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_SCRAPE_URL=\"http://coolexamplephotos.com/\"\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_SCRAPE_PARENTELNAME=\"li\"\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_RELATIVE_PATH=\"coolexamplephotos/\"\n\nWhere ``FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_SCRAPE_URL`` is the URL of the page to scrape, ``FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_SCRAPE_PARENTELNAME`` is the parent element of the image links, and ``FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_RELATIVE_PATH`` is the relative directory in which to store the downloaded images on the filesystem.\n\nTo pre-download the sample images for faster access, use the ``downloadsampleimages`` command like so ::\n\n    python manage.py downloadsampleimages --url=\"http://coolexamplephotos.com/\" --targetdir=./flask_editablesite/static/uploads/coolexamplephotos --parentelname=\"li\"\n\nFor the \"sample text\" functionality, you can configure one or more URLs of texts to use as source material. The texts can be anything (e.g. \"lorem ipsum\" blurb, blog posts, encyclopaedia entries), and can be in any text format (e.g. HTML, RSS, CSV); but books in plain text are recommended.\n\nSet the following environment variable to randomly source text from one of the URLs ::\n\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_TEXT_SCRAPE_URLS=\"['http://cooltextsources.com/texts/foo.txt', 'http://cooltextsources.com/texts/bar.txt', 'http://cooltextsources.com/texts/baz.txt']\"\n\nThe actual sentences that then get displayed in text fields, are generated based on the chosen source text, using the `Markovify \u003chttps://github.com/jsvine/markovify\u003e`_ library.\n\nIf using sample images and/or text with these utilities, it's recommended to set the \"credits\" environment variables, which will show your specified acknowledgements on the home page ::\n\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_IMAGES_CREDITS='\u003cp\u003eThe placeholder images are a selection from the public domain \u003ca href=\"http://coolexamplephotos.com/\"\u003eCool Example Photos\u003c/a\u003e photo collection (a different random set for each session). Many thanks to John Smith of Foobar Design.\u003c/p\u003e'\n    export FLASK_EDITABLESITE_EDITABLE_SAMPLE_TEXT_CREDITS='\u003cp\u003eThe placeholder text is sourced from a subset of the public domain \u003ca href=\"http://cooltextsources.org/\"\u003eCool Text Sources\u003c/a\u003e texts collection (a different random text for each session). Many thanks to the original text authors. The actual sentences in the text are generated using the \u003ca href=\"https://github.com/jsvine/markovify\"\u003eMarkovify\u003c/a\u003e library.\u003c/p\u003e'\n\n\nDeployment\n----------\n\nIn your production environment, make sure the ``FLASK_EDITABLESITE_ENV`` environment variable is set to ``\"prod\"``.\n\n\nShell\n-----\n\nTo open the interactive shell, run ::\n\n    python manage.py shell\n\nBy default, you will have access to ``app``, ``db``, and the ``User`` model.\n\n\nRunning Tests\n-------------\n\nTo run all tests, run ::\n\n    python manage.py test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJaza%2Fflask-editablesite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJaza%2Fflask-editablesite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJaza%2Fflask-editablesite/lists"}