Book Image

Python 3 Web Development Beginner's Guide

By : Michel Anders
Book Image

Python 3 Web Development Beginner's Guide

By: Michel Anders

Overview of this book

<p>Building your own Python web applications provides you with the opportunity to have great functionality, with no restrictions. However, creating web applications with Python is not straightforward. Coupled with learning a new skill of developing web applications, you would normally have to learn how to work with a framework as well.</p> <p><em>Python 3 Web Development Beginner's Guide</em> shows you how to independently build your own web application that is easy to use, performs smoothly, and is themed to your taste – all without having to learn another web framework.</p> <p>Web development can take time and is often fiddly to get right. This book will show you how to design and implement a complex program from start to finish. Each chapter looks at a different type of web application, meaning that you will learn about a wide variety of features and how to add them to your custom web application. You will also learn to implement jQuery into your web application to give it extra functionality. By using the right combination of a wide range of tools, you can have a fully functional, complex web application up and running in no time.</p>
Table of Contents (19 chapters)
Python 3 Web Development Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – defining new entities: how it should look


Type in and run the following code (also available as testentity.py). It will use the refactored entity module to define a MyEntity class and work with some instances of this class. We will create, list, and update instances and even see an update fail because we try to assign a value that will not pass a validation for an attribute:

Chapter7/testentity.py

from entity import *

class Entity(AbstractEntity):
	database="/tmp/abc.db"
	
class MyEntity(Entity):
	a=Attribute(unique=True, notnull=True, affinity='float',
		displayname='Attribute A', validate=lambda x:x<5)

a=MyEntity(a=3.14)
print(MyEntity.list())

e=MyEntity.list(pattern=[('a',3.14)])[0]
print(e)

e.delete()

a=MyEntity(a=2.71)
print([str(e) for e in MyEntity.list()])

a.a=1
a.update()
print([str(e) for e in MyEntity.list()])

a.a=9

The output produced by the print functions should look similar to the lines listed next, including the raised exception caused by an invalid...