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

Deborah's-Branch #7

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0b62880
Recorded successfully
leportella Jul 15, 2021
0e342ea
recorded successfully
leportella Jul 16, 2021
da99029
recorded successfully
leportella Jul 16, 2021
4c8b3c4
recorded successfully
leportella Jul 16, 2021
e640ce9
recorded successfully
leportella Jul 18, 2021
a1bc741
recorded successfully
leportella Jul 18, 2021
9c491e8
recorded successfully
leportella Jul 18, 2021
4a047e5
recorded successfully
leportella Jul 19, 2021
f7b4497
recorded successfully
leportella Jul 19, 2021
0cbc90c
recorded successfully
leportella Jul 19, 2021
b64f063
recorded successfully
leportella Jul 26, 2021
d92281b
recorded successfully
leportella Jul 27, 2021
ce11cbb
recorded successfully
leportella Jul 27, 2021
a5d2bd3
use base.html in all templates
leportella Jul 27, 2021
a32b25c
recorded successfully
leportella Jul 27, 2021
80acac1
add some more styles
leportella Jul 27, 2021
16d68c6
recorded successfully
leportella Jul 27, 2021
b028e5b
recorded successfully
leportella Jul 28, 2021
74d3e92
recorded successfully
leportella Jul 28, 2021
bacdb74
recorded successfully
leportella Jul 28, 2021
4b8fef3
remove unnecessary validation
leportella Jul 28, 2021
c3a84c2
recorded successfully
leportella Jul 28, 2021
801568b
align buttons on notes_form.html
leportella Jul 28, 2021
2b8d5f1
recorded successfully
leportella Jul 28, 2021
909ec3d
recorded successfully
leportella Jul 28, 2021
8ff1f01
recorded successfully
leportella Jul 28, 2021
5a98aa3
require login in all endpoints
leportella Aug 1, 2021
db9050d
recorded successfully
leportella Aug 1, 2021
3b832dc
recorded successfully
leportella Aug 1, 2021
9e8cd80
change login_url
leportella Aug 1, 2021
66d38a8
cleanup
leportella Aug 1, 2021
c1865f6
recorded successfully
leportella Aug 1, 2021
943b291
recorded successfully
leportella Aug 1, 2021
994be48
recorded successfully
leportella Aug 6, 2021
3d49b6d
Update views.py
nichollsspencer Sep 14, 2021
66f5adb
Moving files using main
Sep 27, 2021
76e693e
Got the virtual branch working on smartsheets
Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
36 changes: 34 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,44 @@ All Rights Reserved.
Licensed under the LinkedIn Learning Exercise File License (the "License").
See LICENSE in the project root for license information.

ATTRIBUTIONS:
[PLEASE PROVIDE ATTRIBUTIONS OR DELETE THIS AND THE ABOVE LINE “ATTRIBUTIONS”]
Django
https://github.com/django/django
Copyright (c) Django Software Foundation and individual contributors
License: BSD-3-Clause
https://opensource.org/licenses/BSD-3-Clause

Please note, this project may automatically load third party code from external
repositories (for example, NPM modules, Composer packages, or other dependencies).
If so, such third party code may be subject to other license terms than as set
forth above. In addition, such third party code may also depend on and load
multiple tiers of dependencies. Please review the applicable licenses of the
additional dependencies.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

BSD-3-Clause

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of Django nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# COURSENAME
This is the repository for the LinkedIn Learning course `course-name`. The full course is available from [LinkedIn Learning][lil-course-url].
# Django Essential Training
This is the repository for the LinkedIn Learning course Django Essential Training. The full course is available from [LinkedIn Learning][lil-course-url].

![course-name-alt-text][lil-thumbnail-url]
![Django Essential Training][lil-thumbnail-url]

Django is a robust and powerful framework with a lot of moving parts. Although starting a new project can be quite easy, there is a lot to uncover. This course teaches fundamentals, such as what a framework is, what an HTTP request is, and how Django replies to HTTP requests. Software developer and podcaster Leticia Portella walks you through each step of building a working system that can create, edit, and list books per user with an authentication system. Topics include getting started, creating users and data, ORMs, creating a dynamic template, Django class-based files and static views, and so much more!

_See the readme file in the main branch for updated instructions and information._
## Instructions
This repository has branches for each of the videos in the course. You can use the branch pop up menu in github to switch to a specific branch and take a look at the course at that stage, or you can add `/tree/BRANCH_NAME` to the URL to go to the branch you want to access.

Expand All @@ -29,8 +30,15 @@ To resolve this issue:
3. [Course-specific instructions]


[0]: # (Replace these placeholder URLs with actual course URLs)
### Instructor

Leticia Portella





[lil-course-url]: https://www.linkedin.com/learning/
[lil-thumbnail-url]: http://
Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/leticia-portella).

[lil-course-url]: https://www.linkedin.com/learning/django-essential-training
[lil-thumbnail-url]: https://cdn.lynda.com/course/2894047/2894047-1632244073199-16x9.jpg
Empty file added home/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions home/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions home/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class HomeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'home'
Empty file added home/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions home/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
5 changes: 5 additions & 0 deletions home/templates/home/authorized.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.html" %}

{% block content %}
<h1>You are in a restricted area</h1>
{% endblock %}
9 changes: 9 additions & 0 deletions home/templates/home/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}

<form method='post'>{% csrf_token %}
{{form.as_p}}
<input type='submit' class="btn btn-secondary"/>
</form>

{% endblock %}
6 changes: 6 additions & 0 deletions home/templates/home/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% block content %}

