This repository was archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Add reporting and quote hiding #60
Merged
mxmeinhold
merged 16 commits into
ComputerScienceHouse:master
from
mxmeinhold:reporting-and-hiding
Nov 17, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eda11a1
Create DB migrations
mxmeinhold bf96a8c
Define report table
mxmeinhold f8d62c2
Hide hidden quotes
mxmeinhold 2c5e74b
Add Report, Hide, and Review Functions
jabbate19 eb39dd4
Pylint Fixes
jabbate19 e0c0dea
Working Fix to LDAP Docstring
jabbate19 85ac2a6
Syntax and Model Repair to Reports
jabbate19 4bcf0d6
Add Report Path for Form
jabbate19 fcd6e9d
Default Report Reason"
jabbate19 abf86be
Fix Nesting and Styling
jabbate19 906f37d
Comment and HTML Code Fixes
jabbate19 91c29eb
JS Repairs with Hidden
jabbate19 4497aa2
Pin requirements
jabbate19 7cffc91
Newlines
jabbate19 66daf7c
409 File
jabbate19 a3cb5fb
Reformat and reword migrations readme
mxmeinhold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ | |
| app.run(host=app.config['IP'], port=app.config['PORT'], threaded = False) | ||
|
|
||
| application = app | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ## What are Alembic and migrations? | ||
| Migrations give a versioned history of changes to the SQL Schema for this project. | ||
| A `revision` or `migration` defines changes to the structure of the database (such as adding/dropping tables or columns), as well as procedures for migrating existing data to the new structure. Migrations allow for safe(ish) rollbacks, and make it easier to make incremental changes to the database. | ||
|
|
||
| ## Applying migrations | ||
| Once you have your db URI in `config.py`, run `flask db upgrade` to bring the db up to the latest revision. | ||
|
|
||
| ## Creating new revisions | ||
| When you change `models.py`, you'll need to make a new migration. | ||
| Run `flask db revision -m "<descriptive title>"` to autogenerate one. | ||
| You should go manually inspect the created revision to make sure it does what you expect. | ||
| Once you've got your changes all set, be sure to commit the migration file in the same commit as your changes to `models.py` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # A generic, single database configuration. | ||
|
|
||
| [alembic] | ||
| # path to migration scripts | ||
| script_location = migrations | ||
|
|
||
| # template used to generate migration files | ||
| # file_template = %%(rev)s_%%(slug)s | ||
|
|
||
| # timezone to use when rendering the date | ||
| # within the migration file as well as the filename. | ||
| # string value is passed to dateutil.tz.gettz() | ||
| # leave blank for localtime | ||
| # timezone = | ||
|
|
||
| # max length of characters to apply to the | ||
| # "slug" field | ||
| #truncate_slug_length = 40 | ||
|
|
||
| # set to 'true' to run the environment during | ||
| # the 'revision' command, regardless of autogenerate | ||
| # revision_environment = false | ||
|
|
||
| # set to 'true' to allow .pyc and .pyo files without | ||
| # a source .py file to be detected as revisions in the | ||
| # versions/ directory | ||
| # sourceless = false | ||
|
|
||
| # version location specification; this defaults | ||
| # to migrations/versions. When using multiple version | ||
| # directories, initial revisions must be specified with --version-path | ||
| # version_locations = %(here)s/bar %(here)s/bat migrations/versions | ||
|
|
||
| # the output encoding used when revision files | ||
| # are written from script.py.mako | ||
| # output_encoding = utf-8 | ||
|
|
||
| sqlalchemy.url = driver://user:pass@localhost/dbname | ||
|
|
||
|
|
||
| # Logging configuration | ||
| [loggers] | ||
| keys = root,sqlalchemy,alembic | ||
|
|
||
| [handlers] | ||
| keys = console | ||
|
|
||
| [formatters] | ||
| keys = generic | ||
|
|
||
| [logger_root] | ||
| level = WARN | ||
| handlers = console | ||
| qualname = | ||
|
|
||
| [logger_sqlalchemy] | ||
| level = WARN | ||
| handlers = | ||
| qualname = sqlalchemy.engine | ||
|
|
||
| [logger_alembic] | ||
| level = INFO | ||
| handlers = | ||
| qualname = alembic | ||
|
|
||
| [handler_console] | ||
| class = StreamHandler | ||
| args = (sys.stderr,) | ||
| level = NOTSET | ||
| formatter = generic | ||
|
|
||
| [formatter_generic] | ||
| format = %(levelname)-5.5s [%(name)s] %(message)s | ||
| datefmt = %H:%M:%S | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| from __future__ import with_statement | ||
|
|
||
| import logging | ||
| from logging.config import fileConfig | ||
|
|
||
| from flask import current_app | ||
|
|
||
| from alembic import context | ||
|
|
||
| # this is the Alembic Config object, which provides | ||
| # access to the values within the .ini file in use. | ||
| config = context.config | ||
|
|
||
| # Interpret the config file for Python logging. | ||
| # This line sets up loggers basically. | ||
| fileConfig(config.config_file_name) | ||
| logger = logging.getLogger('alembic.env') | ||
|
|
||
| # add your model's MetaData object here | ||
| # for 'autogenerate' support | ||
| # from myapp import mymodel | ||
| # target_metadata = mymodel.Base.metadata | ||
| config.set_main_option( | ||
| 'sqlalchemy.url', | ||
| str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) | ||
| target_metadata = current_app.extensions['migrate'].db.metadata | ||
|
|
||
| # other values from the config, defined by the needs of env.py, | ||
| # can be acquired: | ||
| # my_important_option = config.get_main_option("my_important_option") | ||
| # ... etc. | ||
|
|
||
|
|
||
| def run_migrations_offline(): | ||
| """Run migrations in 'offline' mode. | ||
|
|
||
| This configures the context with just a URL | ||
| and not an Engine, though an Engine is acceptable | ||
| here as well. By skipping the Engine creation | ||
| we don't even need a DBAPI to be available. | ||
|
|
||
| Calls to context.execute() here emit the given string to the | ||
| script output. | ||
|
|
||
| """ | ||
| url = config.get_main_option("sqlalchemy.url") | ||
| context.configure( | ||
| url=url, target_metadata=target_metadata, literal_binds=True | ||
| ) | ||
|
|
||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
|
|
||
|
|
||
| def run_migrations_online(): | ||
| """Run migrations in 'online' mode. | ||
|
|
||
| In this scenario we need to create an Engine | ||
| and associate a connection with the context. | ||
|
|
||
| """ | ||
|
|
||
| # this callback is used to prevent an auto-migration from being generated | ||
| # when there are no changes to the schema | ||
| # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html | ||
| def process_revision_directives(context, revision, directives): | ||
| if getattr(config.cmd_opts, 'autogenerate', False): | ||
| script = directives[0] | ||
| if script.upgrade_ops.is_empty(): | ||
| directives[:] = [] | ||
| logger.info('No changes in schema detected.') | ||
|
|
||
| connectable = current_app.extensions['migrate'].db.engine | ||
|
|
||
| with connectable.connect() as connection: | ||
| context.configure( | ||
| connection=connection, | ||
| target_metadata=target_metadata, | ||
| process_revision_directives=process_revision_directives, | ||
| **current_app.extensions['migrate'].configure_args | ||
| ) | ||
|
|
||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
|
|
||
|
|
||
| if context.is_offline_mode(): | ||
| run_migrations_offline() | ||
| else: | ||
| run_migrations_online() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """${message} | ||
|
|
||
| Revision ID: ${up_revision} | ||
| Revises: ${down_revision | comma,n} | ||
| Create Date: ${create_date} | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| ${imports if imports else ""} | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = ${repr(up_revision)} | ||
| down_revision = ${repr(down_revision)} | ||
| branch_labels = ${repr(branch_labels)} | ||
| depends_on = ${repr(depends_on)} | ||
|
|
||
|
|
||
| def upgrade(): | ||
| ${upgrades if upgrades else "pass"} | ||
|
|
||
|
|
||
| def downgrade(): | ||
| ${downgrades if downgrades else "pass"} | ||
|
|
25 changes: 25 additions & 0 deletions
25
migrations/versions/3b8a4c7fbcc2_report_reviewed_column_added.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Report Reviewed Column Added | ||
|
|
||
| Revision ID: 3b8a4c7fbcc2 | ||
| Revises: 76898f8ac346 | ||
| Create Date: 2021-11-07 22:31:04.835460 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '3b8a4c7fbcc2' | ||
| down_revision = '76898f8ac346' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.add_column('report', sa.Column('reviewed', sa.Boolean(), nullable=False, default=False)) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_column('report', 'reviewed') | ||
|
|
||
|
mxmeinhold marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Initial schema | ||
|
|
||
| Revision ID: 4f95c173f1d9 | ||
| Revises: | ||
| Create Date: 2021-04-23 01:02:40.157049 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '4f95c173f1d9' | ||
| down_revision = None | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('api_key', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('hash', sa.String(length=64), nullable=True), | ||
| sa.Column('owner', sa.String(length=80), nullable=True), | ||
| sa.Column('reason', sa.String(length=120), nullable=True), | ||
| sa.PrimaryKeyConstraint('id'), | ||
| sa.UniqueConstraint('hash'), | ||
| sa.UniqueConstraint('owner', 'reason', name='unique_key') | ||
| ) | ||
| op.create_table('quote', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('submitter', sa.String(length=80), nullable=False), | ||
| sa.Column('quote', sa.String(length=200), nullable=False), | ||
| sa.Column('speaker', sa.String(length=50), nullable=False), | ||
| sa.Column('quote_time', sa.DateTime(), nullable=False), | ||
| sa.PrimaryKeyConstraint('id'), | ||
| sa.UniqueConstraint('quote') | ||
| ) | ||
| op.create_table('vote', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('quote_id', sa.Integer(), nullable=True), | ||
| sa.Column('voter', sa.String(length=200), nullable=False), | ||
| sa.Column('direction', sa.Integer(), nullable=False), | ||
| sa.Column('updated_time', sa.DateTime(), nullable=False), | ||
| sa.ForeignKeyConstraint(['quote_id'], ['quote.id'], ), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_table('vote') | ||
| op.drop_table('quote') | ||
| op.drop_table('api_key') | ||
| # ### end Alembic commands ### | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Add reports | ||
|
|
||
| Revision ID: 76898f8ac346 | ||
| Revises: 4f95c173f1d9 | ||
| Create Date: 2021-04-23 01:18:03.934757 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '76898f8ac346' | ||
| down_revision = '4f95c173f1d9' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.create_table('report', | ||
| sa.Column('id', sa.Integer(), nullable=False, autoincrement=True), | ||
| sa.Column('quote_id', sa.Integer(), nullable=False), | ||
| sa.Column('reporter', sa.Text(), nullable=False), | ||
| sa.Column('reason', sa.Text(), nullable=False), | ||
| sa.ForeignKeyConstraint(['quote_id'], ['quote.id'], ), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
| op.add_column('quote', sa.Column('hidden', sa.Boolean(), nullable=False, default=False)) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_column('quote', 'hidden') | ||
| op.drop_table('report') | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.