Giter VIP home page Giter VIP logo

tango_with_django_2_code's Introduction

Tango with Django 2 Codebase

This is a model solution for the Tango with Django 2 book. Included are model solutions to all of the exercises included through each chapter. Screenshots that appear in the book were taken from a browser when executing this code.

If you notice something that doesn't work -- or you think there's a better way to solve something -- it would be great to hear from you. Add an issue to this repository, and myself or Leif will get back to you!

Everything is working as of January 10, 2020.

David Maxwell (maxwelld90 at acm dot org)

Note: if you are a student looking for a quick way to complete your Rango assignment, you should be aware that there are a few little things in here which, if you blindly copy and paste, will demonstrate that you did just that. You have been warned. It's always better to spend your time actually learning about what everything does -- rather than blindly copying and pasting someone else's work, and flogging it off as your own. Have fun!

How to Use this Repository

It's easy to use this repository. We've split our implementations of each chapter into a separate branch. If something needs to be changed later, we can simply update a specific branch -- rather than getting stuck and being unable to undo an old commit.

In the master branch, we keep our tests for the end of different chapters, along with this README, and the project's requirements.txt file. You can checkout the appropriate branch for the chapter you're interested in. Let's say you want to see what our sample solution looked like at the end of Chapter 5.

  1. Make a copy of the repository on your device with $ git clone https://github.com/maxwelld90/tango_with_django_2_code.
  2. Change into the directory that you've just created with $ cd tango_with_django_2_code.
  3. Run the checkout command to switch your workspace to the correct branch with $ git checkout remotes/origin/chapter5.

You can view a full list of the available branches by issuing the command git branch -a. Substitute chapter5 in Step 3 above with the name of the branch you want to view. Commits are made as we add each individual new feature -- not at the end of every chapter. This means each branch will have several commits for each chapter, so you can see how we build Rango up!

End of Chapter Tests

We've also implemented some unit tests that can be run at the end of each chapter. We've currently got tests up to the end of Chapter 10. If there is demand for further chapters to be covered, let us know!

Test modules are located in the master branch, progress_tests directory. In order to run these tests, check out the Tango with Django book. Section 2.6 details exactly what you need to do. If you are stuck, reach out to us with a new issue.

tango_with_django_2_code's People

Contributors

asimeonovuog avatar maxwelld90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tango_with_django_2_code's Issues

The overriden clean() method in PageForm class doesn't produce the desired effect

Hello,
I understand that by overriding the clean() method in PageForm class the URL box on the ../add_page/ webpage should also accept URLs that don't begin with 'http://'.
But it appears that the method is called only after the URL box is validated for incorrect format of URL, therefore it's never called until you type the URL correctly formatted in the first place.
I tried cloning your chapter7 branch and it produced the same result as my project.

Is there a mistake or do I understand the purpose of the method in a wrong way?

image

Chapter 3 Tests Fail : syntax error on line 26 : FAILURE HEADER

Completed exercises until end of Chapter 3.
Upon executing the tests for chapter 3 get following error:

File "/home/aspma/python/django/tango_with_django_project/rango/tests_chapter3.py", line 26
FAILURE_HEADER = f"{os.linesep}{os.linesep}{os.linesep}================{os.linesep}TwD TEST FAILURE =({os.linesep}================{os.linesep}"

----------------------------------------------- Console Output --------------------------------------------
SyntaxError: invalid syntax

(rangoenv) aspma@aspma-VirtualBox:~/python/django/tango_with_django_project$ python manage.py test rango.tests_chapter3
Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/core/management/commands/test.py", line 56, in handle
failures = test_runner.run_tests(test_labels)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/test/runner.py", line 603, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/aspma/Envs/rangoenv/lib/python3.5/site-packages/django/test/runner.py", line 485, in build_suite
tests = self.test_loader.loadTestsFromName(label)
File "/usr/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
module = import(module_name)
File "/home/aspma/python/django/tango_with_django_project/rango/tests_chapter3.py", line 26
FAILURE_HEADER = f"{os.linesep}{os.linesep}{os.linesep}================{os.linesep}TwD TEST FAILURE =({os.linesep}================{os.linesep}"
^
SyntaxError: invalid syntax

----------------------------------------------- Console Output --------------------------------------------

Chapter 5 Tests

The tests for Chapter 5 are producing the error message on line 178 of the tests_chapter5.py file. The error message reads:
"We couldn't find the correct output in the Page view within the admin interface for page listings. Did you complete the exercises, adding extra columns to the admin view for this model? Are the columns in the correct order?"

I can see that the pertinent test checks whether expected_str is in response_body. When I print response_body, the string is identical to expected_str except for the start of the string, which begins instead of , but everything else is the same.

I.e. response_body reads:

image

instead of:

image

The code in my admin.py file for the project reads as follows:

"from django.contrib import admin
from rango.models import Category, Page

