Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into featureRequest/apps.problems
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Nov 7, 2023
2 parents 5e3ba0a + dca5400 commit c4b7a90
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 59 deletions.
15 changes: 15 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exclude_patterns:
- "config/"
- "db/"
- "dist/"
- "features/"
- "**/node_modules/"
- "script/"
- "**/spec/"
- "**/test/"
- "**/tests/"
- "Tests/"
- "**/vendor/"
- "**/*_test.go"
- "**/*.d.ts"
- "**/tests.py"
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Upload data to integrations

on:
push:
pull_request:
types:
- reopened

jobs:
upload:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.11"]
poetry-version: ["1.6.1"]

env:
DATABASE_URL: "sqlite:///db.sqlite3"
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry ${{ matrix.poetry-version }}
uses: snok/install-poetry@v1
with:
version: ${{ matrix.poetry-version }}
virtualenvs-create: false
installer-parallel: true

- name: Install dependencies
run: |
poetry run pip install --no-deps --upgrade pip
poetry install --with dev
- name: Generate configuration file
run: ./bin/create-env

- name: Generate tests coverage report
run: |
poetry run coverage run \
--source="." manage.py test \
--settings=server.settings.development
poetry run coverage xml
- name: Upload tests coverage report (Codecov)
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml

- name: Upload tests coverage report (Code Climate)
uses: paambaati/[email protected]
with:
coverageCommand: coverage report
16 changes: 16 additions & 0 deletions apps/users/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import TYPE_CHECKING

from django.contrib.auth.forms import UserCreationForm

from apps.users.models import User

if TYPE_CHECKING:
BaseUserCreationForm = UserCreationForm[User]
else:
BaseUserCreationForm = UserCreationForm


class CreateUserForm(BaseUserCreationForm):
class Meta:
model = User
fields = ["username", "email", "password1", "password2"]
9 changes: 9 additions & 0 deletions apps/users/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from apps.users.views import RegisterView

app_name = "users"

urlpatterns = [
path("", RegisterView.as_view(), name="register"),
]
21 changes: 21 additions & 0 deletions apps/users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect, render
from django.views import View

from apps.users.forms import CreateUserForm


class RegisterView(View):
template_name = "registration/register.html"

def get(self, request: HttpRequest) -> HttpResponse:
form = CreateUserForm()
return render(request, self.template_name, {"form": form})

def post(self, request: HttpRequest) -> HttpResponse:
form = CreateUserForm(self.request.POST)
if form.is_valid():
form.save()
return redirect("login")

return render(request, self.template_name, {"form": form})
94 changes: 69 additions & 25 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
django = "^4.2.5"
django = "^4.2.7"
psycopg2 = "^2.9.7"
django-environ = "^0.11.2"
django-guardian = "^2.4.0"
Expand All @@ -22,6 +22,7 @@ commitizen = "^3.9.0"
flake8 = "^6.1.0"
mypy = "^1.5.1"
django-stubs = {extras = ["compatible-mypy"], version = "^4.2.4"}
coverage = "^7.3.2"

[tool.poetry.group.docs]
optional = true
Expand Down
1 change: 1 addition & 0 deletions server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
LOGOUT_REDIRECT_URL = "home"

LOGIN_URL = "login"
REGISTER_URL = "register"

# The model to use to represent an user.
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-user-model
Expand Down
1 change: 1 addition & 0 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
path("", IndexView.as_view(), name="home"),
path("contests/", include("apps.contests.urls")),
path("tasks/", include("apps.tasks.urls")),
path("register/", include("apps.users.urls")),
]
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</a>
</li>
{% endif %}
<li><a href="#" class="dropdown-item">You profile</a></li>
<li><a href="#" class="dropdown-item">Your profile</a></li>
<li><hr class="dropdown-divider"></li>
<li>
<a href="{% url 'logout' %}" class="dropdown-item">
Expand All @@ -80,6 +80,7 @@
</ul>
</div>
{% else %}
<a href="{% url 'users:register' %}" class="nav-link text-white">Register</a>
<a href="{% url 'login' %}" class="nav-link text-white">Sign in</a>
{% endif %}
</div>
Expand Down
39 changes: 7 additions & 32 deletions templates/registration/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,14 @@
<div class="card">
<div class="card-header">Register</div>
<div class="card-body">
<form method="POST" action="{% url 'register' %}">
<form method="POST" action="{% url 'users:register' %}">
{% csrf_token %}
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input
type="text"
class="form-control"
id="name"
name="name"
required
>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input
type="email"
class="form-control"
id="email"
name="email"
required
>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input
type="password"
class="form-control"
id="password"
name="password"
required
>
</div>
<button type="submit" class="btn btn-primary">Register</button>
{% for field in form%}
{{field.label}}
{{field}}
{% endfor %}
<button type="submit" class="btn btn-primary">Register</button>
{{form.errors}}
</form>
</div>
</div>
Expand Down

0 comments on commit c4b7a90

Please sign in to comment.