Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Aug 18, 2024
0 parents commit e0a5f9e
Show file tree
Hide file tree
Showing 17 changed files with 631 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci
on:
push:
branches:
- main
jobs:
tasks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Tests
uses: fluentci-io/setup-fluentci@v5
with:
wasm: true
plugin: mongo
args: |
start
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: |
fluentci run --wasm devbox run pip install -r requirements.txt
devbox run python run.py &
sleep 3
fluentci run --wasm devbox run python -m unittest
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DB: mongodb://localhost:27017/tasks
PORT: 5000
176 changes: 176 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023 Tsiry Sandratraina <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"packages": [
"python310",
"python310Packages.pip"
],
"shell": {
"init_hook": ". $VENV_DIR/bin/activate"
}
}
40 changes: 40 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"lockfile_version": "1",
"packages": {
"python310": {
"plugin_version": "0.0.3",
"resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#python310",
"source": "nixpkg",
"systems": {
"x86_64-linux": {
"outputs": [
{
"path": "/nix/store/s6fgyqbk8vn1014daznm5kqx90xdn86x-python3-3.10.13",
"default": true
}
]
}
}
},
"python310Packages.pip": {
"plugin_version": "0.0.2",
"resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#python310Packages.pip",
"source": "nixpkg",
"systems": {
"x86_64-linux": {
"outputs": [
{
"path": "/nix/store/96zrmllll78k3zf6zyxyyfzpcihf1svd-python3.10-pip-23.2.1",
"default": true
},
{
"name": "man",
"path": "/nix/store/1y54g9y4l1cifs9f2lhkyz8xwjh26qgs-python3.10-pip-23.2.1-man",
"default": true
}
]
}
}
}
}
}
17 changes: 17 additions & 0 deletions fluentciflask/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Flask, flash
from flask_pymongo import PyMongo
import os

app = Flask('__name__', template_folder="./fluentciflask/templates/")
app.config['SECRET_KEY'] = 'b6b462cf486aa21eee5719bf931a792e'
app.config["MONGO_URI"] = os.environ.get('DB') or os.environ.get('MONGODB_URI')

try:
mongo = PyMongo(app)
except mongo.errors.ServerSelectionTimeoutError as err:
flash(f'MongoDB server is not running', 'error')

from fluentciflask import routes

app.register_error_handler(404, routes.page_not_found)
app.register_error_handler(500, routes.internal_server_error)
8 changes: 8 additions & 0 deletions fluentciflask/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, DateTimeField, SubmitField
from wtforms.validators import DataRequired

class CreateTaskForm(FlaskForm):
task_title = StringField('Task Title', validators=[DataRequired()])
task_description = TextAreaField('Task Description')
task_submit = SubmitField('Create Task')
88 changes: 88 additions & 0 deletions fluentciflask/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from flask import render_template, flash, request, redirect, url_for, jsonify
import datetime
from bson.objectid import ObjectId
from fluentciflask import app, mongo
from fluentciflask.forms import CreateTaskForm


@app.route('/')
@app.route('/task/all')
def tasks_all():
tasks_data = []
if mongo:
tasks = mongo.db.tasks.find()
if tasks:
for task in tasks:
print(task)
tasks_data.append({'task_id': task['_id'], 'task_title': task['task_title'], 'task_description': task['task_description'],
'task_created_at': task['task_created_at']})
return render_template('tasks_all.html', tasks= tasks_data, title='All Tasks')


@app.route('/task/new', methods = ['GET', 'POST'])
def task_new():
form = CreateTaskForm()
if form.validate_on_submit():
task_title = form.task_title.data
task_description = form.task_description.data
task_created_at = datetime.datetime.now()
mongo.db.tasks.insert_one({'task_title': task_title, 'task_description': task_description,
'task_created_at': task_created_at})
flash(f'Task { form.task_title.data } has been created successfully!', 'success')
return redirect(url_for('tasks_all'))
return render_template('task_create.html', title='Create New Task', form=form, operation='create')


@app.route('/task/<task_id>', methods = ['GET'])
def task_view(task_id):
if len(task_id) == 24:
task = mongo.db.tasks.find_one({'_id': ObjectId(task_id)})
if task:
return render_template('task.html', task = [task], title='Task: {0}'.format(task['task_title']))
else:
return render_template('404.html')
else:
return render_template('404.html')


@app.route('/task/<task_id>/update', methods = ['GET', 'POST'])
def task_update(task_id):
if len(task_id) == 24:
task_to_update = mongo.db.tasks.find_one({'_id': ObjectId(task_id)})
if task_to_update:
form = CreateTaskForm()
if form.validate_on_submit():
mongo.db.tasks.update_one({"_id": ObjectId(task_id)},
{ '$set' : {"task_title": form.task_title.data,
"task_description": form.task_description.data,
"task_created_at": datetime.datetime.now()
}
},
upsert=False)
flash(f'Task has been updated', 'success')
return redirect(url_for('task_view', task_id=ObjectId(task_id)))
elif request.method == 'GET':
form.task_title.data = task_to_update['task_title']
form.task_description.data = task_to_update['task_description']
form.task_submit.data = 'Update Task'
return render_template('task_create.html', title='Update task: {0}'.format(task_to_update['task_title']),
form=form, operation='update')
else:
return render_template('404.html')


@app.route('/task/<task_id>/delete', methods = ['POST'])
def task_delete(task_id):
mongo.db.tasks.remove({"_id": ObjectId(task_id)})
flash(f'Task has been deleted sucessfully', 'success')
return redirect(url_for('tasks_all'))


@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404

@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'), 500

Loading

0 comments on commit e0a5f9e

Please sign in to comment.