Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ea5c2a3
lab-01 v2
austenc-id Dec 14, 2021
9f37a86
resolve conflicts
austenc-id Dec 16, 2021
b053aab
Merge branch 'Austen' into austen-js-01
austenc-id Dec 16, 2021
2f5a844
resolve conflicts
austenc-id Dec 16, 2021
2d36911
ignore secretes.js
austenc-id Dec 22, 2021
ed5a318
Merge branch 'master' into austen-js-01
austenc-id Dec 22, 2021
0ba4d52
Merge branch 'master' of https://github.com/PdxCodeGuild/Class_Raven
colburnlee Dec 23, 2021
4f5cc2b
Merge branch 'master' into austen-js-01
austenc-id Dec 28, 2021
8d22fb8
completed v3
austenc-id Dec 28, 2021
d2fdf22
Merge branch 'master' into austen-js-01
austenc-id Dec 28, 2021
4a79174
update tracker
austenc-id Dec 28, 2021
4958401
add space around ## links
austenc-id Dec 28, 2021
c38e927
Merge branch 'master' of https://github.com/PdxCodeGuild/Class_Raven
colburnlee Dec 29, 2021
969405b
created new branch
ArktheTark Dec 29, 2021
2f56820
app initialization
austenc-id Dec 30, 2021
5b308b1
it sucks but it works
austenc-id Dec 30, 2021
9514f56
move from working directory
austenc-id Dec 31, 2021
f77204a
init flask app
austenc-id Dec 31, 2021
7189da6
commit to switch branch
austenc-id Dec 31, 2021
23a1306
it sucks but it works
austenc-id Dec 31, 2021
ca44f07
adding lab1 as complete
colburnlee Dec 31, 2021
bf5741a
Merge branch 'master' of https://github.com/PdxCodeGuild/Class_Raven
colburnlee Dec 31, 2021
8675f22
Merge branch 'master' into lee-django-lab01
colburnlee Dec 31, 2021
9d72685
Just need to figure out foreign key issue
ArktheTark Jan 2, 2022
88bfdea
Merge branch 'master' into arek-dj-lab1
ArktheTark Jan 4, 2022
15fcfda
saving changes
ArktheTark Jan 4, 2022
fafd17b
removed un needed fileds causing constraints
ArktheTark Jan 4, 2022
0ff06b0
made code simpler with .get_or_create method and fixed issue of priot…
ArktheTark Jan 4, 2022
9dc34c1
Submitting Lab1
ArktheTark Jan 4, 2022
ff40614
update, detail and logout urls, views and templates
perennialAutodidact Jan 5, 2022
d17506f
adjusted styling
perennialAutodidact Jan 5, 2022
849eb49
Merge branch 'master' into austen-js-01
perennialAutodidact Jan 5, 2022
1c0d3b4
Merge pull request #291 from PdxCodeGuild/austen-js-01
perennialAutodidact Jan 5, 2022
20bbdf1
Merge branch 'master' into austen-tracker
perennialAutodidact Jan 5, 2022
16b7c01
Merge pull request #292 from PdxCodeGuild/austen-tracker
perennialAutodidact Jan 5, 2022
d8e774b
Merge branch 'master' into austen-flask-01
perennialAutodidact Jan 5, 2022
ee3ec2e
Merge pull request #293 from PdxCodeGuild/austen-flask-01
perennialAutodidact Jan 5, 2022
166409b
Merge branch 'master' into austen-flask-02
perennialAutodidact Jan 5, 2022
34ae5de
Merge pull request #294 from PdxCodeGuild/austen-flask-02
perennialAutodidact Jan 5, 2022
2eeeee2
added django lab2 and Django resources
perennialAutodidact Jan 5, 2022
c94c29d
added hyphen
perennialAutodidact Jan 5, 2022
1b6525f
Merge branch 'master' into lee-django-lab01
perennialAutodidact Jan 5, 2022
af8b7a2
Merge pull request #295 from PdxCodeGuild/lee-django-lab01
perennialAutodidact Jan 5, 2022
478d0c7
fixed 404 error on port 8000
ArktheTark Jan 5, 2022
b27495a
Merge branch 'master' into arek-dj-lab1
perennialAutodidact Jan 5, 2022
2380823
Merge pull request #296 from PdxCodeGuild/arek-dj-lab1
perennialAutodidact Jan 5, 2022
dc4540b
added venv instructions and screenshots
perennialAutodidact Jan 5, 2022
a11dedb
Merge branch 'master' of github.com:PdxCodeGuild/Class_Raven
perennialAutodidact Jan 5, 2022
4caad2d
fixed spacing
perennialAutodidact Jan 5, 2022
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
8 changes: 7 additions & 1 deletion 4 Django/demo/picster/picster_proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@
# direct django to the project-level static folder
STATICFILES_DIRS = [str(BASE_DIR.joinpath('static'))]

