From 63c7f1cd1ac06fe64604530b45daa066aa647f4e Mon Sep 17 00:00:00 2001
From: Ragil Al Badrun Pasaribu <ragil.al@ui.ac.id>
Date: Wed, 16 Oct 2019 17:50:59 +0700
Subject: [PATCH] Migrate to mongo

---
 .gitignore                                    | 217 +-----------------
 README.md                                     |  32 ---
 {old => archive}/mod_grader_form.php          |   0
 .../uploadgrader/assignment.class.php         |   0
 .../uploadgrader/assignment.class.php_old     |   0
 {old => archive}/uploadgrader/exportexcel.php |   0
 .../lang/en_utf8/assignment_uploadgrader.php  |   0
 {old => archive}/uploadgrader/report-asli.php |   0
 {old => archive}/uploadgrader/report.php      |   0
 {old => archive}/uploadgrader/zipall.php      |   0
 gradernew/.gitignore                          | 155 ++++++++++++-
 gradernew/README.md                           |  13 ++
 gradernew/app/__init__.py                     |  17 ++
 gradernew/app/models.py                       |   1 +
 gradernew/main.py                             |  48 ----
 gradernew/models.py                           |   7 -
 gradernew/requirement.txt                     |   5 -
 gradernew/requirements.txt                    |   2 +
 18 files changed, 199 insertions(+), 298 deletions(-)
 delete mode 100644 README.md
 rename {old => archive}/mod_grader_form.php (100%)
 rename {old => archive}/uploadgrader/assignment.class.php (100%)
 rename {old => archive}/uploadgrader/assignment.class.php_old (100%)
 rename {old => archive}/uploadgrader/exportexcel.php (100%)
 rename {old => archive}/uploadgrader/lang/en_utf8/assignment_uploadgrader.php (100%)
 rename {old => archive}/uploadgrader/report-asli.php (100%)
 rename {old => archive}/uploadgrader/report.php (100%)
 rename {old => archive}/uploadgrader/zipall.php (100%)
 create mode 100644 gradernew/README.md
 create mode 100644 gradernew/app/__init__.py
 create mode 100644 gradernew/app/models.py
 delete mode 100644 gradernew/main.py
 delete mode 100644 gradernew/models.py
 delete mode 100644 gradernew/requirement.txt
 create mode 100644 gradernew/requirements.txt

diff --git a/.gitignore b/.gitignore
index e0f2ce8..fa694f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,209 +1,16 @@
 
-# Created by https://www.gitignore.io/api/macos,flask,python,virtualenv
-# Edit at https://www.gitignore.io/?templates=macos,flask,python,virtualenv
+# Created by https://www.gitignore.io/api/visualstudiocode
+# Edit at https://www.gitignore.io/?templates=visualstudiocode
 
