Skip to content
Snippets Groups Projects
Commit c64a64b4 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

remove IG sync tool, add pre-commit hooks

parent 7753df9a
Branches
No related tags found
No related merge requests found
Pipeline #13600 failed
Showing
with 81 additions and 82 deletions
default_language_version:
python: python3.11
exclude: snapshots/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: ^.*\.md$
- id: end-of-file-fixer
- id: debug-statements
- id: mixed-line-ending
args: [--fix=lf]
- id: detect-private-key
- id: check-merge-conflict
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
...@@ -17,8 +17,6 @@ RUN DATABASE_URL=postgres://x/x \ ...@@ -17,8 +17,6 @@ RUN DATABASE_URL=postgres://x/x \
SECRET_KEY=x \ SECRET_KEY=x \
ALLOWED_HOSTS=x \ ALLOWED_HOSTS=x \
CHOBOTNICE_RV_GID=x \ CHOBOTNICE_RV_GID=x \
INSTAGRAM_CLIENT_ID=x \
INSTAGRAM_CLIENT_SECRET=x \
python manage.py collectstatic --noinput --settings=rybicka.settings.production python manage.py collectstatic --noinput --settings=rybicka.settings.production
RUN bash -c "adduser --disabled-login --quiet --gecos app app && \ RUN bash -c "adduser --disabled-login --quiet --gecos app app && \
......
...@@ -11,6 +11,8 @@ help: ...@@ -11,6 +11,8 @@ help:
@echo "Setup:" @echo "Setup:"
@echo " venv Setup virtual environment" @echo " venv Setup virtual environment"
@echo " install Install dependencies to venv" @echo " install Install dependencies to venv"
@echo " install-hooks Install pre-commit hooks"
@echo " hooks Run pre-commit hooks manually"
@echo " build Build CSS and JS files" @echo " build Build CSS and JS files"
@echo "" @echo ""
@echo "Application:" @echo "Application:"
...@@ -34,6 +36,12 @@ build: venv ...@@ -34,6 +36,12 @@ build: venv
${VENV}/bin/npm run build ${VENV}/bin/npm run build
${VENV}/bin/python manage.py collectstatic --noinput --settings=${SETTINGS} ${VENV}/bin/python manage.py collectstatic --noinput --settings=${SETTINGS}
install-hooks:
pre-commit install --install-hooks
hooks:
pre-commit run -a
run: venv run: venv
${VENV}/bin/python manage.py runserver ${PORT} --settings=${SETTINGS} ${VENV}/bin/python manage.py runserver ${PORT} --settings=${SETTINGS}
......
...@@ -2,5 +2,5 @@ from django.apps import AppConfig ...@@ -2,5 +2,5 @@ from django.apps import AppConfig
class AutoServerResizeConfig(AppConfig): class AutoServerResizeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = "django.db.models.BigAutoField"
name = 'asset_server_resize' name = "asset_server_resize"
...@@ -6,8 +6,4 @@ from django_http_exceptions import HTTPExceptions ...@@ -6,8 +6,4 @@ from django_http_exceptions import HTTPExceptions
def index(request): def index(request):
return render( return render(request, "asset_server_resize/index.html", {})
request,
"asset_server_resize/index.html",
{}
)
...@@ -5,8 +5,5 @@ SECRET_KEY="%@=^sip3=tqn6d_-xvvidc1@-t0t3&*kab@vr4c4" ...@@ -5,8 +5,5 @@ SECRET_KEY="%@=^sip3=tqn6d_-xvvidc1@-t0t3&*kab@vr4c4"
CHOBOTNICE_API_URL="https://chobotnice.pirati.cz/graphql/" CHOBOTNICE_API_URL="https://chobotnice.pirati.cz/graphql/"
CHOBOTNICE_RV_GID="R3JvdXBUeXBlOjYyNQ==" CHOBOTNICE_RV_GID="R3JvdXBUeXBlOjYyNQ=="
INSTAGRAM_CLIENT_ID=3828083077418467
INSTAGRAM_CLIENT_SECRET=da7ea1af344e60ccd2bfcfa0f296b808
# Production settings # Production settings
ALLOWED_HOSTS="tools.pirati.cz" ALLOWED_HOSTS="tools.pirati.cz"
...@@ -2,5 +2,5 @@ from django.apps import AppConfig ...@@ -2,5 +2,5 @@ from django.apps import AppConfig
class MailSignatureConfig(AppConfig): class MailSignatureConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = "django.db.models.BigAutoField"
name = 'mail_signature' name = "mail_signature"
...@@ -2,8 +2,6 @@ from django.shortcuts import render ...@@ -2,8 +2,6 @@ from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
return render( return render(request, "mail_signature/index.html")
request,
"mail_signature/index.html"
)
...@@ -6,7 +6,7 @@ import sys ...@@ -6,7 +6,7 @@ import sys
def main(): def main():
"""Run administrative tasks.""" """Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rybicka.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rybicka.settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:
...@@ -18,5 +18,5 @@ def main(): ...@@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__': if __name__ == "__main__":
main() main()
...@@ -2,8 +2,6 @@ from django.shortcuts import render ...@@ -2,8 +2,6 @@ from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
return render( return render(request, "member_group_size_calc/index.html")
request,
"member_group_size_calc/index.html"
)
from django import template from django import template
register = template.Library() register = template.Library()
# https://stackoverflow.com/a/29664945 # https://stackoverflow.com/a/29664945
......
...@@ -5,9 +5,5 @@ from . import views ...@@ -5,9 +5,5 @@ from . import views
app_name = "rv_voting_calc" app_name = "rv_voting_calc"
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path( path("calculated-votes", views.get_calculated_votes, name="get_calculated_votes"),
"calculated-votes",
views.get_calculated_votes,
name="get_calculated_votes"
)
] ]
...@@ -8,15 +8,13 @@ import urllib.parse ...@@ -8,15 +8,13 @@ import urllib.parse
import gql import gql
import requests import requests
from gql.transport.exceptions import TransportQueryError
from gql.transport.requests import RequestsHTTPTransport
from django.conf import settings from django.conf import settings
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from django.shortcuts import render from django.shortcuts import render
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django_http_exceptions import HTTPExceptions from django_http_exceptions import HTTPExceptions
from gql.transport.exceptions import TransportQueryError
from gql.transport.requests import RequestsHTTPTransport
def get_options_by_member(source, rv_members) -> dict: def get_options_by_member(source, rv_members) -> dict:
...@@ -75,7 +73,7 @@ def index(request): ...@@ -75,7 +73,7 @@ def index(request):
"rv_members": rv_members, "rv_members": rv_members,
"keyed_rv_members": keyed_rv_members, "keyed_rv_members": keyed_rv_members,
"options_by_member": options_by_member, "options_by_member": options_by_member,
} },
) )
...@@ -143,7 +141,7 @@ def convert_rv_members_to_dict(source: list) -> dict: ...@@ -143,7 +141,7 @@ def convert_rv_members_to_dict(source: list) -> dict:
# Convert to username: {data} # Convert to username: {data}
rv_members[member["username"]] = { rv_members[member["username"]] = {
"displayName": member["displayName"], "displayName": member["displayName"],
"officialLastName": member["officialLastName"] "officialLastName": member["officialLastName"],
} }
return rv_members return rv_members
...@@ -218,7 +216,7 @@ def do_step_b_through_d( ...@@ -218,7 +216,7 @@ def do_step_b_through_d(
"options": options, "options": options,
"options_by_member": options_by_member, "options_by_member": options_by_member,
"options_with_support_count": options_with_support_count, "options_with_support_count": options_with_support_count,
"rv_members": rv_members "rv_members": rv_members,
} }
html_steps.append( html_steps.append(
...@@ -237,7 +235,7 @@ def do_step_b_through_d( ...@@ -237,7 +235,7 @@ def do_step_b_through_d(
) )
# Delete options without support and those marked for deletion. # Delete options without support and those marked for deletion.
for option_key in (options_without_support + options_marked_for_deletion): for option_key in options_without_support + options_marked_for_deletion:
options.pop(option_key, None) options.pop(option_key, None)
# If no options remain, show that there are no winners and end everything. # If no options remain, show that there are no winners and end everything.
...@@ -266,8 +264,7 @@ def do_step_b_through_d( ...@@ -266,8 +264,7 @@ def do_step_b_through_d(
# Sort options by their vote count. # Sort options by their vote count.
options = { options = {
key: value key: value
for key, value for key, value in sorted(
in sorted(
options.items(), options.items(),
reverse=True, reverse=True,
key=lambda option: option[1]["vote_count"], key=lambda option: option[1]["vote_count"],
...@@ -325,7 +322,7 @@ def do_step_b_through_d( ...@@ -325,7 +322,7 @@ def do_step_b_through_d(
"options": options, "options": options,
"options_by_member": options_by_member, "options_by_member": options_by_member,
"rv_members": rv_members, "rv_members": rv_members,
"randomly": True "randomly": True,
} }
html_steps.append( html_steps.append(
...@@ -352,8 +349,7 @@ def do_step_b_through_d( ...@@ -352,8 +349,7 @@ def do_step_b_through_d(
# Sort options by their vote count, with lowest ranking ones first. # Sort options by their vote count, with lowest ranking ones first.
options = { options = {
key: value key: value
for key, value for key, value in sorted(
in sorted(
options.items(), options.items(),
key=lambda option: option[1]["vote_count"], key=lambda option: option[1]["vote_count"],
) )
...@@ -404,9 +400,7 @@ def do_step_b_through_d( ...@@ -404,9 +400,7 @@ def do_step_b_through_d(
else: else:
# If there are multiple losing options, order them by the amount of # If there are multiple losing options, order them by the amount of
# ticket votes they have. # ticket votes they have.
losing_option_keys.sort( losing_option_keys.sort(key=lambda key: options[key]["ticket_count"])
key=lambda key: options[key]["ticket_count"]
)
# Delete the vote with the least ticket votes. There maybe more, but # Delete the vote with the least ticket votes. There maybe more, but
# those should be taken care of in the next iteration. # those should be taken care of in the next iteration.
...@@ -517,10 +511,9 @@ def get_calculated_votes(request): ...@@ -517,10 +511,9 @@ def get_calculated_votes(request):
continue continue
# Add this vote to the option's ticket votes. # Add this vote to the option's ticket votes.
options[option]["ticket_votes"].append({ options[option]["ticket_votes"].append(
"member": member, {"member": member, "other_acceptable": selected_options[1:]}
"other_acceptable": selected_options[1:] )
})
# Increase the vote and ticket vote counters. # Increase the vote and ticket vote counters.
options[option]["ticket_count"] += 1 options[option]["ticket_count"] += 1
options[option]["vote_count"] += 1 options[option]["vote_count"] += 1
...@@ -555,8 +548,7 @@ def get_calculated_votes(request): ...@@ -555,8 +548,7 @@ def get_calculated_votes(request):
# This is purely for aesthetic purpose. # This is purely for aesthetic purpose.
options = { options = {
key: value key: value
for key, value for key, value in sorted(
in sorted(
options.items(), options.items(),
reverse=True, reverse=True,
key=lambda option: option[1]["has_support"], key=lambda option: option[1]["has_support"],
...@@ -568,7 +560,7 @@ def get_calculated_votes(request): ...@@ -568,7 +560,7 @@ def get_calculated_votes(request):
"options_by_member": options_by_member, "options_by_member": options_by_member,
"rv_members": rv_members, "rv_members": rv_members,
"total_ticket_count": total_ticket_count, "total_ticket_count": total_ticket_count,
"has_support_treshold": has_support_treshold "has_support_treshold": has_support_treshold,
} }
html_steps.append( html_steps.append(
...@@ -598,8 +590,8 @@ def get_calculated_votes(request): ...@@ -598,8 +590,8 @@ def get_calculated_votes(request):
request.COOKIES.get( request.COOKIES.get(
"seed", "seed",
# If neither are set, generate a default. # If neither are set, generate a default.
base64.b64encode(secrets.token_bytes()).decode("utf-8") base64.b64encode(secrets.token_bytes()).decode("utf-8"),
) ),
) )
# Unquote the seed if it was found in the URL parameters # Unquote the seed if it was found in the URL parameters
...@@ -630,10 +622,7 @@ def get_calculated_votes(request): ...@@ -630,10 +622,7 @@ def get_calculated_votes(request):
response = render( response = render(
request, request,
"rv_voting_calc/combined_steps.html", "rv_voting_calc/combined_steps.html",
{ {"html_steps": "\n".join(html_steps), "md_steps": md_steps},
"html_steps": "\n".join(html_steps),
"md_steps": md_steps
}
) )
# Set the random seed cookie to the one used in the calculation. # Set the random seed cookie to the one used in the calculation.
......
...@@ -11,6 +11,6 @@ import os ...@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rybicka.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rybicka.settings")
application = get_asgi_application() application = get_asgi_application()
...@@ -37,7 +37,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") ...@@ -37,7 +37,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
# Server # Server
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# Application definition # Application definition
...@@ -46,14 +46,11 @@ INSTALLED_APPS = [ ...@@ -46,14 +46,11 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"webpack_loader", "webpack_loader",
"shared", "shared",
"member_group_size_calc", "member_group_size_calc",
"rv_voting_calc", "rv_voting_calc",
"mail_signature", "mail_signature",
"instagram_token",
"asset_server_resize", "asset_server_resize",
] ]
...@@ -64,7 +61,6 @@ MIDDLEWARE = [ ...@@ -64,7 +61,6 @@ MIDDLEWARE = [
"django.middleware.csrf.CsrfViewMiddleware", "django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware", "django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_http_exceptions.middleware.ExceptionHandlerMiddleware", "django_http_exceptions.middleware.ExceptionHandlerMiddleware",
"django_http_exceptions.middleware.ThreadLocalRequestMiddleware", "django_http_exceptions.middleware.ThreadLocalRequestMiddleware",
] ]
...@@ -92,9 +88,7 @@ WSGI_APPLICATION = "rybicka.wsgi.application" ...@@ -92,9 +88,7 @@ WSGI_APPLICATION = "rybicka.wsgi.application"
# Database # Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases # https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = { DATABASES = {"default": dj_database_url.config(conn_max_age=600)}
"default": dj_database_url.config(conn_max_age=600)
}
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
...@@ -127,8 +121,7 @@ WEBPACK_LOADER = { ...@@ -127,8 +121,7 @@ WEBPACK_LOADER = {
# Chobotnice # Chobotnice
CHOBOTNICE_API_URL = env.str( CHOBOTNICE_API_URL = env.str(
"CHOBOTNICE_API_URL", "CHOBOTNICE_API_URL", "https://chobotnice.pirati.cz/graphql/"
"https://chobotnice.pirati.cz/graphql/"
) )
CHOBOTNICE_RV_GID = env.str("CHOBOTNICE_RV_GID") CHOBOTNICE_RV_GID = env.str("CHOBOTNICE_RV_GID")
......
...@@ -19,7 +19,6 @@ urlpatterns = [ ...@@ -19,7 +19,6 @@ urlpatterns = [
path("vypocet-skupiny-clenu/", include("member_group_size_calc.urls")), path("vypocet-skupiny-clenu/", include("member_group_size_calc.urls")),
path("hlasovani-rv/", include("rv_voting_calc.urls")), path("hlasovani-rv/", include("rv_voting_calc.urls")),
path("emailove-podpisy/", include("mail_signature.urls")), path("emailove-podpisy/", include("mail_signature.urls")),
path("instagram/", include("instagram_token.urls")),
path("asset-server/", include("asset_server_resize.urls")), path("asset-server/", include("asset_server_resize.urls")),
path("", include("shared.urls")), path("", include("shared.urls")),
] ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment