Skip to content

Commit

Permalink
Improved lint results
Browse files Browse the repository at this point in the history
  • Loading branch information
awallenfang committed Sep 20, 2024
1 parent 7d86642 commit 6b01dde
Show file tree
Hide file tree
Showing 13 changed files with 665 additions and 100 deletions.
569 changes: 569 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions hub/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

class LoginForm(forms.Form):
template_name = "hub/form_template.html"
username = forms.CharField(max_length=100,
widget=forms.TextInput(attrs={'placeholder': 'Username'}))
username = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'placeholder': 'Username'}))
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))

class SignupForm(forms.Form):
Expand All @@ -13,4 +12,6 @@ class SignupForm(forms.Form):
widget=forms.TextInput(attrs={'placeholder': 'Username'}))
email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'E-Mail'}))
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
repeat_password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Repeat Password'}))
repeat_password = forms.CharField(widget=forms.PasswordInput(
attrs={'placeholder': 'Repeat Password'}
))
79 changes: 39 additions & 40 deletions hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.contrib.auth.models import User as AuthUser
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods



from .forms import LoginForm, SignupForm
from .models import SharedSpace, User
from .models import User



Expand All @@ -23,8 +22,8 @@ def hub(request):
return render(request,
"hub/base.html",
{"user_spaces": user_spaces, "selected_space": selected_space})
else:
return HttpResponseRedirect("/login")

return HttpResponseRedirect("/login")

def login(request):
# If the user is alread logged in, redirect
Expand All @@ -35,19 +34,19 @@ def login(request):
form = LoginForm()
return render(request, "hub/login.html", {'form': form})

elif request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
auth_user = auth.authenticate(username=form.cleaned_data["username"], password=form.cleaned_data["password"])

if auth_user:
auth.login(request, auth_user)

return HttpResponseRedirect("/")
else:
return render(request, "hub/login.html", {"form": form, "error_message": "The input data is incorrect!"})
else:
return render(request, "hub/login.html", {"form": form, "error_message": "The input data is incorrect!"})

form = LoginForm(request.POST)
if form.is_valid():
auth_user = auth.authenticate(username=form.cleaned_data["username"], password=form.cleaned_data["password"])

if auth_user:
auth.login(request, auth_user)

return HttpResponseRedirect("/")

return render(request, "hub/login.html", {"form": form, "error_message": "The input data is incorrect!"})

return render(request, "hub/login.html", {"form": form, "error_message": "The input data is incorrect!"})

def signup(request):
# If the user is alread logged in, redirect
Expand All @@ -58,29 +57,29 @@ def signup(request):
form = SignupForm()
return render(request, "hub/signup.html", {'form': form})

elif request.method == "POST":
form = SignupForm(request.POST)

if form.is_valid():

# Catch invalid repeat password
if form.cleaned_data["password"] != form.cleaned_data["repeat_password"]:
return render(request, "hub/signup.html", {"form": form, "error_message": "The passwords don't match."})

# Create the user. If the username is already taken, return an error stating it
try:
auth_user = AuthUser.objects.create_user(form.cleaned_data["username"], form.cleaned_data["email"], form.cleaned_data["password"])
except IntegrityError:
return render(request, "hub/signup.html", {"form": form, "error_message": "The username is already taken."})
else:
# If the auth_user was created, also create out user model
User.objects.create(auth_user=auth_user)

# If everything was successful return to the hub
return HttpResponseRedirect("/login")

form = SignupForm(request.POST)

if form.is_valid():

# Catch invalid repeat password
if form.cleaned_data["password"] != form.cleaned_data["repeat_password"]:
return render(request, "hub/signup.html", {"form": form, "error_message": "The passwords don't match."})

# Create the user. If the username is already taken, return an error stating it
try:
auth_user = AuthUser.objects.create_user(form.cleaned_data["username"], form.cleaned_data["email"], form.cleaned_data["password"])
except IntegrityError:
return render(request, "hub/signup.html", {"form": form, "error_message": "The username is already taken."})
else:
# If something is wrong in the valid, check what it is and return a corresponding error
return render(request, "hub/signup.html", {"form": form, "error_message": "There is a problem in the form!"})
# If the auth_user was created, also create out user model
User.objects.create(auth_user=auth_user)

