Skip to content

Commit

Permalink
chore: remove martor dependency (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Oct 11, 2023
1 parent cbbcd14 commit 0df8008
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 412 deletions.
5 changes: 0 additions & 5 deletions basedosdados_api/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseAccountAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.db import models
from faker import Faker
from martor.widgets import AdminMartorWidget

from basedosdados_api.account.models import Account, BDGroup, BDGroupRole, BDRole, Career

Expand Down Expand Up @@ -224,9 +222,6 @@ class CareerAdmin(admin.ModelAdmin):


class BDGroupAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {"widget": AdminMartorWidget},
}
inlines = (BDGroupRoleInline,)
list_display = ("name", "description")
search_fields = ("name", "description")
Expand Down
10 changes: 0 additions & 10 deletions basedosdados_api/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,10 @@ class CoverageTableInline(admin.StackedInline):
readonly_fields = [
"id",
"area",
# "table",
]
inlines = [
DateTimeRangeInline,
]
# template = "admin/edit_inline/custom_coverage_model_inline.html"
# inlines = [
# TableCoverageFilter,
# ]
# formfield_overrides = {models.TextField: {"widget": AdminMartorWidget}}


################################################################################
Expand Down Expand Up @@ -494,7 +488,6 @@ def related_objects(self, obj):

related_objects.short_description = "Tables"

# formfield_overrides = {models.TextField: {"widget": AdminMartorWidget}}
readonly_fields = [
"id",
"full_slug",
Expand Down Expand Up @@ -680,7 +673,6 @@ class ColumnAdmin(TabbedTranslationAdmin):
list_filter = [
"table__dataset__organization__name",
]
# formfield_overrides = {models.TextField: {"widget": AdminMartorWidget}}


class ObservationLevelAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -722,7 +714,6 @@ class RawDataSourceAdmin(TabbedTranslationAdmin):
"languages",
"area_ip_address_required",
]
# formfield_overrides = {models.TextField: {"widget": AdminMartorWidget}}


class InformationRequestAdmin(TabbedTranslationAdmin):
Expand All @@ -732,7 +723,6 @@ class InformationRequestAdmin(TabbedTranslationAdmin):
autocomplete_fields = [
"dataset",
]
# formfield_overrides = {models.TextField: {"widget": AdminMartorWidget}}


class CoverageTypeAdminFilter(admin.SimpleListFilter):
Expand Down

This file was deleted.

140 changes: 12 additions & 128 deletions basedosdados_api/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@
# Application definition

INSTALLED_APPS = [
"modeltranslation",
"jazzmin",
"martor",
"modeltranslation",
#
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
"graphene_django",
"haystack",
"health_check",
"health_check.db",
#
"corsheaders",
"haystack",
"graphene_django",
"ordered_model",
"huey.contrib.djhuey",
# Apps
"basedosdados_api.account",
"basedosdados_api.core",
"basedosdados_api.api.v1",
Expand Down Expand Up @@ -131,7 +133,11 @@
# Media files
MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR / "media"
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
}
}

LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
Expand Down Expand Up @@ -281,128 +287,6 @@
"actions_sticky_top": True,
}


MARTOR_THEME = "bootstrap"
MARTOR_ENABLE_CONFIGS = {
"emoji": "true", # to enable/disable emoji icons.
"imgur": "false", # to enable/disable imgur/custom uploader.
"mention": "false", # to enable/disable mention
"jquery": "true", # to include/revoke jquery (require for admin default django)
"living": "false", # to enable/disable live updates in preview
"spellcheck": "false", # to enable/disable spellcheck in form textareas
"hljs": "true", # to enable/disable hljs highlighting in preview
}
MARTOR_TOOLBAR_BUTTONS = [
"bold",
"italic",
"horizontal",
"heading",
"pre-code",
"blockquote",
"unordered-list",
"ordered-list",
"link",
"image-link",
"image-upload",
"emoji",
"direct-mention",
"toggle-maximize",
"help",
]
MARTOR_MARKDOWNIFY_FUNCTION = "martor.utils.markdownify" # default
MARTOR_MARKDOWNIFY_URL = "/martor/markdownify/" # default
MARTOR_MARKDOWN_EXTENSIONS = [
"markdown.extensions.extra",
"markdown.extensions.nl2br",
"markdown.extensions.smarty",
"markdown.extensions.fenced_code",
# Custom markdown extensions.
"martor.extensions.urlize",
"martor.extensions.del_ins", # ~~strikethrough~~ and ++underscores++
"martor.extensions.mention", # to parse markdown mention
"martor.extensions.emoji", # to parse markdown emoji
"martor.extensions.mdx_video", # to parse embed/iframe video
"martor.extensions.escape_html", # to handle the XSS vulnerabilities
]
MARTOR_MARKDOWN_EXTENSION_CONFIGS = {}
MARTOR_UPLOAD_URL = "" # Completely disable the endpoint
MARTOR_SEARCH_USERS_URL = "" # Completely disables the endpoint
MARTOR_MARKDOWN_BASE_EMOJI_URL = (
"https://github.githubassets.com/images/icons/emoji/" # default from github
)
ALLOWED_HTML_TAGS = [
"a",
"abbr",
"b",
"blockquote",
"br",
"cite",
"code",
"command",
"dd",
"del",
"dl",
"dt",
"em",
"fieldset",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"hr",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"label",
"legend",
"li",
"ol",
"optgroup",
"option",
"p",
"pre",
"small",
"span",
"strong",
"sub",
"sup",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"tr",
"u",
"ul",
]

# https://github.com/decal/werdlists/blob/master/html-words/html-attributes-list.txt
ALLOWED_HTML_ATTRIBUTES = [
"alt",
"class",
"color",
"colspan",
"datetime", # "data",
"height",
"href",
"id",
"name",
"reversed",
"rowspan",
"scope",
"src",
"style",
"title",
"type",
"width",
]

CSRF_COOKIE_HTTPONLY = False

DATA_UPLOAD_MAX_NUMBER_FIELDS = 20000
Expand Down
2 changes: 0 additions & 2 deletions basedosdados_api/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from basedosdados_api.settings.base import * # noqa
from basedosdados_api.utils import getenv

INSTALLED_APPS += ["django_extensions"] # noqa: F405

# CSRF
# https://docs.djangoproject.com/en/4.2/ref/csrf/
# https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS
Expand Down
6 changes: 5 additions & 1 deletion basedosdados_api/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@
GS_CREDENTIALS = service_account.Credentials.from_service_account_info(loads(GS_SERVICE_ACCOUNT))
GS_BUCKET_NAME = getenv("GCP_BUCKET_NAME")
GS_EXPIRATION = timedelta(seconds=604800)
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
STORAGES = {
"default": {
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
}
}
1 change: 0 additions & 1 deletion basedosdados_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def render_robots():
urlpatterns = [
re_path(r"^healthcheck/", include("health_check.urls")),
path("admin/", admin.site.urls),
path("martor/", include("martor.urls")),
path("account/", include("basedosdados_api.account.urls")),
path("api/", redirect_to_v1, name="api"),
path("api/v1/", redirect_to_v1_graphql),
Expand Down
Loading

0 comments on commit 0df8008

Please sign in to comment.