# root directory for media files
MEDIA_ROOT = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# redefine the default auth user model from our users app
AUTH_USER_MODEL = 'users_app.User'
AUTH_USER_MODEL = 'users_app.User'

# tell django where to redirect if not logged in
LOGIN_URL = '/users/login'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion 4 Django/demo/picster/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@
<title>Picster</title>
</head>
<body>
{% include 'partials/_navbar.html' %}
<main class="container">

{% if errors %}
{{errors}}
<div class="row w-100">
{% for error in errors %}
<div class="col-12 col-lg-6 offset-lg-3">
<div class="position-absolute start-50 translate-middle alert alert-danger alert-dismissible fade show d-flex align-items-center" role="alert">
{{error}}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
{% endfor %}
</div>
{% endif %}

{% block content %}
Expand Down
42 changes: 42 additions & 0 deletions 4 Django/demo/picster/templates/partials/_navbar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{%load static%}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Picster</a>
<a href="" class='link-success'>
<i class="far fa-plus-square large-icon"></i>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav w-100 d-flex justify-content-end">
<div class="d-flex gap-2">

{% if request.user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">Logout</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<img src="{% static user.avatar.url %}" height=40 width=40 alt="{{user.username}}'s avatar">
</a>
</li>
</div>

{% else %}
<div class="d-flex gap-2">

<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</div>

</ul>
{% endif %}
</div>
</div>
</nav>
68 changes: 68 additions & 0 deletions 4 Django/demo/picster/templates/users/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}

<div class="row">
<div class="col-12 col-lg-8 offset-lg-2 d-flex gap-3 flex-column align-items-center pt-5">
<h1 class="h1 py-2">{{user.username}}</h1>
{% if request.user == user %}
<a href="{% url 'users_app:update' user.username %}" class='link-secondary'>
<i class="fas fa-edit"></i>
</a>
{% endif %}
<img src="{% static user.avatar.url %}" alt="{{user.username}}'s avatar" class="rounded-circle shadow" height=250 width=250>
</div>

<div class="col-8 offset-2 col-lg-4 offset-lg-4 pt-5">
<table class="table">
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">First</th>
<td>
{% if user.first_name %}
{{user.first_name}}
{% else %}
Not Provided
{% endif %}
</td>
</tr>
<tr>
<th scope="row">Last</th>
<td>{% if user.last_name %}
{{user.last_name}}
{% else %}
Not Provided
{% endif %}</td>
</tr>
<tr>
<th scope="row">Joined</th>
<td colspan="2">{{user.date_joined|date}}</td>
</tr>
<tr>
<th scope="row">Pics</th>
<td colspan="2">0</td>
</tr>
<tr>
<th scope="row">Followers</th>
<td colspan="2">0</td>
</tr>
<tr>
<th scope="row">Following</th>
<td colspan="2">0</td>
</tr>
</tbody>
</table>
</div>
</div>

<h1 class="h1">Pics</h1>
<div class="row d-flex justify-content-center pb-5 mb-5">
<!-- render user's pics -->
</div>


{% endblock content %}
25 changes: 25 additions & 0 deletions 4 Django/demo/picster/templates/users/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'base.html' %}

{% block content %}
<h1 class="h1 text-center">Log in</h1>


<form action="{% url 'users_app:login' %}" method='POST' class='d-flex flex-column align-items-center gap-3'>

<!-- {{form}} will render the entire form -->
<fieldset>
<label for="id_username">{{form.username.label}}</label>
{{form.username}}
</fieldset>

<fieldset>
<label for="id_password">{{form.password.label}}</label>
{{form.password}}
</fieldset>

