Skip to content
This repository was archived by the owner on Jul 18, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
49107ab
Svelte & Bulma = ♥
cofob Apr 26, 2022
1a0fce9
Update
cofob Apr 27, 2022
5025607
Add logo
cofob Apr 27, 2022
fe01fcd
Add Modal.svelte
cofob Apr 27, 2022
0afb111
Merge branch 'master' into cofob/svelte
PerchunPak Apr 27, 2022
4ace3ab
Update
cofob Apr 27, 2022
ac0f425
Add deduplication and pay url generation to Donate
cofob Apr 28, 2022
18aa5c8
Add fancy Donate buttons
cofob Apr 28, 2022
5da2345
Fix pay_url generation
cofob Apr 28, 2022
0bc4e0a
Fix pay button disabled state
cofob Apr 28, 2022
76771db
add about button to donate
cofob Apr 28, 2022
c8de115
move +/- buttons
cofob Apr 28, 2022
8f78625
Fix tests
cofob Apr 28, 2022
1ce242b
Fix docstring
cofob Apr 28, 2022
e35dbad
Fix typo
cofob Apr 28, 2022
9389935
Remove useless files
cofob Apr 28, 2022
5b5a6ab
More
cofob Apr 28, 2022
6c7a716
Add Svelte CI/CD (#105)
cofob Apr 28, 2022
7f64867
Squashed commit of the following:
cofob Apr 28, 2022
739cfa3
Merge branch 'cofob/svelte' of github.com:fire-square/autodonate into…
cofob Apr 28, 2022
2ac97fe
Add docs
cofob Apr 28, 2022
c60856b
Fix cofob's docstrings
PerchunPak Apr 28, 2022
fd6f9a8
Move dataclasses to DB models
PerchunPak Apr 28, 2022
5daa1b0
Add player model
cofob Apr 29, 2022
8b40130
Add media files serve for FileField
cofob Apr 29, 2022
7c5023f
Remove ugly defenition
cofob Apr 29, 2022
e64cbc3
Fix typo
cofob Apr 29, 2022
7805bae
Remove bulma from staticfiles dir
cofob Apr 29, 2022
28928da
Upgrade models
cofob Apr 29, 2022
24009d1
Register models in admin
cofob Apr 29, 2022
f79d512
Add media folder to gitignore
cofob Apr 29, 2022
01d1c0b
Uodate
cofob Apr 29, 2022
6ea72a5
Change to ImageField
cofob Apr 29, 2022
92b89ae
Fix tests
cofob Apr 29, 2022
9be8c94
Fix UUID generation
cofob Apr 29, 2022
f7e766e
Update :)
cofob Apr 29, 2022
04ab415
Add modal, remove about section
cofob Apr 29, 2022
9018b80
Normal toasts
cofob Apr 29, 2022
a114d7f
Add about anchor
cofob Apr 29, 2022
67b1e16
Remove old toast from base.html
cofob Apr 29, 2022
8fe6fa0
Working modal (broken backdrop)
cofob Apr 29, 2022
6f6cb86
Impemented about for Donate
cofob Apr 29, 2022
f7465a2
Fix pay url generation
cofob Apr 29, 2022
775af75
Fix warn
cofob Apr 29, 2022
7109fcb
Use POST instead of GET request for pay button
cofob Apr 29, 2022
49d445b
Fix ci
cofob Apr 29, 2022
df8881f
Add empty stubs
cofob Apr 29, 2022
d58851b
Add comments
cofob Apr 29, 2022
aa0e8e1
More comments
cofob Apr 29, 2022
514d093
Add dot
cofob Apr 29, 2022
6fef82b
Typo
cofob Apr 29, 2022
2d84ea8
Add handler to `urlpatterns` with decorator
PerchunPak Apr 29, 2022
84be612
Add TokenField
cofob Apr 29, 2022
900915a
Merge remote-tracking branch 'origin/cofob/svelte' into cofob/svelte
cofob Apr 29, 2022
5a81626
Fix mypy
cofob Apr 29, 2022
8b32a13
Add docstring
cofob Apr 29, 2022
8a2e9e1
Make API return true JSON
PerchunPak Apr 29, 2022
182b6b8
Add djangorestframework
cofob Apr 30, 2022
310d332
Move docs deps to dev section
cofob Apr 30, 2022
a93cc70
Changed to REST API framework
cofob Apr 30, 2022
28f3152
Fix svelte widgets
cofob Apr 30, 2022
1e3bcfc
Add rate limits
cofob Apr 30, 2022
fe96863
Fix
cofob Apr 30, 2022
5efea1e
Fix z-index toast
cofob Apr 30, 2022
9fa9eac
Revert "Move docs deps to dev section"
cofob Apr 30, 2022
7493b09
Fix warnings
cofob Apr 30, 2022
23e4d67
Use special svelte file for index page
cofob Apr 30, 2022
b2a281a
Fix btn on mobile
cofob Apr 30, 2022
66947d6
Md support for Modals & Donate about section
cofob Apr 30, 2022
8c6d366
Merge branch 'master' into cofob/svelte
PerchunPak Apr 30, 2022
86df07f
Migrate to TypeScript
PerchunPak Apr 30, 2022
4950e52
Replace tabs to spaces
PerchunPak Apr 30, 2022
d442b6f
Revert "Migrate to TypeScript"
cofob Apr 30, 2022
9a00cc5
Revert "Revert "Migrate to TypeScript""
PerchunPak Apr 30, 2022
f23432b
Fix all TypeScript errors
PerchunPak Apr 30, 2022
1f7f456
Merge branch 'master' into cofob/svelte
cofob May 1, 2022
84a4204
Add screenshot action (#116)
cofob May 1, 2022
df90e36
Fix tsconfig
cofob May 1, 2022
60c5f3c
Fix screenshot.yml
PerchunPak May 1, 2022
e997f2c
Apply black changes
PerchunPak May 1, 2022
2e0c50e
Revert "Fix tsconfig"
PerchunPak May 1, 2022
4bfa1ec
Remove DEBUG=false in screenshot.yml
PerchunPak May 1, 2022
c604c11
Merge branch 'master' into cofob/svelte
PerchunPak May 1, 2022
f35c207
Fix RelationsFields in the API (#118)
PerchunPak May 1, 2022
be71b14
Fix action
cofob May 1, 2022
86e36c1
Update poetry.lock
PerchunPak May 1, 2022
12e60ed
Add public config fields
cofob May 1, 2022
86c32d6
Merge branch 'cofob/svelte' of github.com:fire-square/autodonate into…
cofob May 1, 2022
7fa0dec
Change __str__ docs
cofob May 1, 2022
1b6e3f0
Add product groups
cofob May 1, 2022
acc5377
Replace `django-svelte` with custom file (#120)
PerchunPak May 1, 2022
51ab332
update
cofob May 1, 2022
12bd659
Remove migrations
cofob May 1, 2022
ec276ac
Update readme
cofob May 1, 2022
1da148f
Add sleep to screenshot.py
cofob May 1, 2022
e371836
Update action
cofob May 1, 2022
0f40a54
Remove ubjson
cofob May 2, 2022
28d6a46
Customize svelte css class name
cofob May 4, 2022
67f97d4
Update screenshot action (#123)
cofob May 5, 2022
e8b3b51
Reduce js usage
cofob May 6, 2022
734cd12
Merge branch 'master' into cofob/svelte
PerchunPak May 6, 2022
b923a88
Update poetry.lock
PerchunPak May 6, 2022
edc03ea
Merge branch 'master' into cofob/svelte
cofob May 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.{ts, svelte, scss}]
indent_style = space
indent_size = 4
75 changes: 75 additions & 0 deletions .github/scripts/screenshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Script for generating screenshots of the main page in ``.github/workflows/screenshot.yml``."""

import re
from base64 import b64encode
from json import loads
from subprocess import check_output
from time import sleep
from typing import Dict, List

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager


def main() -> None:
"""Main function of the script."""
# Blacklist url regex expression
expr = re.compile(r".*(auth|login|__|<|>|api).*")
# Blacklist
blacklist: List[str] = []

# Load all urlpatterns
urls: List[Dict[str, str]] = loads(check_output("poetry run python manage.py show_urls -uf json".split()).decode())

# Initialize Chrome (pre-installed on GitHub Actions machine)
chrome_options = Options()
chrome_options.add_argument("--headless")
# Download appropriate driver version for Chrome
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

# Iterate over screen widths
for width in [1920, 720, 640, 480, 360]:
# Iterate over all urls in urlpatterns
for url in urls:
# Check if url in blacklist
if url["url"] in blacklist:
continue

# Check if url contains url arguments. Drop if hit.
if expr.findall(url["url"].lower()):
# Add to blacklist
blacklist.append(url["url"])
continue

# Get page
driver.get("http://localhost:8000" + url["url"])

# Sleep 1 second, wait for redirects
sleep(1)

# Check if url contains url arguments. Drop if hit.
if expr.findall(driver.current_url.lower()):
# Add to blacklist
blacklist.append(url["url"])
continue

# Set window size to page size (fullpage screenshot)
driver.set_window_size(width, driver.execute_script("return document.body.parentNode.scrollHeight"))

# Sleep more to ensure full page load
sleep(2)

# Save screenshot of body element, avoid scrollbar
driver.find_element(by=By.TAG_NAME, value="body").screenshot(
f"screenshot-{b64encode((url['url'] + ' (width: ' + str(width) + ')').encode()).decode()}.png"
)

# Properly close Chrome
driver.close()


if __name__ == "__main__":
main()
31 changes: 31 additions & 0 deletions .github/scripts/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Script for uploading screenshots to public storage."""

from base64 import b64decode
from glob import glob
from sys import argv

import requests


def main(secret_key: str, commit: str) -> str:
"""Main function to upload screenshots.

Args:
secret_key: Secret key for uploading. Passing directly to API.
commit: Commit where screenshot was taken.

Returns:
Link to uploaded screenshots.
"""
for image in glob("screenshot-*.png"):
response = requests.post(
"https://screen.deta.dev/upload",
data={"secret": secret_key, "key": commit, "comment": b64decode(image[11:-4]).decode()},
files={"file": open(image, "rb")},
)

return "https://screen.deta.dev/" + response.json()["key"]


if __name__ == "__main__":
print(main(argv[1], argv[2]))
24 changes: 0 additions & 24 deletions .github/workflows/deploy-pypi.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ jobs:
with:
file: ./coverage.xml

- name: Install node
if: ${{ matrix.python-version == '3.10' }}
uses: bahmutov/npm-install@v1
with:
working-directory: svelte

- name: Check TypeScript types
if: ${{ matrix.python-version == '3.10' }}
run: npx svelte-check

- name: Build Svelte
if: ${{ matrix.python-version == '3.10' }}
working-directory: svelte
run: npm run build

- name: Configure git
if: ${{ matrix.python-version == '3.10' }}
run: |
Expand Down Expand Up @@ -74,3 +89,35 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}

- name: Install screenshot dependencies
if: ${{ matrix.python-version == '3.10' }}
run: poetry install -E screenshot-script

- name: Make and run migrations
if: ${{ matrix.python-version == '3.10' }}
run: |
echo "DISABLE_DEBUG_TOOLBAR=True" >> .env
poetry run python manage.py makemigrations --noinput
poetry run python manage.py makemigrations autodonate --noinput
poetry run python manage.py makemigrations api --noinput
poetry run python manage.py migrate
poetry run python manage.py initconfig

- name: Run server and screenshot script
if: ${{ matrix.python-version == '3.10' }}
run: |
poetry run python manage.py runserver &
sleep 5
poetry run python .github/scripts/screenshot.py

- name: Make screenshot arifacts
uses: actions/upload-artifact@v3
if: ${{ matrix.python-version == '3.10' }}
with:
name: screen
path: screenshot-*.png

- name: Upload screenshots
if: ${{ matrix.python-version == '3.10' }}
run: |
poetry run python .github/scripts/upload.py ${{ secrets.BIN_SECRET }} $(git rev-parse --short HEAD)
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# Created by https://www.toptal.com/developers/gitignore/api/linux,python,windows,pycharm+all,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,python,windows,pycharm+all,visualstudiocode

# svelte
svelte/node_modules/
svelte/public/build/
svelte/dist

# bulma
bulma/node_modules/
bulma/dist

# media files
media/

# decouple
.env
settings.ini
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@

## Установка

Установите `git` и `node.js` для вашей платформы.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если это не заставляет иметь зависимость node.js в рантайме, зачем пользователя заставлять компилировать? Как на счет добавить пре-компилированные файлы для моментального запуска в проде? (Это будет стороннее изменение, так что не в этом PR, просто обсуждение)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, можно распространять скомпилированные файлы в релизах и докерах.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved?


```bash
git clone https://github.com/fire-square/autodonate.git
git clone --recurse-submodules https://github.com/fire-square/autodonate.git
cd autodonate

cd svelte
npm install
npm run build
cd ..
```

Затем установите `poetry` [рекомендованым путем](https://python-poetry.org/docs/master/#installation).
Expand All @@ -42,6 +49,13 @@ curl -sSL https://install.python-poetry.org | python -
poetry install
```

Применим миграции:

```bash
poetry run python manage.py migrate
poetry run python manage.py initconfig
```

## Спасибо

Этот проект был сгенерирован с помощью [`fire-square-style`](https://github.com/fire-square/fire-square-style).
Expand Down
1 change: 1 addition & 0 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""API app."""
10 changes: 10 additions & 0 deletions api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""App module for API app."""

from django.apps import AppConfig


class ApiConfig(AppConfig):
"""API configuration."""

default_auto_field = "django.db.models.BigAutoField"
name = "api"
94 changes: 94 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""URL patterns for API app."""

from typing import List

from django.urls import include, path
from django.urls.resolvers import URLPattern
from rest_framework import generics, mixins, routers, serializers, viewsets

from api.views import urls
from autodonate.models import Config, Donation, Player, Product


class ConfigSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for Config model."""

class Meta:
"""Meta class."""

model = Config
fields = ["key", "value", "read_only"]


class ConfigViewSet(viewsets.ModelViewSet):
"""Config viewset model."""

queryset = Config.objects.filter(public=True)
serializer_class = ConfigSerializer


class ProductSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for Product model."""

class Meta:
"""Meta class."""

model = Product
fields = ["id", "name", "price", "long_description", "group", "max_in_cart", "image"]


class ProductViewSet(viewsets.ModelViewSet):
"""Product viewset model."""

queryset = Product.objects.filter(enabled=True)
serializer_class = ProductSerializer


class PlayerSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for Player model."""

class Meta:
"""Meta class."""

model = Player
fields = ["nickname"]


class PlayerViewSet(generics.RetrieveAPIView, viewsets.GenericViewSet):
"""Viewset for Player model."""

queryset = Player.objects.all()
serializer_class = PlayerSerializer


class DonationSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for Donation model."""

product = ProductSerializer(read_only=True)
player = PlayerSerializer(read_only=True)

class Meta:
"""Meta class."""

model = Donation
fields = ["id", "product", "player", "date"]


class DonationViewSet(viewsets.ModelViewSet):
"""Serializer for Donation model."""

queryset = Donation.objects.filter(product__enabled=True)[:6]
serializer_class = DonationSerializer


router = routers.DefaultRouter()
router.register(r"config", ConfigViewSet)
router.register(r"product", ProductViewSet)
router.register(r"player", PlayerViewSet)
router.register(r"donation", DonationViewSet)

urlpatterns: List[URLPattern] = [
path("", include(router.urls)),
]

urlpatterns.extend(urls)
7 changes: 7 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Views module for index app."""

from typing import List

from django.urls.resolvers import URLPattern

urls: List[URLPattern] = []
7 changes: 6 additions & 1 deletion autodonate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
from django.contrib import admin
from structlog.stdlib import get_logger

from autodonate.models import Config
from autodonate.models import Config, Donation, Player, Product

log = get_logger()


admin.site.register(Player)
admin.site.register(Donation)
admin.site.register(Product)


@admin.register(Config)
class ConfigAdmin(admin.ModelAdmin):
"""Admin Config model."""
Expand Down
Loading