Skip to content

Commit

Permalink
Feature: improve form process (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo-SF authored Sep 15, 2024
1 parent 85cd73d commit d9df525
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 113 deletions.
7 changes: 0 additions & 7 deletions portal/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
InstructorsSignupView.as_view(),
name="instructors_signup",
),
# path("",
# TemplateView.as_view(template_name="pages/home.html"),
# name="home"),
# path("about/",
# TemplateView.as_view(template_name="pages/about.html"),
# name="about",
# ),
path("", HomeRedirectView.as_view(), name="home"),
# Django Admin, use {% url 'admin:index' %}
path(settings.ADMIN_URL, admin.site.urls),
Expand Down
2 changes: 0 additions & 2 deletions portal/fixtures/initial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@
updated_at: 2021-04-14 20:32:27.106363+00:00
date_joined: 2021-04-14 20:32:27.106363+00:00
name: Admin
logo: qwe
student: false
slack_member_id: qwe
github_username: qwe
Expand Down Expand Up @@ -924,7 +923,6 @@
created_at: 2021-04-14 20:32:27.106363+00:00
updated_at: 2021-04-14 20:32:27.106363+00:00
name: ''
logo: ''
student: true
slack_member_id: 'U01SZUU0R2M'
github_username: ''
Expand Down
20 changes: 20 additions & 0 deletions portal/portal/static/css/project.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ table img {
background-color: #f2dede;
border-color: #eed3d7;
}

/* Center the form on the page */
.form-container {
margin: 0 auto;
max-width: 600px;
}

/* Style the deploy key section */
.deploy-key {
background-color: #f8f9fa;
padding: 15px;
border-radius: 5px;
font-family: monospace;
}

