-
Notifications
You must be signed in to change notification settings - Fork 0
Jdom/josepost #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ __pycache__/ | |
| .DS_Store | ||
| *.py[cod] | ||
| *.swp | ||
| *.py.save | ||
|
|
||
| /.* | ||
| !/.gitignore | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
|
|
||
| # python manage.py runserver | ||
|
|
||
| # python manage.py migrate | ||
| # python manage.py migrate | ||
|
|
||
| #DOUBT: tests.py -> 'href="{0}"'.format(homepage_url) what does "{0}" mean? | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,8 @@ | |
| from django.contrib import admin | ||
|
|
||
| # Register your models here. | ||
| from django.contrib import admin | ||
| from .models import Board | ||
|
|
||
| admin.site.register(Board) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, you haven't reach that yet, but you can also configure your own admin classes. I.e.: This is actually very easy to use and extremely useful. Try including Board attributes on the Like: etc You can also build admins for the rest of the models! Don't forget to register them! 😄 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,49 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from django.urls import reverse, resolve | ||
| from django.test import TestCase | ||
| from .views import home | ||
| from .views import home, board_topics | ||
| from .models import Board | ||
| from django.db import models | ||
|
|
||
|
|
||
|
|
||
| class HomeTests(TestCase): | ||
| def test_home_view_status_code(self): | ||
| def setUp(self): | ||
| self.board = Board.objects.create(name='DjangoTest', description='This is another django test') | ||
| url = reverse('home') | ||
| response = self.client.get(url) | ||
| self.assertEquals(response.status_code, 200) | ||
| self.response = self.client.get(url) | ||
|
|
||
| def test_home_view_status_code(self): | ||
| self.assertEquals(self.response.status_code, 200) | ||
|
|
||
| def test_home_url_resolves_home_view(self): | ||
| view = resolve('/homepage/') | ||
| self.assertEquals(view.func, home) | ||
|
|
||
| def test_home_view_contains_link_to_topics_page(self): | ||
| board_topics_url = reverse('board_topics', kwargs={'pk': self.board.pk}) | ||
| self.assertContains(self.response, 'href="{0}"'.format(board_topics_url)) | ||
|
|
||
| class BoardTopicsTests(TestCase): | ||
| def setUp(self): | ||
| Board.objects.create(name='Django_test', description='Django board to test') | ||
|
|
||
| def test_board_topics_view_success_status_code(self): | ||
| url = reverse('board_topics', kwargs={'pk': 1}) | ||
| response = self.client.get(url) | ||
| self.assertEquals(response.status_code, 200) | ||
|
|
||
| def test_board_topics_view_not_found_status_code(self): | ||
| url = reverse('board_topics', kwargs={'pk': 99}) | ||
| response = self.client.get(url) | ||
| self.assertEquals(response.status_code, 404) | ||
|
|
||
| def test_board_topics_url_resolves_board_topics_view(self): | ||
| view = resolve('/boards/1/') | ||
| self.assertEquals(view.func, board_topics) | ||
|
|
||
| def test_board_topics_view_contains_link_back_to_homepage(self): | ||
| homepage_url = reverse('home') | ||
| board_topics_url = reverse('board_topics', kwargs={'pk': 1}) | ||
| response = self.client.get(board_topics_url) | ||
| self.assertContains(response, 'href="{0}"'.format(homepage_url)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from boards import views | ||
|
|
||
| urlpatterns = [ | ||
| url(r'^homepage/$',views.home,name='home'), | ||
| url(r'^homepage/$', views.home, name='home'), | ||
| url(r'^boards/(?P<pk>\d+)/$', views.board_topics, name='board_topics'), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually comes from an old django version, <3.0 for sure. The syntax changes a bit to |
||
| url(r'^admin/', admin.site.urls), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,10 @@ | |
| <ol class="breadcrumb my-4"> | ||
| <li class="breadcrumb-item active">Boards</li> | ||
| </ol> | ||
| <table border="1"> | ||
| <thead> | ||
| <table class="table"> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Element In CSS, you can apply the style to the element, in this case or the class, in this case..... First one applies to all elements |
||
| <thead class="thead-inverse"> | ||
| <tr> | ||
| <th>Board --------------------</th> | ||
| <th>Board</th> | ||
| <th>Posts</th> | ||
| <th>Topics</th> | ||
| <th>Last Post</th> | ||
|
|
@@ -23,11 +23,11 @@ | |
| {% for board in boards %} | ||
| <tr> | ||
| <td> | ||
| {{ board.name }}<br> | ||
| <small style="color: #888">{{ board.description }}</small> | ||
| <a href="{% url 'board_topics' board.pk %}">{{ board.name }}</a> | ||
| <small class="text-muted d-block">{{ board.description }}</small> | ||
| </td> | ||
| <td>0</td> | ||
| <td>0</td> | ||
| <td class="align-middle">0</td> | ||
| <td class="align-middle">0</td> | ||
| <td></td> | ||
| </tr> | ||
| {% endfor %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| {% load static %} <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>{{ board.name }}</title> | ||
| <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <ol class="breadcrumb my-4"> | ||
| <li class="breadcrumb-item"><a href="{% url 'home' %}">Boards</a></li> | ||
| <li class="breadcrumb-item active">{{ board.name }}</li> | ||
| </ol> | ||
| </div> | ||
| </body> | ||
| </html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{0} is the placeholder for the first variable (hence 0, for variable 0) that goes in the format function. In that case, you only have one variable:
homepage_url.If
homepage_url="https://pipetilla.com" then the result would be:'href="https://pipetilla.com"'
That sintax is also equivalent to:
or
From Python 3.6 onwards, you can use also f-strings:
There is more interesting info here:
https://realpython.com/python-f-strings/