-### Flask ###
-instance/*
-!instance/.gitignore
-.webassets-cache
+### VisualStudioCode ###
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
 
-### Flask.Python Stack ###
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
+### VisualStudioCode Patch ###
+# Ignore all local history of files
+.history
 
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-wheels/
-pip-wheel-metadata/
-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
-.hypothesis/
-.pytest_cache/
-
-# Translations
-*.mo
-*.pot
-
-# Scrapy stuff:
-.scrapy
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-
-# pyenv
-.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
-
-# celery beat schedule file
-celerybeat-schedule
-
-# SageMath parsed files
-*.sage.py
-
-# Spyder project settings
-.spyderproject
-.spyproject
-
-# Rope project settings
-.ropeproject
-
-# Mr Developer
-.mr.developer.cfg
-.project
-.pydevproject
-
-# mkdocs documentation
-/site
-
-# mypy
-.mypy_cache/
-.dmypy.json
-dmypy.json
-
-# Pyre type checker
-.pyre/
-
-### macOS ###
-# General
-.DS_Store
-.AppleDouble
-.LSOverride
-
-# Icon must end with two \r
-Icon
-
-# Thumbnails
-._*
-
-# Files that might appear in the root of a volume
-.DocumentRevisions-V100
-.fseventsd
-.Spotlight-V100
-.TemporaryItems
-.Trashes
-.VolumeIcon.icns
-.com.apple.timemachine.donotpresent
-
-# Directories potentially created on remote AFP share
-.AppleDB
-.AppleDesktop
-Network Trash Folder
-Temporary Items
-.apdisk
-
-### Python ###
-# Byte-compiled / optimized / DLL files
-
-# C extensions
-
-# Distribution / packaging
-
-# 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.
-
-# Installer logs
-
-# Unit test / coverage reports
-
-# Translations
-
-# Scrapy stuff:
-
-# Sphinx documentation
-
-# PyBuilder
-
-# pyenv
-
-# 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.
-
-# celery beat schedule file
-
-# SageMath parsed files
-
-# Spyder project settings
-
-# Rope project settings
-
-# Mr Developer
-
-# mkdocs documentation
-
-# mypy
-
-# Pyre type checker
-
-### VirtualEnv ###
-# Virtualenv
-# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
-[Bb]in
-[Ii]nclude
-[Ll]ib
-[Ll]ib64
-[Ll]ocal
-[Ss]cripts
-pyvenv.cfg
-.env
-.venv
-env/
-venv/
-ENV/
-env.bak/
-venv.bak/
-pip-selfcheck.json
-
-# End of https://www.gitignore.io/api/macos,flask,python,virtualenv
+# End of https://www.gitignore.io/api/visualstudiocode
diff --git a/README.md b/README.md
deleted file mode 100644
index 735f0b8..0000000
--- a/README.md
+++ /dev/null
@@ -1,32 +0,0 @@
-# Readme Grader Next Generation
-
-## Manual untuk menjalankan Grader Next Generation
-
-1. Masuk ke dalam direktori /gradernew
-
-2. Buat sebuah virtual environment python3 menggunakan command berikut, `python3 -m venv env`
-
-3. Bila anda menggunakan linux, aktivasi environment python3 yang baru saja anda buat dengan cara menjalankan command, `source env/bin/activate`.
-
-4. Kemudian install semua requirement yang berada di dalam `gradernew/requirement.txt` dengan cara menjalankan command berikut, `pip3 install -r requirement.txt`.
-
-5. Bila terdapat error di beberapa command, mohon beri tahu developer agar bisa ditroubleshoot dan dokumentasi.
-
-6. Setelah itu, mohon buat sebuah file .env di dalam /gradernew. Di dalam file ini, adalah definisi environment variable yang akan digunakan oleh flask. Di antara environment variable tersebut adalah,
-
-Nama Environment Variable | Deskripsi Value
----|---
-FLASK_APP | Diisi dengan nama file yang ada di dalam direktori /gradernew yang akan menjadi entry point dari flask. Misalnya, `FLASK_APP=main.py`.
-
-7. Untuk menjalankan aplikasi, buka bash/command prompt dengan environment sedang menyala (`source env/bin/activate` di atas), dan jalankan `flask run`.
-
-
-## Environment Variables used
-
-Name | Description | Example
----|---|---
-FLASKAPP | The entry point for the application. |FLASK_APP=main.py
-POSTGRES_URL | URL for the postgres database. |POSTGRES_URL=localhost:32768
-POSTGRES_DATABASE_NAME | The name of the database being used. | POSTGRES_DATABASE_NAME=postgres
-POSTGRES_USERNAME | Username used to access the database. | POSTGRES_USERNAME=postgres
-POSTGRES_PASSWORD | The password used with the username to access the database. | POSTGRES_PASSWORD=lmao123
\ No newline at end of file
diff --git a/old/mod_grader_form.php b/archive/mod_grader_form.php
similarity index 100%
rename from old/mod_grader_form.php
rename to archive/mod_grader_form.php
diff --git a/old/uploadgrader/assignment.class.php b/archive/uploadgrader/assignment.class.php
similarity index 100%
rename from old/uploadgrader/assignment.class.php
rename to archive/uploadgrader/assignment.class.php
diff --git a/old/uploadgrader/assignment.class.php_old b/archive/uploadgrader/assignment.class.php_old
similarity index 100%
rename from old/uploadgrader/assignment.class.php_old
rename to archive/uploadgrader/assignment.class.php_old
diff --git a/old/uploadgrader/exportexcel.php b/archive/uploadgrader/exportexcel.php
similarity index 100%
rename from old/uploadgrader/exportexcel.php
rename to archive/uploadgrader/exportexcel.php
diff --git a/old/uploadgrader/lang/en_utf8/assignment_uploadgrader.php b/archive/uploadgrader/lang/en_utf8/assignment_uploadgrader.php
similarity index 100%
rename from old/uploadgrader/lang/en_utf8/assignment_uploadgrader.php
rename to archive/uploadgrader/lang/en_utf8/assignment_uploadgrader.php
diff --git a/old/uploadgrader/report-asli.php b/archive/uploadgrader/report-asli.php
similarity index 100%
rename from old/uploadgrader/report-asli.php
rename to archive/uploadgrader/report-asli.php
diff --git a/old/uploadgrader/report.php b/archive/uploadgrader/report.php
similarity index 100%
rename from old/uploadgrader/report.php
rename to archive/uploadgrader/report.php
diff --git a/old/uploadgrader/zipall.php b/archive/uploadgrader/zipall.php
similarity index 100%
rename from old/uploadgrader/zipall.php
rename to archive/uploadgrader/zipall.php
diff --git a/gradernew/.gitignore b/gradernew/.gitignore
index 2eea525..c8c8ca5 100644
--- a/gradernew/.gitignore
+++ b/gradernew/.gitignore
@@ -1 +1,154 @@
-.env
\ No newline at end of file
+
+# Created by https://www.gitignore.io/api/macos,flask,visualstudiocode
+# Edit at https://www.gitignore.io/?templates=macos,flask,visualstudiocode
+
+### Flask ###
+instance/*
+!instance/.gitignore
+.webassets-cache
+
+### Flask.Python Stack ###
+# 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/
+pip-wheel-metadata/
+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
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# pyenv
+.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
+
+# celery beat schedule file
+celerybeat-schedule
+
+# SageMath parsed files
+*.sage.py
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+### macOS ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### VisualStudioCode ###
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+
+### VisualStudioCode Patch ###
+# Ignore all local history of files
+.history
+
+# End of https://www.gitignore.io/api/macos,flask,visualstudiocode
diff --git a/gradernew/README.md b/gradernew/README.md
new file mode 100644
index 0000000..9c92255
--- /dev/null
+++ b/gradernew/README.md
@@ -0,0 +1,13 @@
+# Grader New
+
+## How
+
+1. Buat sebuah virtual environment `python3` menggunakan command berikut `python3 -m venv env` atau sejenisnya
+
+2. Bila anda menggunakan linux, aktivasi environment `python3` yang baru saja anda buat dengan cara menjalankan command `source env/bin/activate`
+
+3. Kemudian install semua requirement yang berada di dalam `requirements.txt` dengan cara menjalankan command berikut, `pip install -r requirements.txt`.
+
+4. Bila terdapat error di beberapa command, mohon beri tahu developer agar bisa di-troubleshoot dan dokumentasi.
+
+5. Setelah itu, buat sebuah folder dengan nama `instance` yang didalamnya terdapat file kosong yang bernama `config.cfg`. File ini nantinya digunakan sebagai file konfigurasi saat di production
diff --git a/gradernew/app/__init__.py b/gradernew/app/__init__.py
new file mode 100644
index 0000000..7782a2d
--- /dev/null
+++ b/gradernew/app/__init__.py
@@ -0,0 +1,17 @@
+from flask import Flask
+from flask_mongoengine import MongoEngine
+
+
+app = Flask(__name__, instance_relative_config=True)
+
+# config vars
+app.config['MONGODB_DB'] = 'sofita'
+app.config['MONGODB_HOST'] = '127.0.0.1'
+app.config['MONGODB_PORT'] = 27017
+app.config['MONGODB_USERNAME'] = 'sofita'
+app.config['MONGODB_PASSWORD'] = 'haisofita'
+
+# config from file
+app.config.from_pyfile("config.cfg")
+
+MongoEngine(app)
diff --git a/gradernew/app/models.py b/gradernew/app/models.py
new file mode 100644
index 0000000..7a13e78
--- /dev/null
+++ b/gradernew/app/models.py
@@ -0,0 +1 @@
+# insert the models here
diff --git a/gradernew/main.py b/gradernew/main.py
deleted file mode 100644
index debbf48..0000000
--- a/gradernew/main.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# Start the app
-from flask_sqlalchemy import SQLAlchemy
-from flask import Flask, escape, request
-from os import environ
-
-# Start the database
-app = Flask(__name__)
-
-
-def get_db_configured_url():
-    url = environ.get('POSTGRES_URL', default=None)
-    database_name = environ.get('POSTGRES_DATABASE_NAME', default=None)
-    username = environ.get('POSTGRES_USERNAME', default=None)
-    password = environ.get('POSTGRES_PASSWORD', default="")
-
-    # "postgresql://postgres:@localhost:32768/postgres" sebagai contoh
-    return f"postgresql://{username}:{password}@{url}/{database_name}"
-
-
-app.config['SQLALCHEMY_DATABASE_URI'] = get_db_configured_url()
-db = SQLAlchemy(app)
-from gradernew.models import *
-
-"""
-Use this by using `flask initdb`. Will initialize the database.
-
-TODO: This is a very early version of it, make sure you could do
-migrations here. Right now, it will only create tables and column
-on models.py or anything that's extending `db.models`.
-"""
-@app.cli.command('initdb')
-def resetdb_command():
-    db.create_all()
-
-# TODO move to a new file that handles controller. We're going Controller - Model here. With service and stuff.
-@app.route('/')
-def all_test_here():
-    result_declarative = File.query.all()
-    
-    result_translated = []
-    for j in result_declarative:
-        i: File = j
-        result_translated.append({
-            'id':i.id,
-            'name':i.name
-        })
-    
-    return {'yuh': result_translated}
diff --git a/gradernew/models.py b/gradernew/models.py
deleted file mode 100644
index d5999a2..0000000
--- a/gradernew/models.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from gradernew.main import db
-
-
-class File(db.Model):
-    __tablename__ = 'file'
-    id = db.Column(db.Integer, primary_key=True)
-    name = db.Column(db.String(200))
diff --git a/gradernew/requirement.txt b/gradernew/requirement.txt
deleted file mode 100644
index add01e0..0000000
--- a/gradernew/requirement.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-flask == 1.1.1
-psycopg2 == 2.8.3
-Flask-SQLAlchemy == 2.4.1
-Flask-Migrate == 2.5.2
-python-dotenv == 0.10.3
\ No newline at end of file
diff --git a/gradernew/requirements.txt b/gradernew/requirements.txt
new file mode 100644
index 0000000..85305ad
--- /dev/null
+++ b/gradernew/requirements.txt
@@ -0,0 +1,2 @@
+Flask==1.1.1
+flask-mongoengine==0.9.5
-- 
GitLab