class PageAdmin (admin.ModelAdmin):
list_display = ('title', 'category', 'url')

Register your models here.

admin.site.register(Category)
admin.site.register(Page,PageAdmin)"

which matches the code suggested in the Excercise Hints part of the book on Page 89. The code also produces the correct Pages view on the /admin/ site:

image

The above is a screenshot of the /admin/ page from my project which exactly matches the screenshot on page 88 of the book.

I am running a later version of Django than suggested in the book (4.1), which perhaps explains this error.

Can you please confirm whether there is something wrong with my implementation or whether the error is produced due to external reasons (e.g. using a later version of Django)? Thanks in advance for your help!

About the 4th Test

Sorry for doing the actions so late. I figured out where is the problem for can't pass the test even the page shows the correct content. The HTML code for showing the picture has to be exactly same as

<img src="{% static 'images/rango.jpg' %}" alt="Picture of Rango" />

No SPACE or LINE BREAK is allowed ๐Ÿ˜ต

I personally think that maybe a little bit too harsh for people who need to pass the test to get the grade like university students. I wish it can be changed to a more friendly test : ) ๐Ÿ˜„

Tests at the end of chapter 4 require hard coded path to media

The required str in test_about_contains_rango:

required_str = f"<img src=\"{settings.MEDIA_URL}cat.jpg\" alt=\"Picture of a Cat\" />"

fails if about.html contains context variable like:

<img src="{{ MEDIA_URL }}cat.jpg" alt="Picture of a Cat.">

only was to pass the test seems to be to hard code the path to media:
<img src="/media/cat.jpg" alt="Picture of a Cat" />

Not sure if this is intended or if the context variable for media should also pass the test.

Unit test for chapter 3 require specific project name

One of the unit tests from chapter 3 requires the directory name to be exactly "tango_with_django_project". This is a bit inconsistent with the instructions from the book (page 27).

This command will invoke the django-admin.py script, which will set up a new Django project called tango_with_django_project for you. Naming conventions dictate that we would typically append _project to the end of our Django project directories so we know exactly what they contain โ€“ but naming this is really entirely up to you.

Unit test case:

 def test_project_created(self):
        """
        Tests whether the tango_with_django_project configuration directory is present and correct.
        """
        directory_exists = os.path.isdir(os.path.join(self.project_base_dir, 'tango_with_django_project'))
        urls_module_exists = os.path.isfile(os.path.join(self.project_base_dir, 'tango_with_django_project', 'urls.py'))
        
        self.assertTrue(directory_exists, f"{FAILURE_HEADER}Your tango_with_django_project configuration directory doesn't seem to exist. Did you use the correct name?{FAILURE_FOOTER}")
        self.assertTrue(urls_module_exists, f"{FAILURE_HEADER}Your project's urls.py module does not exist. Did you use the startproject command?{FAILURE_FOOTER}")

My suggestion is to remove the directory assertion and leave only the "urls_module_exists" -- adapting it to ignore the project name.

Test Fail for Chapter 8.

Hello,

I have finished Chapter 8 and when doing the tests, I get 1 failure - I've been looking over the code for a couple days and can't seem to work out what I have to change. If you could help that would be great - think i'm just not understanding the error. I have included my github link if you need to look at that.

https://github.com/emilymurphy2110/TangoProject

Screenshot 2020-02-14 at 10 22 13

URL inconsistency in tests_chapter6

In Creating a Population Script in chapter 5 of the book, the sample code gives the URL for Django Rocks as http://www.djangorocks.com/, with a trailing forward slash.
2020-01-19 19_49_55-tangowithdjango2 pdf -  Tango With Django 2  - SumatraPDF

In the test_index_pages method on line 108 of tests_chapter6.py, the index view responses are checked using regex, including a check for Django Rocks as http://www.djangorocks.com, without the trailing forward slash.
2020-01-19 19_44_17-tests_chapter6 py - Visual Studio Code
This of course results in the test failing.

Chapter 11 - python_2_unicode_compatible

Hi -

A definite newbie to Django (and even Python) and I'm getting the below error when attempting Chapter 11:

"File "/Users/kent/.virtualenvs/rangoprojenv/lib/python3.8/site-packages/registration/models.py", line 21, in
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/Users/kent/.virtualenvs/rangoprojenv/lib/python3.8/site-packages/django/utils/encoding.py)"

I've googled the above and the solutions I find discuss altering external libraries which I'm definitely not comfortable with doing at the moment (especially as one of the lines could not even be found - otherwise might have attempted it).

Is it something I missed in the book, a bug on my part, or any chance a compatibility error as most posts I've seen have hinted at? Not much coding in Chapter 11 and can't see where I might have gone wrong (though I've coded enough to know it could definitely be me!).

New to Github too but will post code if the need arises.

Thanks,

Kent

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.