Skip to content

Commit

Permalink
user categories to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOsahenru committed Nov 1, 2022
1 parent 02b4346 commit c359526
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions project/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,29 @@ class ProfileEditForm(forms.ModelForm):

class Meta:
model = Profile

fields = [
"first_name",
"last_name",
"about_me",
"profile_image",
"username",
"email",
"categories",
]
widgets = {"categories": forms.CheckboxSelectMultiple()}

first_name = forms.CharField(label="First Name", max_length=63, required=False)
last_name = forms.CharField(label="Last Name", max_length=63, required=False)
about_me = forms.CharField(label="About Me", max_length=511, required=False)
email = forms.EmailField(label="Email", disabled=True)
username = forms.CharField(label="Username", disabled=True)
profile_image = forms.ImageField(required=False)
# categories = forms.ModelMultipleChoiceField(
# queryset=Category.objects.all(),
# required=False,
# widget=forms.CheckboxSelectMultiple
# )


class UpdatePassword(forms.ModelForm):
Expand Down
23 changes: 14 additions & 9 deletions project/accounts/templates/accounts/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

<!-- Prevent users from following themselves. -->
{% if not profile == request.user.profile %}
{% if profile not in request.user.profile.following.all %}
<a href="{% url 'profile-follow' profile.user.username %}" class="waves-effect waves-light btn follow-btn" id="sidebar-follow-btn">
follow
</a>
{% else %}
<a href="{% url 'profile-unfollow' profile.user.username %}" class="waves-effect waves-light btn follow-btn" id="sidebar-follow-btn">
unfollow
</a>
{% endif %}
{% if profile not in request.user.profile.following.all %}
<a href="{% url 'profile-follow' profile.user.username %}" class="waves-effect waves-light btn follow-btn" id="sidebar-follow-btn">
follow
</a>
{% else %}
<a href="{% url 'profile-unfollow' profile.user.username %}" class="waves-effect waves-light btn follow-btn" id="sidebar-follow-btn">
unfollow
</a>
{% endif %}
{% endif %}

<div class="user-info section">
Expand All @@ -45,6 +45,11 @@
<div class="section-title">ABOUT ME</div>
<div class="divider"></div>
<div class="about-me">{{ profile.about_me }}</div>
<div class="divider"></div>
<div class="section-title">CATEGORIES</div>
{% for category in categories %}
<div class="about-me">{{ category.name }}</div>
{% endfor %}
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions project/accounts/templates/accounts/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
</div>
</div>
<div class="row center">
{%if not readonly %}
{% if not readonly %}
<button class='btn' type='submit' value="Save Changes">Save Changes</button>
{% endif%}
{% endif %}
</div>
</form>
<div class="row center">
Expand All @@ -86,7 +86,7 @@
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function(event) {
const button = document.getElementById('delete-account-button');

button.addEventListener('click', (event) => {
// Confirm user intent before committing to expunge
if (window.confirm('Are you certain you want to expunge your information? This action is irreversible.')) {
Expand Down
3 changes: 3 additions & 0 deletions project/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def get_initial(self):
"last_name": profile.last_name or None,
"about_me": profile.about_me or None,
"profile_image": profile.profile_image or None,
"categories": profile.categories.add() or None,
}
)
return super(SettingsView, self).get_initial()
Expand All @@ -178,12 +179,14 @@ class UserProfileView(LoginRequiredMixin, View):

def get(self, request, username=None):
profile = get_object_or_404(Profile, user__username=username)
categories = profile.categories.all()

return TemplateResponse(
request,
"account.html",
{
"profile": profile,
"categories": categories,
},
)

Expand Down

0 comments on commit c359526

Please sign in to comment.