# If everything was successful return to the hub
return HttpResponseRedirect("/login")

# If something is wrong in the valid, check what it is and return a corresponding error
return render(request, "hub/signup.html", {"form": form, "error_message": "There is a problem in the form!"})

@login_required
def logout(request):
Expand Down
1 change: 0 additions & 1 deletion root/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down
1 change: 0 additions & 1 deletion root/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from django.contrib import admin
from django.urls import include, path

import transactions

urlpatterns = [
path('admin/', admin.site.urls),
Expand Down
10 changes: 4 additions & 6 deletions space/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ def create_space(name: str, owner):
while len(spaces) > 0:
invite_token = ''.join(random.choice(string.ascii_uppercase) for _ in range(10))
spaces = SharedSpace.objects.filter(invite_token = invite_token)

# Avoid circular dependencies
from hub.models import User


return SharedSpace.objects.create(name=name, invite_token=invite_token, owner=owner)

def join(user, token):
try:
space_with_token = SharedSpace.objects.get(invite_token = token)
except:
raise InvalidTokenError("There is no space with the given token")
except Exception as exc:
raise InvalidTokenError("There is no space with the given token") from exc
else:
user.spaces.add(space_with_token)
user.save()
Expand All @@ -47,7 +45,7 @@ def leave(self, user):
try:
self.owner = self.joined_people()[0]
self.save()
except:
except IndexError:
# Space is empty now, so remove it
self.delete_space()
user.save()
Expand Down
17 changes: 9 additions & 8 deletions space/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_space(request):

SharedSpace.join(user, space.invite_token)

if user.selected_space == None:
if user.selected_space is None:
user.select_space(space.id)
return HttpResponseRedirect("/")

Expand All @@ -36,7 +36,7 @@ def create_space(request):
def join_space(request):
user = User.objects.get(auth_user = request.user)
space_id = request.POST.get("space_token", None)
if space_id == None:
if space_id is None:
return HttpResponseRedirect("/")
try:
SharedSpace.join(user, space_id)
Expand Down Expand Up @@ -90,12 +90,13 @@ def space_view(request, space_id):
'joined_people': joined_people})

return HttpResponseRedirect("/")
else:
name = request.POST.get("name", "My Space")
space = SharedSpace.objects.get(id = space_id)
space.name = name
space.save()
return HttpResponseRedirect("/space/" + str(space_id))


name = request.POST.get("name", "My Space")
space = SharedSpace.objects.get(id = space_id)
space.name = name
space.save()
return HttpResponseRedirect("/space/" + str(space_id))

@login_required
def delete_space(request, space_id):
Expand Down
10 changes: 5 additions & 5 deletions todos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def assign_user(self, user):
self.assigned_user = user
self.save()

