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
No related branches found
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 \
SECRET_KEY=x \
ALLOWED_HOSTS=x \
CHOBOTNICE_RV_GID=x \
INSTAGRAM_CLIENT_ID=x \
INSTAGRAM_CLIENT_SECRET=x \
python manage.py collectstatic --noinput --settings=rybicka.settings.production
RUN bash -c "adduser --disabled-login --quiet --gecos app app && \
......
......@@ -11,6 +11,8 @@ help:
@echo "Setup:"
@echo " venv Setup virtual environment"
@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 ""
@echo "Application:"
......@@ -34,6 +36,12 @@ build: venv
${VENV}/bin/npm run build
${VENV}/bin/python manage.py collectstatic --noinput --settings=${SETTINGS}
install-hooks:
pre-commit install --install-hooks
hooks:
pre-commit run -a
run: venv
${VENV}/bin/python manage.py runserver ${PORT} --settings=${SETTINGS}
......
......@@ -2,5 +2,5 @@ from django.apps import AppConfig
class AutoServerResizeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'asset_server_resize'
default_auto_field = "django.db.models.BigAutoField"
name = "asset_server_resize"
......@@ -6,8 +6,4 @@ from django_http_exceptions import HTTPExceptions
def index(request):
return render(
request,
"asset_server_resize/index.html",
{}
)
return render(request, "asset_server_resize/index.html", {})
......@@ -5,8 +5,5 @@ SECRET_KEY="%@=^sip3=tqn6d_-xvvidc1@-t0t3&*kab@vr4c4"
CHOBOTNICE_API_URL="https://chobotnice.pirati.cz/graphql/"
CHOBOTNICE_RV_GID="R3JvdXBUeXBlOjYyNQ=="
INSTAGRAM_CLIENT_ID=3828083077418467
INSTAGRAM_CLIENT_SECRET=da7ea1af344e60ccd2bfcfa0f296b808
# Production settings
ALLOWED_HOSTS="tools.pirati.cz"
......@@ -2,5 +2,5 @@ from django.apps import AppConfig
class MailSignatureConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'mail_signature'
default_auto_field = "django.db.models.BigAutoField"
name = "mail_signature"
......@@ -81,7 +81,7 @@
>
</div>
</div>
<div class="my-4">
Do každého emailu doporučujeme zadat max. 3 odkazy. Do těch
se počítají i ty na sociální sítě v podpisu.
......@@ -176,7 +176,7 @@
class="border border-gray-200 p-2 rounded-md grow w-full"
>
</div>
<div class="text-right">
<button id="generate" class="btn btn--icon" type="button">
<div class="btn__body-wrap">
......@@ -188,7 +188,7 @@
</button>
</div>
</form>
<div class="flex flex-col gap-3">
<section class="flex flex-col gap-4">
<div class="flex justify-between gap-3 items-center">
......
......@@ -2,8 +2,6 @@ from django.shortcuts import render
# Create your views here.
def index(request):
return render(
request,
"mail_signature/index.html"
)
return render(request, "mail_signature/index.html")
......@@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rybicka.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rybicka.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
......@@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()
......@@ -2,8 +2,6 @@ from django.shortcuts import render
# Create your views here.
def index(request):
return render(
request,
"member_group_size_calc/index.html"
)
return render(request, "member_group_size_calc/index.html")
gunicorn==20.1.0
gunicorn==20.1.0
whitenoise==6.3.0
......@@ -56,7 +56,7 @@
{% endfor %}
</ul>
</div>
<div>
<div class="flex items-center gap-3 justify-between mb-5">
<h2 class="text-2xl font-bebas">Výsledky</h2>
......@@ -76,7 +76,7 @@
class="flex flex-col gap-5"
id="result"
>
</ul>
<div class="mt-4 flex gap-4 md:justify-end justify-center">
<a
......@@ -97,7 +97,7 @@
</main>
{{ keyed_rv_members|json_script:"rv-members" }}
<script>
const VOTE_CALCULATION_ENDPOINT = "{% url "rv_voting_calc:get_calculated_votes" %}"
......
from django import template
register = template.Library()
# https://stackoverflow.com/a/29664945
......
......@@ -5,9 +5,5 @@ from . import views
app_name = "rv_voting_calc"
urlpatterns = [
path("", views.index, name="index"),
path(
"calculated-votes",
views.get_calculated_votes,
name="get_calculated_votes"
)
path("calculated-votes", views.get_calculated_votes, name="get_calculated_votes"),
]
......@@ -8,15 +8,13 @@ import urllib.parse
import gql
import requests
from gql.transport.exceptions import TransportQueryError
from gql.transport.requests import RequestsHTTPTransport
from django.conf import settings
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.template.loader import render_to_string
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:
......@@ -75,7 +73,7 @@ def index(request):
"rv_members": rv_members,
"keyed_rv_members": keyed_rv_members,
"options_by_member": options_by_member,
}
},
)
......@@ -143,7 +141,7 @@ def convert_rv_members_to_dict(source: list) -> dict:
# Convert to username: {data}
rv_members[member["username"]] = {
"displayName": member["displayName"],
"officialLastName": member["officialLastName"]
"officialLastName": member["officialLastName"],
}
return rv_members
......@@ -218,7 +216,7 @@ def do_step_b_through_d(
"options": options,
"options_by_member": options_by_member,
"options_with_support_count": options_with_support_count,
"rv_members": rv_members
"rv_members": rv_members,
}
html_steps.append(
......@@ -237,7 +235,7 @@ def do_step_b_through_d(
)
# 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)
# If no options remain, show that there are no winners and end everything.
......@@ -266,8 +264,7 @@ def do_step_b_through_d(
# Sort options by their vote count.
options = {
key: value
for key, value
in sorted(
for key, value in sorted(
options.items(),
reverse=True,
key=lambda option: option[1]["vote_count"],
......@@ -315,7 +312,7 @@ def do_step_b_through_d(
# randomly eliminate one and continue to the next iteration.
elif winner_count == len(options) and ticket_count_same:
eliminated_winner = random.choice(winning_option_keys)
options[eliminated_winner]["marked_for_deletion"] = True
context = {
......@@ -325,7 +322,7 @@ def do_step_b_through_d(
"options": options,
"options_by_member": options_by_member,
"rv_members": rv_members,
"randomly": True
"randomly": True,
}
html_steps.append(
......@@ -352,8 +349,7 @@ def do_step_b_through_d(
# Sort options by their vote count, with lowest ranking ones first.
options = {
key: value
for key, value
in sorted(
for key, value in sorted(
options.items(),
key=lambda option: option[1]["vote_count"],
)
......@@ -404,9 +400,7 @@ def do_step_b_through_d(
else:
# If there are multiple losing options, order them by the amount of
# ticket votes they have.
losing_option_keys.sort(
key=lambda key: options[key]["ticket_count"]
)
losing_option_keys.sort(key=lambda key: options[key]["ticket_count"])
# Delete the vote with the least ticket votes. There maybe more, but
# those should be taken care of in the next iteration.
......@@ -517,10 +511,9 @@ def get_calculated_votes(request):
continue
# Add this vote to the option's ticket votes.
options[option]["ticket_votes"].append({
"member": member,
"other_acceptable": selected_options[1:]
})
options[option]["ticket_votes"].append(
{"member": member, "other_acceptable": selected_options[1:]}
)
# Increase the vote and ticket vote counters.
options[option]["ticket_count"] += 1
options[option]["vote_count"] += 1
......@@ -555,8 +548,7 @@ def get_calculated_votes(request):
# This is purely for aesthetic purpose.
options = {
key: value
for key, value
in sorted(
for key, value in sorted(
options.items(),
reverse=True,
key=lambda option: option[1]["has_support"],
......@@ -568,7 +560,7 @@ def get_calculated_votes(request):
"options_by_member": options_by_member,
"rv_members": rv_members,
"total_ticket_count": total_ticket_count,
"has_support_treshold": has_support_treshold
"has_support_treshold": has_support_treshold,
}
html_steps.append(
......@@ -598,8 +590,8 @@ def get_calculated_votes(request):
request.COOKIES.get(
"seed",
# 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
......@@ -630,10 +622,7 @@ def get_calculated_votes(request):
response = render(
request,
"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.
......@@ -644,4 +633,4 @@ def get_calculated_votes(request):
return response
# Step E
iteration += 1
iteration += 1
......@@ -11,6 +11,6 @@ import os
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()
......@@ -37,7 +37,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
# Server
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# Application definition
......@@ -46,14 +46,11 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"webpack_loader",
"shared",
"member_group_size_calc",
"rv_voting_calc",
"mail_signature",
"instagram_token",
"asset_server_resize",
]
......@@ -64,7 +61,6 @@ MIDDLEWARE = [
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_http_exceptions.middleware.ExceptionHandlerMiddleware",
"django_http_exceptions.middleware.ThreadLocalRequestMiddleware",
]
......@@ -92,9 +88,7 @@ WSGI_APPLICATION = "rybicka.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
"default": dj_database_url.config(conn_max_age=600)
}
DATABASES = {"default": dj_database_url.config(conn_max_age=600)}
# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/
......@@ -126,11 +120,10 @@ WEBPACK_LOADER = {
# Chobotnice
CHOBOTNICE_API_URL=env.str(
"CHOBOTNICE_API_URL",
"https://chobotnice.pirati.cz/graphql/"
CHOBOTNICE_API_URL = env.str(
"CHOBOTNICE_API_URL", "https://chobotnice.pirati.cz/graphql/"
)
CHOBOTNICE_RV_GID=env.str("CHOBOTNICE_RV_GID")
CHOBOTNICE_RV_GID = env.str("CHOBOTNICE_RV_GID")
# Instagram
......
......@@ -7,4 +7,4 @@ what!
from .base import *
DEBUG = True
DEBUG = True
......@@ -19,7 +19,6 @@ urlpatterns = [
path("vypocet-skupiny-clenu/", include("member_group_size_calc.urls")),
path("hlasovani-rv/", include("rv_voting_calc.urls")),
path("emailove-podpisy/", include("mail_signature.urls")),
path("instagram/", include("instagram_token.urls")),
path("asset-server/", include("asset_server_resize.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