Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update edit profile form #1005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion project/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.decorators import action
from rest_framework.response import Response
from api.permissions import IsAccountOwnerOrDuringRegistrationOrReadOnly

from api.utils import get_account
from api.models import Thread
from accounts.models import Account
from api.serializers import (
Expand Down
11 changes: 10 additions & 1 deletion project/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ class UpdateAccount(forms.ModelForm):
Form for updating Account data
"""

def __init__(self, *args, **kwargs):
readonly = kwargs.pop("readonly", False)
super(UpdateAccount, self).__init__(*args, **kwargs)
if readonly:
self.disable_fields()

def disable_fields(self):
for _, field in self.fields.items():
field.disabled = True

class Meta:
model = Account
fields = [
Expand Down Expand Up @@ -332,4 +342,3 @@ def clean_profile_image(self):
pass

return profile_image

47 changes: 1 addition & 46 deletions project/accounts/templates/accounts/utils/update_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,7 @@
<section style='display: flex;justify-content: center; padding-top: 20px;'>
<div class="setting card" style="width: 75%;" >
<div class="card-content">
<div class="step-title">
<div class="section">
<div class="title-lato center">
Account Settings
</div>
</div>
<div class="accent-line"></div>
{{form.non_field_errors}}
<form style="padding-top: 10px;" method="POST">
{% csrf_token %}
<div class='row'>
<div class=" col s12 m6 ">
<span class='error'>{{form.first_name.errors}}</span>
{{form.first_name.label_tag}}
{{form.first_name}}
</div>
<div class=" col s12 m6 ">
<span class='error'>{{form.last_name.errors}}</span>
{{form.last_name.label_tag}}
{{form.last_name}}
</div>
</div>
<div class='row'>
<div class=" col s12 m6 ">
<span class='error'>{{form.username.errors}}</span>
{{form.username.label_tag}}
{{form.username}}
</div>
<div class=" col s12 m6 ">
<span class='error'>{{form.email.errors}}</span>
{{form.email.label_tag}}
{{form.email}}
</div>
</div>
<div class='row'>
<div class="col s24 m12">
<span> {{form.about_me.errors}}</span>
{{form.about_me.label_tag}}
{{form.about_me}}
</div>
</div>
<div class="row center">
<input class='btn' type='submit' value="Save Changes"></input>
</div>
</form>
</div>
{% include "accounts/utils/update_settings_form.html" %}
<div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="step-title">
<div class="section">
<div class="title-lato center">
Account Settings
</div>
</div>
<div class="accent-line"></div>
{{form.non_field_errors}}
<form style="padding-top: 10px;" method="POST">
{% csrf_token %}
<div class='row'>
<div class=" col s12 m6 ">
<span class='error'>{{form.first_name.errors}}</span>
{{form.first_name.label_tag}}
{{form.first_name}}
</div>
<div class=" col s12 m6 ">
<span class='error'>{{form.last_name.errors}}</span>
{{form.last_name.label_tag}}
{{form.last_name}}
</div>
</div>
<div class='row'>
<div class=" col s12 m6 ">
<span class='error'>{{form.username.errors}}</span>
{{form.username.label_tag}}
{{form.username}}
</div>
<div class=" col s12 m6 ">
<span class='error'>{{form.email.errors}}</span>
{{form.email.label_tag}}
{{form.email}}
</div>
</div>
<div class='row'>
<div class="col s24 m12">
<span> {{form.about_me.errors}}</span>
{{form.about_me.label_tag}}
{{form.about_me}}
</div>
</div>
<div class="row center">
{%if not readonly %}
<input class='btn' type='submit' value="Save Changes"></input>
{% endif%}
</div>
</form>
</div>
46 changes: 31 additions & 15 deletions project/frontend_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

from api.models import Category, Thread, Civi, Activity
from accounts.models import Account
from accounts.forms import UpdateAccount
from api.forms import UpdateProfileImage
from core.constants import US_STATES
from core.custom_decorators import login_required, full_account

from django.contrib.auth import get_user_model

User = get_user_model()


Expand Down Expand Up @@ -64,18 +66,34 @@ def base_view(request):
@login_required
@full_account
def user_profile(request, username=None):
if not username:
return HttpResponseRedirect("/profile/{0}".format(request.user))
else:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
return HttpResponseRedirect("/404")
data = {
"username": user,
"profile_image_form": UpdateProfileImage,
}
return TemplateResponse(request, "account.html", data)
if request.method == "GET":
if not username:
return HttpResponseRedirect("/profile/{0}".format(request.user))
else:
is_owner = username == request.user.username
try:
user = User.objects.get(username=username)
account = user.account_set.first()
except User.DoesNotExist:
return HttpResponseRedirect("/404")

form = UpdateAccount(
initial={
"username": user.username,
"email": user.email,
"first_name": account.first_name or None,
"last_name": account.last_name or None,
"about_me": account.about_me or None,
},
readonly=True,
)
data = {
"username": user,
"profile_image_form": UpdateProfileImage,
"form": form if is_owner else None,
"readonly": True,
}
return TemplateResponse(request, "account.html", data)


@login_required
Expand Down Expand Up @@ -123,9 +141,7 @@ def issue_thread(request, thread_id=None):
},
"contributors": [
Account.objects.chip_summarize(a)
for a in Account.objects.filter(
pk__in=c_qs.values("author").distinct()
)
for a in Account.objects.filter(pk__in=c_qs.values("author").distinct())
],
"category": {"id": t.category.id, "name": t.category.name},
"categories": [{"id": c.id, "name": c.name} for c in Category.objects.all()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<li class="tab"><a href="#issues">MY ISSUES</a></li>
{% if request.user.username == username|stringformat:"s" %}
<li class="tab">
<a href="#settings">EDIT PROFILE</a>
<a href="#settings">Settings</a>
</li>
{% endif %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
<!-- TODO: Content swipes up for edit functions -->
<div class="account-edit scroll-col">
<div class="section">
<div class="section">
<div class="card">
<div class="card-content">
<div class="row">
<div class="title-lato center">Edit Profile</div>
{% verbatim %}
<!-- <div class="white-background-input-field input-field col s6">
<input class="save-account" id="first_name" type="text" value="{{this.model.get('first_name')}}">
<label for="first-name">First Name</label>
</div>
<div class="white-background-input-field input-field col s6">
<input class="save-account" id="last_name" type="text" value="{{this.model.get('last_name')}}">
<label for="last-name">Last Name</label>
</div> -->
<div class="white-background-input-field input-field col s12">
<input class="save-account" id="about_me" type="text" value="{{this.model.get('about_me')}}">
<label for="zipcode">About Me</label>
</div>

<div class="white-background-input-field input-field col s12">
<form method="post" enctype="multipart/form-data" id="profile_image_form">
<div class="section">
<label for="profile_image_form">Profile Image</label>
</div>
<div class="section">
<div id="confirmation-prompt" class="center hide">This is only a preview image. Press confirm to finish your upload.</div>
</div>
<div class="z-index-1 center">
<img class="preview-image responsive-img" id="profile-image" src="{{this.model.get('profile_image')}}">
</div>
<div class="file-field input-field col s12 m8 push-m2" >
<input class="upload-image btn waves-effect hide" type="submit" value="Confirm Upload"/>
<div class="btn profile-image-pick">
<span>Choose Image</span>
<input id="id_profile_image" name="profile_image" type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</form>
<div class="card">
<div class="card-content">
{% include "accounts/utils/update_settings_form.html" %}
</div>
{% endverbatim %}
</div>
</div>
</div>
</div>
</div>
</div>