def make_recurrent(self, users=[], rate=7):
def make_recurrent(self, users=[None], rate=7):
"""
Turn the todo into a recurrent todo with the specified users and the specified rate.
The users are ordered
Expand All @@ -162,8 +162,8 @@ def get_currently_assigned_user(self) -> User:

passed_time = current_time - start_time
return self.recurrent_state.get_user_at_day(passed_time.days)
else:
return self.assigned_user

return self.assigned_user

def get_next_assigned_user(self) -> User:
if self.recurrent_state:
Expand All @@ -172,8 +172,8 @@ def get_next_assigned_user(self) -> User:

passed_time = current_time - start_time
return self.recurrent_state.get_user_at_day(passed_time.days + self.recurrent_state.day_rotation)
else:
return self.assigned_user

return self.assigned_user



Expand Down
7 changes: 4 additions & 3 deletions todos/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from .models import Todo
from space.models import SharedSpace
from hub.models import User

from django.test import TestCase
from django.contrib.auth.models import User as AuthUser


from .models import Todo
from space.models import SharedSpace
from hub.models import User

# Create your tests here.
class TodosTest(TestCase):
Expand Down
15 changes: 7 additions & 8 deletions todos/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from django.contrib import admin
from django.urls import include, path
from django.urls import path

from . import views

app_name = "todos"

urlpatterns = [
path('', views.dashboard, name="todos"),
path('<int:id>/delete/', views.delete_todo, name="delete_todo"),
path('<int:todo_id>/delete/', views.delete_todo, name="delete_todo"),
path('add/', views.add_todo, name="add_todo"),
path('<int:id>/edit/', views.edit_todo, name="edit_todo"),
path('<int:id>/finish_edit/', views.finish_edit_todo, name="finish_todo_edit"),
path('<int:id>/close_todo/', views.close_todo, name="close_todo"),
path('<int:id>/open_todo/', views.open_todo, name="open_todo"),
path('<int:id>/<str:left>/<str:right>/<str:status>/reorder', views.reorder, name="todo_reorder")
path('<int:todo_id>/edit/', views.edit_todo, name="edit_todo"),
path('<int:todo_id>/finish_edit/', views.finish_edit_todo, name="finish_todo_edit"),
path('<int:todo_id>/close_todo/', views.close_todo, name="close_todo"),
path('<int:todo_id>/open_todo/', views.open_todo, name="open_todo"),
path('<int:todo_id>/<str:left>/<str:right>/<str:status>/reorder', views.reorder, name="todo_reorder")

]
28 changes: 13 additions & 15 deletions todos/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.http import require_http_methods
from django.db.models import F
from django.contrib.auth.decorators import login_required

from hub.models import User
Expand All @@ -25,11 +23,11 @@ def dashboard(request):

@login_required
@require_http_methods(['DELETE'])
def delete_todo(request, id):
def delete_todo(request, todo_id):
"""
Delete the todo with the given ID
"""
Todo.objects.filter(id=id).delete()
Todo.objects.filter(id=todo_id).delete()

todos = Todo.get_open(request)

Expand All @@ -55,20 +53,20 @@ def add_todo(request):

@login_required
@require_http_methods(['POST'])
def edit_todo(request, id):
def edit_todo(request, todo_id):
"""
Swap the todo with the editable version
"""
todo = Todo.objects.get(id = id)
todo = Todo.objects.get(id = todo_id)
return render(request, "todos/components/todo_edit.html", {"todo": todo})

@login_required
@require_http_methods(['POST'])
def finish_edit_todo(request, id):
def finish_edit_todo(request, todo_id):
"""
Finish and submit the editing of a todo with the given ID
"""
todo = Todo.objects.get(id = id)
todo = Todo.objects.get(id = todo_id)

todo_name = request.POST.get("todo_name", todo.name)
todo_description = request.POST.get("todo_description", todo.description)
Expand All @@ -82,11 +80,11 @@ def finish_edit_todo(request, id):

@login_required
@require_http_methods(['POST'])
def close_todo(request, id):
def close_todo(request, todo_id):
"""
Set a todo as being done
"""
todo = Todo.objects.get(id = id)
todo = Todo.objects.get(id = todo_id)

todo.done = True
todo.save()
Expand All @@ -99,11 +97,11 @@ def close_todo(request, id):

@login_required
@require_http_methods(['POST'])
def open_todo(request, id):
def open_todo(request, todo_id):
"""
Reopen a done todo
"""
todo = Todo.objects.get(id = id)
todo = Todo.objects.get(id = todo_id)

todo.done = False
todo.save()
Expand All @@ -116,17 +114,17 @@ def open_todo(request, id):

@login_required
@require_http_methods(['POST'])
def reorder(request, id, left, right, status):
def reorder(request, todo_id, left, right, status):
"""
Allows the reordering on the dashboard. This will be called once a todo is dropped on a droppable space.
It will return the id of the dropped todo, as well as the position values on the left and the right of the space.
If it is on the edges either left or right will be set to -1, since there is no space there.
"""
# Move position
changed_todo = Todo.objects.get(id=int(id))
changed_todo = Todo.objects.get(id=int(todo_id))
changed_todo.reorder(int(left), int(right))

changed_todo.done = False if status == "open" else True
changed_todo.done = not (status == "open")

changed_todo.save()

Expand Down
2 changes: 1 addition & 1 deletion transactions/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.utils import timezone

from .models import get_currencies, Tag, get_all_tags
from .models import get_currencies, get_all_tags


class NewTransactionForm(forms.Form):
Expand Down
Loading

0 comments on commit 6b01dde

Please sign in to comment.