Skip to content

Commit

Permalink
Merge branch 'master' into frontend-release
Browse files Browse the repository at this point in the history
  • Loading branch information
ndepaola committed Feb 26, 2024
2 parents 95d9c5f + 30ec72b commit a66e8e2
Show file tree
Hide file tree
Showing 70 changed files with 358 additions and 6,590 deletions.
12 changes: 1 addition & 11 deletions .github/actions/test-backend/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ runs:
- name: Start Elasticsearch
run: sudo systemctl start elasticsearch.service
shell: bash
- name: Install npm
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Compile frontend
working-directory: MPCAutofill
run: |
npm ci
npm run build
shell: bash
- name: Write Google Drive API credentials to file
uses: jsdaniell/[email protected]
with:
name: "client_secrets.json"
json: ${{ inputs.google-drive-api-key }}
dir: "MPCAutofill/"
- name: Run Django integration tests
- name: Run backend tests
run: |
cd MPCAutofill && pytest .
shell: bash
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ repos:
# backend
"Django~=4.2.3",
"django-cors-headers~=3.14.0",
"django-crispy-forms~=1.14.0",
"django-elasticsearch-dsl~=7.3.0",
"django-bulk-sync~=3.3.0",
"django-environ~=0.10.0",
"django-stubs-ext~=4.2.2",
"django-user-agents~=0.4.0",
"django-widget-tweaks~=1.4.12",
"google-api-python-client~=2.86",
"jsonschema~=4.20.0",
"Levenshtein~=0.23.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Collect Static" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Collect Static" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,6 +11,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="collectstatic --noinput" />
<option name="SHOW_COMMAND_LINE" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Run Migrations" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Dev Server" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,8 +11,9 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="migrate" />
<option name="PARAMETERS" value="runserver" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Import Sources" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Import Sources" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,6 +11,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="import_sources" />
<option name="SHOW_COMMAND_LINE" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Dev Server" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Run Migrations" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,8 +11,9 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="runserver" />
<option name="PARAMETERS" value="migrate" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Update DFCs" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Update DFCs" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,6 +11,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="update_dfcs" />
<option name="SHOW_COMMAND_LINE" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Web Project - Update Database" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="Backend - Update Database" type="PythonConfigurationType" factoryName="Python">
<module name="mpc-autofill" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -11,6 +11,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/MPCAutofill/manage.py" />
<option name="PARAMETERS" value="update_database" />
<option name="SHOW_COMMAND_LINE" value="false" />
Expand Down
19 changes: 0 additions & 19 deletions .run/Frontend - Build (Dev).run.xml

This file was deleted.

12 changes: 12 additions & 0 deletions .run/Frontend - Dev Server.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Frontend - Dev Server" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/frontend/package.json" />
<command value="run" />
<scripts>
<script value="dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
19 changes: 0 additions & 19 deletions .run/Web Project - Build Frontend (Dev).run.xml

This file was deleted.

18 changes: 0 additions & 18 deletions MPCAutofill/.eslintrc.js

This file was deleted.

6 changes: 0 additions & 6 deletions MPCAutofill/MPCAutofill/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
"django.contrib.staticfiles",
"django.contrib.postgres",
"django_elasticsearch_dsl",
"crispy_forms",
"django_user_agents",
"widget_tweaks",
"corsheaders",
]

Expand All @@ -86,7 +83,6 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_user_agents.middleware.UserAgentMiddleware",
]

CORS_ALLOWED_ORIGINS = env.list(
Expand Down Expand Up @@ -115,8 +111,6 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"cardpicker.context_processors.add_site_info",
"cardpicker.context_processors.common_info",
],
},
},
Expand Down
1 change: 0 additions & 1 deletion MPCAutofill/cardpicker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

DATE_FORMAT = "jS F, Y"
DEFAULT_LANGUAGE = pycountry.languages.get(alpha_2="EN")
PAGE_SIZE = 10

NEW_CARDS_PAGE_SIZE = 12
NEW_CARDS_DAYS = 14
Expand Down
32 changes: 0 additions & 32 deletions MPCAutofill/cardpicker/context_processors.py

This file was deleted.

66 changes: 1 addition & 65 deletions MPCAutofill/cardpicker/documents.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from typing import Any

from django_elasticsearch_dsl import Document, fields
from django_elasticsearch_dsl.registries import registry
from elasticsearch_dsl import analyzer

from django.utils import dateformat

from cardpicker.constants import DATE_FORMAT
from cardpicker.models import Card

# custom elasticsearch analysers are configured here to add the `asciifolding` filter, which handles accents:
Expand All @@ -15,45 +10,10 @@
precise_analyser = analyzer("precise_analyser", tokenizer="keyword", filter=["apostrophe", "lowercase", "asciifolding"])
fuzzy_analyser = analyzer("fuzzy_analyser", tokenizer="standard", filter=["apostrophe", "lowercase", "asciifolding"])

# region new API

# when the old (django template-based) UI is fully decommissioned, we can reduce the amount of data stored in
# elasticsearch by replacing the code in the `old API` region below with this code.


# @registry.register_document
# class CardSearch(Document):
# source = fields.TextField(attr="get_source_key", analyzer="keyword")
# searchq = fields.TextField(analyzer=fuzzy_analyser)
# searchq_keyword = fields.TextField(analyzer=precise_analyser)
# card_type = fields.KeywordField()
# language = fields.TextField(analyzer=precise_analyser) # case insensitivity is one less thing which can go wrong
# tags = fields.KeywordField() # all elasticsearch fields support arrays by default
#
# class Index:
# # name of the elasticsearch index
# name = "cards"
# # see Elasticsearch Indices API reference for available settings
# settings = {"number_of_shards": 5, "number_of_replicas": 0}
#
# class Django:
# model = Card
# fields = ["identifier", "priority", "dpi", "date", "size"]

# endregion

# region old API


@registry.register_document
class CardSearch(Document):
source = fields.TextField(attr="get_source_key", analyzer="keyword")
source_name = fields.TextField(attr="get_source_name")
source_external_link = fields.TextField(attr="get_source_external_link")
source_type = fields.TextField(attr="get_source_type")
download_link = fields.TextField(attr="get_download_link")
small_thumbnail_url = fields.TextField(attr="get_small_thumbnail_url")
medium_thumbnail_url = fields.TextField(attr="get_medium_thumbnail_url")
searchq = fields.TextField(analyzer=fuzzy_analyser)
searchq_keyword = fields.TextField(analyzer=precise_analyser)
card_type = fields.KeywordField()
Expand All @@ -68,28 +28,4 @@ class Index:

class Django:
model = Card
fields = ["identifier", "name", "priority", "source_verbose", "dpi", "extension", "date", "size"]

def to_dict(self, **kwargs: Any) -> dict[str, Any]:
return {
"identifier": self.identifier,
"card_type": self.card_type,
"name": self.name,
"priority": self.priority,
"source": self.source,
"source_name": self.source_name,
"source_external_link": self.source_external_link or "",
"source_verbose": self.source_verbose,
"source_type": self.source_type,
"dpi": self.dpi,
"searchq": self.searchq,
"extension": self.extension,
"date": dateformat.format(self.date, DATE_FORMAT),
"size": self.size,
"download_link": self.download_link,
"small_thumbnail_url": self.small_thumbnail_url,
"medium_thumbnail_url": self.medium_thumbnail_url,
}


# endregion
fields = ["identifier", "priority", "dpi", "date", "size"]
Loading

0 comments on commit a66e8e2

Please sign in to comment.