<h1>Hope to see you soon :)</h1>

{% endblock %}
9 changes: 9 additions & 0 deletions home/templates/home/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}

<form method='POST' style='text-align: left; margin: 0 auto; width: 600px;'>{% csrf_token %}
{{form.as_p}}
<input class='btn btn-secondary' type='submit' name='Submit'/>
</form>

{% endblock %}
7 changes: 7 additions & 0 deletions home/templates/home/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}

{% block content %}
<h1>Welcome to SmartNotes!</h1>
<p>Today is {{today}}</p>
<a href="{% url 'notes.list' %}" class="btn btn-primary">Check out these smart notes!</a>
{% endblock %}
3 changes: 3 additions & 0 deletions home/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions home/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
path('login', views.LoginInterfaceView.as_view(), name='login'),
path('logout', views.LogoutInterfaceView.as_view(), name='logout'),
path('signup', views.SignupView.as_view(), name='signup'),
]
32 changes: 32 additions & 0 deletions home/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from datetime import datetime
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.views import LoginView, LogoutView
from django.contrib.auth.forms import UserCreationForm

from django.shortcuts import redirect

class SignupView(CreateView):
form_class = UserCreationForm
template_name = 'home/register.html'
success_url = '/smart/notes'

def get(self, request, *args, **kwargs):
if self.request.user.is_authenticated:
return redirect('notes.list')
return super().get(request, *args, **kwargs)

class LogoutInterfaceView(LogoutView):
template_name = 'home/logout.html'

class LoginInterfaceView(LoginView):
template_name = 'home/login.html'

class HomeView(TemplateView):
template_name = 'home/welcome.html'
extra_context = {'today': datetime.today()}

class AuthorizedView(LoginRequiredMixin, TemplateView):
template_name = 'home/authorized.html'
login_url = '/admin'
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'smartnotes.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file added notes/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions notes/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin

from . import models

class NotesAdmin(admin.ModelAdmin):
list_display = ('title',)

admin.site.register(models.Notes, NotesAdmin)
6 changes: 6 additions & 0 deletions notes/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NotesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'notes'
16 changes: 16 additions & 0 deletions notes/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import forms
from django.core.exceptions import ValidationError

from .models import Notes

class NotesForm(forms.ModelForm):
class Meta:
model = Notes
fields = ('title', 'text')
widgets = {
'title': forms.TextInput(attrs={'class': 'form-control my-5'}),
'text': forms.Textarea(attrs={"class": "form-control mb-5"})
}
labels = {
'text': 'Write your thoughts here:'
}
23 changes: 23 additions & 0 deletions notes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.2 on 2021-07-18 15:28

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Notes',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('text', models.TextField()),
('created', models.DateTimeField(auto_now_add=True)),
],
),
]
22 changes: 22 additions & 0 deletions notes/migrations/0002_notes_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.2 on 2021-07-28 21:40

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('notes', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='notes',
name='user',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='auth.user'),
preserve_default=False,
),
]
Empty file added notes/migrations/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions notes/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models
from django.contrib.auth.models import User

class Notes(models.Model):
title = models.CharField(max_length=200)
text = models.TextField()
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="notes")
11 changes: 11 additions & 0 deletions notes/templates/notes/notes_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base.html' %}

{% block content %}
<form method='post'>{% csrf_token %}
<p>Are you sure you want to delete "{{notes.title}}"?</p>
<p>This action can't be undone</p>

<input type="submit" class="btn btn-danger" value="Confirm"/>
</form>

{% endblock %}
12 changes: 12 additions & 0 deletions notes/templates/notes/notes_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<div class="border round">
<h1 class="my-5">{{note.title}}</h1>
<p>{{note.text}}</p>
</div>

<a href="{% url 'notes.list' %}" class="btn btn-secondary my-5">Back</a>
<a href="{% url 'notes.update' pk=note.id %}" class="btn btn-secondary">Edit</a>
<a href="{% url 'notes.delete' pk=note.id %}" class="btn btn-danger">Delete</a>
{% endblock %}
16 changes: 16 additions & 0 deletions notes/templates/notes/notes_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base.html' %}

{% block content %}

<form method='POST'>{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary my-5">Submit</button>
<a href="{% url 'notes.list'%}" class="btn btn-secondary">Cancel</a>
</form>
{% if form.errors %}
<div class="alert alert-danger my-5">
{{form.errors.title.as_text}}
</div>
{% endif %}

{% endblock %}
20 changes: 20 additions & 0 deletions notes/templates/notes/notes_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base.html" %}

{% block content %}
<h1 class="my-5">These are the notes:</h1>

<div class="row row-cols3 g-2">
{% for note in notes %}
<div class="col">
<div class="p-3 border">
<a href="{% url 'notes.detail' pk=note.id %}" class="text-dark text-decoration-non">
<h3>{{note.title}}</h3>
</a>
{{note.text|truncatechars:10}}

</div>
</div>
{% endfor %}

</div>
{% endblock %}
3 changes: 3 additions & 0 deletions notes/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
11 changes: 11 additions & 0 deletions notes/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path

from . import views

urlpatterns = [
path('notes', views.NotesListView.as_view(), name="notes.list"),
path('notes/<int:pk>', views.NotesDetailView.as_view(), name="notes.detail"),
path('notes/<int:pk>/edit', views.NotesUpdateView.as_view(), name="notes.update"),
path('notes/<int:pk>/delete', views.NotesDeleteView.as_view(), name="notes.delete"),
path('notes/new', views.NotesCreateView.as_view(), name="notes.new"),
]
Loading