EwetoyeIbrahim / Equimolar-Blog

A Flask Blog for publishing articles by multiple users
1 stars 0 forks source link

Equimolar-Blog

This is a flask blogging engine for publishing articles. A live implementation will be made available at Equimolar.com in the coming weeks. Here, will be going through the following in the content:

  1. The Problem
  2. Existing python-blog repos
  3. This Solution
  4. How to Use

The Problem:

I wanted to build a blog for publishing articles and some python programmes, thus, I may have a hard time using wordpress, which sounds like the simplest, in conjunction with my python codes. Why not fork one of the python-blog repos? After trying out alot of them, read more in the next section, none of them seems to solve my needs as stated below.

The needs that call for the development of the flask blog app, are listed below. Obviously, if this are not the features you needed, you may simply jump to the next section to see other available options built by some brilliant people, in fact there are alot out there you can pick from, so feel free to explore alot of other brilliant options out there depending on your needs.

List of the requirements

  1. Support Postings by Many Users.
  2. Article should support tagging
  3. Articles must be editable even after publishing
  4. One must be able to put posts in draft untill published
  5. Allow assigning of multiple rigths to the blog posters: In general, I need three rights.
    • Authour: Users will be able to write an article and edit only their articles
    • Editor: Anyone given this right will be able to create a new article, and edit all posts, even if it does not belong to them
    • Registrar: Will be able to add new users, assign rigths, and edit users details.
      Note: Users can be given multiple roles
  6. Posts should be written in markdown and I must be able to preview in real-time while editing. That is, I should be able open preview windows side-by-side with the markdown text-box.
  7. Articles must be searchable.
  8. Display related articles to the current article being read.
  9. Extendable for use in existing applications: Thus should be cotained in a blueprint to make things easy to whoever wants to port it into another application
  10. Must be able to host some light-weight files, which may be linked to from in the blog posts

Why not fork one of the python-blog repos

There are currently a gazillion number of already available python blog frameworks like, Flask-Blog, Flask-Blogging, Simple-Flask-Blog, and Weblog, which are all brilliant, but based on my needs, there is no single that ever address all my problems. For example, after trying out several of them, I short listed two, which were Flask-Bloogging and Weblog.

The Solution:

Equimolar-Blog was built based on the knowledge gained by trying out several of the programmes discussed earlier, just that they were modified to suit the needs. Equimolar-Blog is Flask blog solution that solves all the previously stated requirements using the simplest method possible. dependent upon a list of several publicly available codes:

  1. Flask-WTF : Form the forms
  2. Flask-Sqlalchemy : Provided an ORM based database
  3. Flask-Whooshalchemy3 : Provides the search fuctionality
  4. Flask-Security : Makes handling of accesses a deadly simple task
  5. Flask-Upload : Used to handle the file upload process
  6. Flask-Admin : For managing the database from the front-end
  7. Slugify : For generating valid slugs
  8. Markdown : Translates markdown content to human readable form
  9. Bootstrap4 : To make the website look gorgeous without stress.
  10. Bootstrap Markdown Editor (Krajee) : Handles the content editor

How to Use


Setting-up

  1. cd into the folder, on windows something like

    C:\Users\Ewetoye Ibrahim>> cd C:\path to the folder\Equimolar-Blog

  2. [Optional] Create a virtual environment and activate it

  3. Install the requirement file: python -m pip install requirement.txt

  4. [Optional] If you have change the database to something else other than sqlite3 configured, you should first make sure that the database exist, even if blank. But it is well-known that this is not required for sqlite3 databases as it will be created on the fly if not found at the specified location

Test mode:

  1. Setup the database. something like:

    C:\path to the folder\Equimolar-Blog>> python create_db.py

    Note: this should only be done on a test database; Never run this on procuction database!!!

    This step creates all the tables in the model; create the three rights (Authour, Editor, and Registrar); adds four dummy users:

    Username Email Password Rigth(s)
    Authour User authour@example.com password Authour
    Editor User editor@example.com password Editor
    Registrar User registrar@example.com password Registrar
    Owner User owner@example.com password Authour, Editor, Registrar

    As such, the create_db.py file should be run on a production database, as it will create the afore-mentioned usersin the database.

  2. Start the app from the command prompt: python run.py Now, your blog should be live at 127.0.0.1:5000

Production mode: There are two basic ways here: set the environment variable or type into run.py directly:

  1. Set the env variable:
    set CONFIG_NAME=production
    set FLASK_APP=run.py
    flask run

  2. Hardcode directly into run.py:

    • Open run.py

    • Edit the third line.
      from

      app = create_app(os.getenv('CONFIG_NAME', default='default'))

      to

      app = create_app('production')
    • Do python run.py

Creating an article

Visit /writter endpoint. e.g localhost:5000/writter

Editing an article

Visit the article, if you are either the one who posted the article or you have an Editor rigth, you will get to see an edit button at the top of article, click it and edit as needed.

First Released: 1/1/2020 by Ewetoye, Ibrahim