Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mymusiclist
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Guadalupe
mymusiclist
Commits
1caae979
Commit
1caae979
authored
Oct 30, 2017
by
Brian Guadalupe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Users can now edit their profiles
parent
0e718e46
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
13 deletions
+48
-13
views.py
core/views.py
+20
-6
urls.py
mymusiclist/urls.py
+6
-4
edit_profile.html
templates/edit_profile.html
+19
-0
profile.html
templates/profile.html
+3
-3
No files found.
core/views.py
View file @
1caae979
...
@@ -6,6 +6,7 @@ from django.contrib.auth import login, authenticate
...
@@ -6,6 +6,7 @@ from django.contrib.auth import login, authenticate
# from django.contrib.auth.forms import UserCreationForm
# from django.contrib.auth.forms import UserCreationForm
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.views.generic.edit
import
UpdateView
from
core.forms
import
SignUpForm
from
core.forms
import
SignUpForm
...
@@ -26,10 +27,23 @@ def signup(request):
...
@@ -26,10 +27,23 @@ def signup(request):
def
home
(
request
):
def
home
(
request
):
return
render
(
request
,
'home.html'
)
return
render
(
request
,
'home.html'
)
def
user_profile_page
(
request
,
username
):
def
user_profile_page
(
request
,
slug
):
user
=
get_object_or_404
(
User
,
username
=
username
)
user
=
get_object_or_404
(
User
,
username
=
slug
)
return
render
(
request
,
'profile.html'
,
{
'profile'
:
user
})
return
render
(
request
,
'profile.html'
,
{
'profile'
:
user
})
# if request.user.is_authenticated:
# return render(request, 'profile.html')
class
EditProfile
(
UpdateView
):
# else:
model
=
User
# return render(request, 'profile_public.html')
fields
=
[
'username'
,
'email'
,
'first_name'
,
'last_name'
]
template_name
=
'edit_profile.html'
slug_field
=
'username'
slug_url_kwarg
=
'slug'
# def edit_profile(request, username):
# if request.method == 'POST':
# form = EditProfile(request.POST, instance=request.user)
# if form.is_valid():
# form.save()
# return HttpResponseRedirect(reverse('update_profile_success'))
# else:
# form = EditProfile(initial={'username': request.user.username, 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name})
# return render(request, 'edit_profile.html', {'form': form})
\ No newline at end of file
mymusiclist/urls.py
View file @
1caae979
...
@@ -14,16 +14,18 @@ Including another URLconf
...
@@ -14,16 +14,18 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
"""
from
django.conf.urls
import
url
from
django.conf.urls
import
url
from
django.urls
import
reverse_lazy
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.contrib.auth
import
views
as
auth_views
from
django.contrib.auth
import
views
as
auth_views
from
core
import
views
as
core_views
from
core
import
views
as
core_views
"""import * pls"""
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^login/$'
,
auth_views
.
login
,
{
'template_name'
:
'login.html'
},
name
=
'login'
),
url
(
r'^login/$'
,
auth_views
.
login
,
{
'template_name'
:
'login.html'
},
name
=
'login'
),
url
(
r'^logout/$'
,
auth_views
.
logout
,
{
'template_name'
:
'logged_out.html'
},
name
=
'logout'
),
url
(
r'^logout/$'
,
auth_views
.
logout
,
{
'template_name'
:
'logged_out.html'
},
name
=
'logout'
),
url
(
r'^admin/'
,
admin
.
site
.
urls
),
url
(
r'^admin/'
,
admin
.
site
.
urls
),
url
(
r'^signup/'
,
core_views
.
signup
,
name
=
'signup'
),
url
(
r'^signup/$'
,
core_views
.
signup
,
name
=
'signup'
),
url
(
r'^profile/(?P<username>[A-Za-z0-9-+_.@]+)/$'
,
core_views
.
user_profile_page
,
name
=
'profile'
),
url
(
r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$'
,
core_views
.
user_profile_page
,
name
=
'viewprofile'
),
url
(
r'^$'
,
core_views
.
home
),
url
(
r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$'
,
core_views
.
EditProfile
.
as_view
(
success_url
=
reverse_lazy
(
'home'
)),
name
=
'editprofile'
),
# url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', core_views.EditProfile.as_view(success_url=reverse_lazy('profile', kwargs={'update':'true'})), name='editprofile'),
url
(
r'^$'
,
core_views
.
home
,
name
=
'home'
),
]
]
templates/edit_profile.html
0 → 100644
View file @
1caae979
{% extends 'base.html' %}
{% block title %}Edit Profile{% endblock %}
{% block content %}
<div
class=
"boxified main profile"
>
{% if request.user.is_authenticated %}
<h2>
Edit Profile
</h2>
<!-- <form method="post"> -->
<form
method=
"post"
action=
"{% url 'editprofile' slug=user.username %}"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
class=
"buttoned"
>
Save changes
</button>
</form>
{% else %}
<p>
Please
<a
href=
"{% url 'login' %}"
>
log in
</a>
to your account to edit your profile.
</p>
{% endif %}
</div>
{% endblock %}
templates/profile.html
View file @
1caae979
...
@@ -4,18 +4,18 @@
...
@@ -4,18 +4,18 @@
{% block content %}
{% block content %}
<div
class=
"boxified main profile"
>
<div
class=
"boxified main profile"
>
{% if user.is_authenticated %}
{% if
request.
user.is_authenticated %}
<h2>
{{profile.username}}'s Profile
</h2>
<h2>
{{profile.username}}'s Profile
</h2>
<ul>
<ul>
<li><strong>
First Name:
</strong>
{{profile.first_name}}
</li>
<li><strong>
First Name:
</strong>
{{profile.first_name}}
</li>
<li><strong>
Last Name:
</strong>
{{profile.last_name}}
</li>
<li><strong>
Last Name:
</strong>
{{profile.last_name}}
</li>
<li><strong>
Email Address:
</strong>
{{profile.email}}
</li>
<li><strong>
Email Address:
</strong>
{{profile.email}}
</li>
</ul>
</ul>
{% if profile.username ==
user.username and
user.is_authenticated %}
{% if profile.username ==
request.user.username and request.
user.is_authenticated %}
<a
href=
"edit"
class=
"buttoned"
>
Edit user profile
</a>
<a
href=
"edit"
class=
"buttoned"
>
Edit user profile
</a>
{% endif %}
{% endif %}
{% else %}
{% else %}
<p>
Please
<a
href=
"
/login
"
>
log in
</a>
to your account to view {{profile.username}}'s profile.
</p>
<p>
Please
<a
href=
"
{% url 'login' %}
"
>
log in
</a>
to your account to view {{profile.username}}'s profile.
</p>
{% endif %}
{% endif %}
</div>
</div>
{% endblock %}
{% endblock %}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment