diff --git a/assignments/session01/echo_client.py b/assignments/session01/echo_client.py index 61616c36..7c052020 100644 --- a/assignments/session01/echo_client.py +++ b/assignments/session01/echo_client.py @@ -6,16 +6,16 @@ def client(msg, log_buffer=sys.stderr): server_address = ('localhost', 10000) # TODO: Replace the following line with your code which will instantiate # a TCP socket with IPv4 Addressing, call the socket you make 'sock' - sock = None + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) print >>log_buffer, 'connecting to {0} port {1}'.format(*server_address) # TODO: connect your socket to the server here. - + sock.connect(server_address) # this try/finally block exists purely to allow us to close the socket # when we are finished with it try: print >>log_buffer, 'sending "{0}"'.format(msg) # TODO: send your message to the server here. - + sock.sendall(msg) # TODO: the server should be sending you back your message as a series # of 16-byte chunks. You will want to log them as you receive # each one. You will also need to check to make sure that @@ -24,13 +24,16 @@ def client(msg, log_buffer=sys.stderr): # # Make sure that you log each chunk you receive. Use the print # statement below to do it. (The tests expect this log format) - chunk = '' - print >>log_buffer, 'received "{0}"'.format(chunk) + chunk = sock.recv(16) + if chunk: + print >>log_buffer, 'received "{0}"'.format(chunk) + else: + return finally: # TODO: after you break out of the loop receiving echoed chunks from # the server you will want to close your client socket. print >>log_buffer, 'closing socket' - + sock.close() if __name__ == '__main__': if len(sys.argv) != 2: @@ -39,4 +42,4 @@ def client(msg, log_buffer=sys.stderr): sys.exit(1) msg = sys.argv[1] - client(msg) \ No newline at end of file + client(msg) diff --git a/assignments/session01/echo_server.py b/assignments/session01/echo_server.py index 217380fb..f68bb943 100644 --- a/assignments/session01/echo_server.py +++ b/assignments/session01/echo_server.py @@ -7,16 +7,17 @@ def server(log_buffer=sys.stderr): address = ('127.0.0.1', 10000) # TODO: Replace the following line with your code which will instantiate # a TCP socket with IPv4 Addressing, call the socket you make 'sock' - sock = None + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) # TODO: Set an option to allow the socket address to be reused immediately # see the end of http://docs.python.org/2/library/socket.html - + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # log that we are building a server print >>log_buffer, "making a server on {0}:{1}".format(*address) # TODO: bind your new sock 'sock' to the address above and begin to listen # for incoming connections - + sock.bind(address) + sock.listen(1) try: # the outer loop controls the creation of new connection sockets. The # server will handle each incoming connection one at a time. @@ -28,7 +29,7 @@ def server(log_buffer=sys.stderr): # the client so we can report it below. Replace the # following line with your code. It is only here to prevent # syntax errors - addr = ('bar', 'baz') + conn, addr = sock.accept() try: print >>log_buffer, 'connection - {0}:{1}'.format(*addr) @@ -41,29 +42,35 @@ def server(log_buffer=sys.stderr): # following line with your code. It's only here as # a placeholder to prevent an error in string # formatting - data = '' + data = conn.recv(16) + print >>log_buffer, 'received "{0}"'.format(data) + # TODO: you will need to check here to see if any data was # received. If so, send the data you got back to # the client. If not, exit the inner loop and wait # for a new connection from a client - + if data: + conn.sendall(data) + else: + return finally: # TODO: When the inner loop exits, this 'finally' clause will # be hit. Use that opportunity to close the socket you # created above when a client connected. Replace the # call to `pass` below, which is only there to prevent # syntax problems - pass + conn.close() except KeyboardInterrupt: # TODO: Use the python KeyboardIntterupt exception as a signal to # close the server socket and exit from the server function. # Replace the call to `pass` below, which is only there to # prevent syntax problems - pass + sock.close() + return if __name__ == '__main__': server() - sys.exit(0) \ No newline at end of file + sys.exit(0) diff --git a/assignments/session07/mysite/myblog/admin.py b/assignments/session07/mysite/myblog/admin.py index 67aec2d6..bf2f42d8 100644 --- a/assignments/session07/mysite/myblog/admin.py +++ b/assignments/session07/mysite/myblog/admin.py @@ -2,5 +2,15 @@ from myblog.models import Post from myblog.models import Category -admin.site.register(Post) -admin.site.register(Category) +class CategoryInline(admin.TabularInline): + model = Category.posts.through + +class PostAdmin(admin.ModelAdmin): + inlines = [CategoryInline,] + + +class CategoryAdmin(admin.ModelAdmin): + exclude = ('posts',) + +admin.site.register(Post, PostAdmin) +admin.site.register(Category, CategoryAdmin) diff --git a/assignments/session07/mysite/mysite.db b/assignments/session07/mysite/mysite.db index 63c9e9a5..b1d4ed86 100644 Binary files a/assignments/session07/mysite/mysite.db and b/assignments/session07/mysite/mysite.db differ diff --git a/ebaq0uai.ytv.txt b/ebaq0uai.ytv.txt new file mode 100644 index 00000000..0d24b597 --- /dev/null +++ b/ebaq0uai.ytv.txt @@ -0,0 +1,105 @@ +Merge remote-tracking branch 'uwpce/master' + +Conflicts: + assignments/session05/microblog/microblog.py +# +# It looks like you may be committing a merge. +# If this is not correct, please remove the file +# .git/MERGE_HEAD +# and try again. + + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# On branch master +# All conflicts fixed but you are still merging. +# (use "git commit" to conclude merge) +# +# Changes to be committed: +# +# new file: assignments/session02/completed_http_server.py +# modified: assignments/session02/tasks.txt +# new file: assignments/session04/flask_walkthrough-plain.html +# renamed: resources/session05/sql/createdb.py -> assignments/session04/sql/createdb.py +# renamed: resources/session05/sql/ddl.sql -> assignments/session04/sql/ddl.sql +# renamed: resources/session05/sql/populatedb.py -> assignments/session04/sql/populatedb.py +# renamed: resources/session05/sql/utils.py -> assignments/session04/sql/utils.py +# new file: assignments/session04/sql_persistence_tutorial-plain.rst +# modified: assignments/session04/tasks.txt +# new file: assignments/session04/template_tutorial-plain.html +# modified: assignments/session05/microblog/microblog.py +# deleted: assignments/session05/microblog/microblog/microblog.cfg +# deleted: assignments/session05/microblog/microblog/microblog.db +# deleted: assignments/session05/microblog/microblog/microblog.py +# deleted: assignments/session05/microblog/microblog/microblog_tests.py +# deleted: assignments/session05/microblog/microblog/schema.sql +# deleted: assignments/session05/microblog/microblog/templates/layout.html +# deleted: assignments/session05/microblog/microblog/templates/login.html +# deleted: assignments/session05/microblog/microblog/templates/show_entries.html +# new file: assignments/session06/django_intro-plain.html +# new file: assignments/session06/img/admin_index.png +# new file: assignments/session06/img/django-admin-login.png +# new file: assignments/session06/img/django-start.png +# new file: assignments/session06/tasks.txt +# new file: assignments/session07/mysite/manage.py +# new file: assignments/session07/mysite/myblog/__init__.py +# new file: assignments/session07/mysite/myblog/admin.py +# new file: assignments/session07/mysite/myblog/fixtures/myblog_test_fixture.json +# new file: assignments/session07/mysite/myblog/migrations/0001_initial.py +# new file: assignments/session07/mysite/myblog/migrations/0002_auto__add_category.py +# new file: assignments/session07/mysite/myblog/migrations/__init__.py +# new file: assignments/session07/mysite/myblog/models.py +# renamed: resources/session08/django_blog.css -> assignments/session07/mysite/myblog/static/django_blog.css +# new file: assignments/session07/mysite/myblog/templates/detail.html +# new file: assignments/session07/mysite/myblog/templates/list.html +# new file: assignments/session07/mysite/myblog/tests.py +# new file: assignments/session07/mysite/myblog/urls.py +# new file: assignments/session07/mysite/myblog/views.py +# new file: assignments/session07/mysite/mysite.db +# new file: assignments/session07/mysite/mysite/__init__.py +# new file: assignments/session07/mysite/mysite/settings.py +# new file: assignments/session07/mysite/mysite/templates/base.html +# new file: assignments/session07/mysite/mysite/templates/login.html +# new file: assignments/session07/mysite/mysite/urls.py +# new file: assignments/session07/mysite/mysite/wsgi.py +# new file: assignments/session07/tasks.txt +# modified: buildout.cfg +# modified: docutils.conf +# modified: resources/session04/wsgi/bookapp.py +# renamed: assignments/session05/microblog/microblog/static/style.css -> resources/session05/microblog/static/style.css +# modified: resources/session06/microblog/microblog_tests.py +# new file: resources/session07/django_blog.css +# modified: resources/session08/mysite/myblog/admin.py +# new file: resources/session08/mysite/myblog/migrations/0001_initial.py +# new file: resources/session08/mysite/myblog/migrations/0002_auto__add_category.py +# new file: resources/session08/mysite/myblog/migrations/__init__.py +# modified: resources/session08/mysite/myblog/models.py +# modified: resources/session08/mysite/myblog/static/django_blog.css +# modified: resources/session08/mysite/myblog/templates/detail.html +# modified: resources/session08/mysite/myblog/templates/list.html +# modified: resources/session08/mysite/myblog/tests.py +# modified: resources/session08/mysite/myblog/urls.py +# modified: resources/session08/mysite/myblog/views.py +# modified: resources/session08/mysite/mysite/settings.py +# modified: resources/session08/mysite/mysite/templates/base.html +# modified: resources/session08/mysite/mysite/templates/login.html +# modified: resources/session08/mysite/mysite/urls.py +# modified: resources/session08/mysite/mysite/wsgi.py +# new file: source/additional/flask_walkthrough.rst +# new file: source/additional/git_cleanup.rst +# new file: source/additional/sql_persistence_tutorial.rst +# new file: source/additional/template_tutorial.rst +# modified: source/img/admin_index.png +# new file: source/img/flask_hello.png +# modified: source/main/outline.rst +# modified: source/main/readings.rst +# renamed: source/presentations/session07.rst -> source/presentations/django_intro.rst +# modified: source/presentations/session02.rst +# modified: source/presentations/session03.rst +# modified: source/presentations/session04.rst +# renamed: source/presentations/session06.rst -> source/presentations/session05.rst +# modified: source/presentations/session06.rst +# renamed: source/presentations/session08.rst -> source/presentations/session07.rst +# modified: source/presentations/session08.rst +# +