{% csrf_token %}

<button type='submit' class='btn btn-success'>Log in</button>
</form>

{% endblock content %}
2 changes: 1 addition & 1 deletion 4 Django/demo/picster/templates/users/register.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}

{% block content %}
<h1 class="h1">Register</h1>
<h1 class="h1 text-center">Register</h1>


<form action="{% url 'users_app:register' %}" method='POST' class='d-flex flex-column align-items-center gap-3'>
Expand Down
25 changes: 25 additions & 0 deletions 4 Django/demo/picster/templates/users/update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% load static %}


{% block content %}

<div class="row">
<div class="col-12 col-lg-8 offset-lg-2 d-flex flex-column align-items-center pt-5">
<h1 class="h1 py-2">{{user.username}}</h1>
<img src="{% static user.avatar.url %}" alt="{{user.username}}'s avatar"
class='rounded-circle shadow' height=250 width=250>
</div>


<div class="col-10 offset-1 col-lg-4 offset-lg-4">
<form action="{% url 'users_app:update' user.username %}" enctype='multipart/form-data' method='POST' class='d-flex flex-column gap-2'>
{% csrf_token %}
{{form}}
<button type='submit' class='btn btn-success'>Update</button>
</form>
</div>

</div>

{% endblock content %}
6 changes: 5 additions & 1 deletion 4 Django/demo/picster/users_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@

app_name = 'users_app'
urlpatterns = [
path('register/', views.register, name='register')
path('register/', views.register, name='register'),
path('login/', views.login, name='login'),
path('logout/', views.logout, name='logout'),
path('<str:username>/', views.detail, name='detail'),
path('update/<str:username>/', views.update, name='update'),
]
97 changes: 94 additions & 3 deletions 4 Django/demo/picster/users_app/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from django.shortcuts import render, redirect, reverse
from django.shortcuts import get_object_or_404, render, redirect, reverse
from django.contrib.auth import (
get_user_model, # returns the AUTH_USER_MODEL variable's value from settings.py
authenticate,
login as django_login,
logout as django_logout
)
from django.contrib.auth.decorators import login_required

from .forms import UserForm, UserAuthForm

Expand Down Expand Up @@ -39,7 +46,91 @@ def register(request):
else:
context = {
'form': UserAuthForm(),
'errors': form.errors
'errors': [value for value in form.errors.values()]
}

return render(request, 'users/register.html', context)
return render(request, 'users/register.html', context)


def login(request):
if request.method == 'GET':
# blank form
form = UserAuthForm()
return render(request, 'users/login.html', {'form': form})

elif request.method == 'POST':
# get the form data from the request
form = request.POST

username = form['username']
password = form['password']

# attempt authentication with the given credentials
user = authenticate(request, username=username, password=password)

# if the form credentials are not valid, render the login page with an error
if user is None:
context = {
'form': UserAuthForm(),
'errors': ['Invalid Username or Password']
}

return render(request, 'users/login.html', context)

else:

# login the user
django_login(request, user)

# redirect to the user's detail page
return redirect(reverse('users_app:detail', kwargs={'username': user.username}))


def detail(request, username):
# find the desired user
user = get_object_or_404(get_user_model(), username=username)
return render(request, 'users/detail.html', {'user': user})

@login_required
def update(request, username):
user = get_object_or_404(get_user_model(), username=username)

if request.method == 'GET':
# create a UserForm with the current user data
form = UserForm(instance=user)

return render(request, 'users/update.html', {'form': form})

elif request.method == 'POST':
# create a UserForm with the form data and
# the User instance to which to apply the changes
form = UserForm(request.POST, instance=user)

# the file from the form will be within request.FILES
# add the filename to the initial form data
new_avatar = request.FILES.get('avatar')

# if a file was uploaded, add it to the form
if new_avatar:
form.initial['avatar'] = new_avatar

if form.is_valid():
# update the user instance with the new data
form.save()

# redirect to the user's detail page
return redirect(reverse('users_app:detail', kwargs={'username': user.username}))

else:
errors = [value for value in form.errors.values()]
context = {
'user': user,
'errors': errors
}

return render(request, 'users/update.html', context)

def logout(request):
django_logout(request)

return redirect(reverse('users_app:login'))
Loading