/* Customize button styles */
.btn-secondary {
background-color: #6c757d;
border-color: black;
}
100 changes: 42 additions & 58 deletions portal/portal/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
{% load static i18n compress%}<!DOCTYPE html>
{% load static i18n compress %}
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{% block title %}LDSA Portal{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->

<link rel="icon" href="{% static 'images/favicons/favicon.ico' %}">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

{% block css %}

<!-- Latest compiled and minified Bootstrap 4.1.1 CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"></head>


<!-- Your stuff: Third-party CSS libraries go here -->
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-..." crossorigin="anonymous">
<!-- FontAwesome CSS -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="..." crossorigin="anonymous">
<!-- Custom CSS -->
{% compress css %}
<!-- This file stores project-specific CSS -->

<link href="{% static 'css/project.css' %}" rel="stylesheet">

{% endcompress %}
{% endblock %}

</head>
{% endblock css %}
</head>

<body>
<body>

<div class="mb-1">
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{% url 'home' %}"><img src="{% static "images/ldssa_white.png" %}" alt="LDSA Portal"></a>
<a class="navbar-brand" href="{% url 'home' %}">
<img src="{% static 'images/ldssa_white.png' %}" alt="LDSA Portal" height="30">
</a>


<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
Expand Down Expand Up @@ -161,40 +147,38 @@

</div>

<div class="container">

{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">{{ message }}</div>
{% endfor %}
{% endif %}

{% block content %}
<p>Use this document as a way to quick start any new project.</p>
{% endblock content %}

</div> <!-- /container -->

{% block modal %}{% endblock modal %}
<div class="container mt-4">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
{% endif %}


{% block content %}
<!-- Default content -->
{% endblock content %}
</div>

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
{% block javascript %}

<!-- Required by Bootstrap v4.1.1 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>

<!-- Your stuff: Third-party javascript libraries go here -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">


<!-- place project specific Javascript in this file -->
{% compress js %}
<script src="{% static 'js/project.js' %}"></script>
{% endcompress %}
{% block modal %}{% endblock modal %}

{% block javascript %}
<!-- jQuery, Popper.js, and Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="..." crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="..." crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="..." crossorigin="anonymous"></script>
<!-- Custom JS -->
{% compress js %}
<script src="{% static 'js/project.js' %}"></script>
{% endcompress %}
{% endblock javascript %}
</body>
</html>
Expand Down
45 changes: 28 additions & 17 deletions portal/portal/templates/users/user_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@
{% block title %}{{ user.username }}{% endblock %}

{% block content %}
<h1>{{ user.username }}</h1>
<form class="form-horizontal" method="post" action="{% url 'users:profile' %}">
{% csrf_token %}
{{ form|crispy }}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Update</button>
</div>
<div class="container mt-4">
<h1 class="mb-4 text-center">Update User Data</h1>

<div class="row justify-content-center form-container">
<div class="col-md-6">
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</form>
</div>
</div>

<h2 class="mt-5">Deploy Key</h2>
<div class="card mb-3">
<div class="card-body deploy-key">
<p class="card-text">{{ user.deploy_public_key }}</p>
</div>
</div>
</form>
<h2>Deploy Key</h2>
<p>{{ user.deploy_public_key }}</p>
<p>
<a href="{% url 'account_set_password' %}">
Change password
</a>
</p>
{% endblock %}

<p>
<a href="{% url 'account_set_password' %}" class="btn btn-secondary">
<i class="fas fa-key"></i> Change Password
</a>
</p>
</div>
{% endblock content %}
1 change: 0 additions & 1 deletion portal/portal/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class UserAdmin(auth_admin.UserAdmin):
"gender",
"profession",
"company",
"logo",
"github_username",
"slack_member_id",
"failed_or_dropped",
Expand Down
33 changes: 12 additions & 21 deletions portal/portal/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,37 @@


class UserChangeForm(forms.ModelForm):
name = forms.CharField()
name = forms.CharField(required=True)
github_username = forms.CharField(required=True)
slack_member_id = forms.CharField(required=True)

def __init__(self, *args, **kwawgs) -> None:
super().__init__(*args, **kwawgs)
if config.PORTAL_STATUS == "academy":
del self.fields["gender"]
del self.fields["profession"]
del self.fields["company"]
del self.fields["ticket_type"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# Remove fields based on portal status
if config.PORTAL_STATUS == "academy":
fields_to_remove = ["gender", "profession", "company", "ticket_type"]
else:
del self.fields["logo"]
del self.fields["github_username"]
del self.fields["slack_member_id"]
if config.PORTAL_STATUS not in (
"admissions",
"admissions:applications",
):
fields_to_remove = ["github_username", "slack_member_id"]
if config.PORTAL_STATUS not in ("admissions", "admissions:applications"):
self.fields["ticket_type"] = forms.ChoiceField(
choices=TicketType.choices,
disabled=True,
)
for field in fields_to_remove:
del self.fields[field]

class Meta:
model = User
fields = (
"name",
"logo",
"github_username",
"slack_member_id",
"gender",
"profession",
"company",
"ticket_type",
)
widgets = {
"logo": forms.TextInput(),
"github_username": forms.TextInput(),
"slack_member_id": forms.TextInput(),
}


class UserCreationForm(django.contrib.auth.forms.UserCreationForm):
Expand Down
16 changes: 16 additions & 0 deletions portal/portal/users/migrations/0021_remove_user_logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.14 on 2024-09-15 21:58

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("users", "0020_user_academy_type_preference"),
]

operations = [
migrations.RemoveField(
model_name="user",
name="logo",
),
]
1 change: 0 additions & 1 deletion portal/portal/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class User(AbstractUser):
# Academy
is_student = models.BooleanField(default=False)
is_instructor = models.BooleanField(default=False)
logo = models.TextField(blank=True)
slack_member_id = models.TextField(blank=True)
github_username = models.TextField(blank=True)
deploy_private_key = models.TextField(blank=True)
Expand Down
3 changes: 0 additions & 3 deletions portal/portal/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

app_name = "users"
urlpatterns = [
# path("", view=user_list_view, name="list"),
# path("~redirect/", view=user_redirect_view, name="redirect"),
path("profile/", view=user_update_view, name="profile"),
# path("<str:username>/", view=user_detail_view, name="detail"),
]
12 changes: 9 additions & 3 deletions portal/portal/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from allauth.account.views import SignupView
from constance import config
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.shortcuts import redirect
Expand Down Expand Up @@ -201,12 +202,17 @@ class UserListView(LoginRequiredMixin, ListView):
class UserUpdateView(LoginRequiredMixin, UpdateView):
model = User
form_class = forms.UserChangeForm
template_name = "users/user_form.html" # Explicitly specify the template name

def get_success_url(self) -> str:
def get_object(self):
return self.request.user

def get_success_url(self):
return reverse("users:profile")

def get_object(self):
return User.objects.get(username=self.request.user.username)
def form_valid(self, form):
messages.success(self.request, "Your profile was updated successfully.")
return super().form_valid(form)


user_update_view = UserUpdateView.as_view()
Expand Down

0 comments on commit d9df525

Please sign in to comment.