Labels
.
Search Your Article
Total Pageviews
Monday, March 13, 2017
TurboGears - Environment
Prerequisite
Python 2.6 or higher. Earlier versions of TurboGears were not compliant with Python 3.X. Latest version claims to work well on Python 3.X. However, official documentation of TurboGears is still based on Python 2.7 environment.TurboGears - First Program
TurboGears has a minimal mode that makes it possible to create single
file applications quickly. Simple examples and services can be built
quickly with minimal set of dependencies.
Application class in a TG application is inherited from TGController class. Methods in this class are available for access by @expose decorator from tg module.
Application class in a TG application is inherited from TGController class. Methods in this class are available for access by @expose decorator from tg module.
TurboGears - Dependencies
A TurboGears project contains the following directories −
- Config − Where project setup and configuration relies
- Controllers − All the project controllers, the logic of web application
- i018n − Translation files for the languages supported
- Lib − Utility python functions and classes
TurboGears - Serving Templates
An Event though HTML content can be returned to the browser, for more
advanced output, the use of template engine is always preferred. In a
full stack project ‘quickstarted’ by gearbox, Genshi is enabled as the
default template renderer. In a minimal application, however Genshi (or
any other template engine, such as jinja) needs to be installed and
enabled.
TurboGears - HTTP Methods
Http Protocol is the foundation of data communication in world wide
web. Different methods of data retrieval from specified URL are defined
in this protocol. Following table summarizes different http methods
TurboGears - Genshi Template Language
Genshi is a XML based template language. It is similar to Kid,
which used to be the template engine for earlier versions of
TurboGears. Genshi as well as Kid are inspired by other well-known
template languages like HSLT, TAL and PHP.
TurboGears - Includes
Contents of another XML document (especially HTML document) can be
included by using inclusion tags in the current document. In order to
enable such an inclusion, XInclude namespace must be declared in the
root element of the HTML document.
TurboGears - JSON Rendering
The @expose() decorator by default renders html content. However, this can be set to json content type. TurboGears supports json rendering through tg.jsonify.JSONEncoder (**kwargs) class. To render json data simply pass json as content type to expose decorator.
TurboGears - URL Hierarchy
Sometimes, a web application may require a URL structure that is
having more than one level. TurboGears can traverse object hierarchy to
find appropriate method that can handle your request.
A project ‘quickstarted’ with gearbox has a BaseController class in project’s lib folder. It is available as ‘Hello/hello/lib/base.py’.
A project ‘quickstarted’ with gearbox has a BaseController class in project’s lib folder. It is available as ‘Hello/hello/lib/base.py’.
TurboGears – ToscaWidgets Forms
One of the most essential aspect of any web application is to present
the user interface for a user. HTML provides a <form> tag which
is used to design an interface. Form’s elements such as text input,
radio, select etc. can be appropriately used. Data entered by the user
is submitted in the form of Http request message to server side script
by either GET or POST method.
TurboGears – Validation
A good Forms widget library should have an input validation feature.
For example, the user should be forced to enter data in a mandatory
field, or verify if an email field contains a valid email, without
resorting to any other programmatic means (like JavaScript function) for
validation.
TurboGears – Flash Messages
TurboGears provides a very convenient messaging system for notifying
information to user in a non-obtrusive way. TGFlash class in tg module
provides support for flashing messages that are stored in a plain
cookie. This class supports fetching flash messages on server side as
well as client side through JavaScript.
TurboGears – Cookies & Sessions
It is often required to hold simple browsing data attached to a
user’s browser. Sessions are the most commonly used technique. Session
represents data which need not be stored in a more persistent form like
disk file or database.
TurboGears – Caching
In order to enhance the performance of a web application, especially
if it is involved in lengthy operations, caching techniques are used.
TurboGears provides two types of caching techniques −
Whole-page Caching
Whole-page Caching
TurboGears – SQLAlchemy
Although it is possible to use SQL in TurboGears application to
perform CRUD operations on any relational database, it is advisable to
use SQLAlchemy, a Python toolkit is a powerful Object Relation Mapper
that gives application developers the full power and flexibility of SQL.
TurboGears – Creating Models
Let us add a student model which will set up a student table in our sqlite database.
Hello\hello\model\student.py
Hello\hello\model\student.py
from sqlalchemy import * from sqlalchemy.orm import mapper, relation, relation, backref from sqlalchemy import Table, ForeignKey, Column from sqlalchemy.types import Integer, Unicode, DateTime
TurboGears – CRUD Operations
The following session methods perform CRUD Operations −
- DBSession.add(model object) − inserts a record into mapped table.
- DBSession.delete(model object) − deletes record from the table.
- DBSession.query(model).all() − retrieves all the records from table (corresponding to a SELECT query).
TurboGears – DataGrid
The ToscaWidgets contains a DataGrid control which provides a quick
way to present data in tabular form. The DataGrid object is declared as
follows −
from tw2.forms import DataGrid
TurboGears – Pagination
TurboGears provides a convenient decorator called paginate() to
divide output in the pages. This decorator is combined with the expose()
decorator. The @Paginate() decorator takes the dictionary object of
query result as argument. In addition, the number of records per page
are decided by value of items_per_page attribute. Ensure that you import
paginate function from tg.decorators into your code.
TurboGears – Admin Access
TurboGears provides the tgext.admin extension, which is powered by
tgext.crud and sprox. This Sprox is a package used for the creation of
web widgets directly from the database schema. This can be used to
automatically create simple administration pages and is the toolkit
powering the /admin page in the newly quickstarted applications.
TurboGears – Authorization & Authentication
A TurboGears application is created by quickstart and setup-app
options of the gearbox toolkit, which has the authorization and
authentication support enabled by default. The models declared in
auth.py are set up and initialized as per values assigned in
bootstrap.py.
The following models are declared in auth.py −
The following models are declared in auth.py −
TurboGears - Using MongoDB
TurboGears also supports MongoDB document databases. It uses Ming, an
Object Document Mapper API. Usage of Ming is very much similar to
SQLAlchemy. Ming query language makes it possible to port SQLAlchemy
based TurboGears project to Ming.
TurboGears – Scaffolding
Gearbox toolkit contains scaffold command, which is very useful to
quickly create new components of TurboGears application. An application
generated by quickstart command of gearbox has a skeleton template in
the model folder (model.py.template), a templates folder
(template.html.template) and a controllers folder
(controller.py.template).
TurboGears – Hooks
There are three ways in TurboGears to plug behaviors inside the existing applications.
- Hook − It is a mechanism by which it is possible to define
an event, and notify registered listeners as and when the events are
emitted.
TurboGears - Writing Extensions
TurboGears extensions are identified by tgext.* package. A Gearbox toolkit provides tgext command to create a sample extension. For example −
gearbox tgext -n myextensionOther optional parameters for this command are −
TurboGears - Pluggable Applications
If your extension needs to expose models and controllers, you probably want to have a look at the Pluggable Applications,
which are meant to create reusable Turbogears applications that can be
plugged inside other applications to extend their features.
TurboGears – RESTful Applications
REST stands for REpresentational State Transfer. REST is web
standards based architecture and uses HTTP Protocol for data
communication. It revolves around a resource where every component is a
resource and a resource is accessed by a common interface using HTTP
standard methods. REST was first introduced by Roy Fielding in 2000.
TurboGears - Deployment
To switch over from a development environment to a full-fledged
production environment, application needs to be deployed on a real web
server. Depending upon what you have, there are different options
available to deploy a TurboGears web application.
Turbogears - Quick Guide
TurboGears - Overview
What is Web Framework?
Web Application Framework or simply Web Framework represents a collection of libraries and modules, which enables a web application developer to write applications, without having to bother about low level details such as protocols, thread management, etc.TurboGears - Useful Resources
The following resources contain additional information on TurboGears. Please use them to get more in-depth knowledge on this.
Discuss TurboGears
TurboGears is a Python web application framework, which consists of
many modules. It is designed around the MVC architecture that are
similar to Ruby on Rails or Struts. TurboGears are designed to make
rapid web application development in Python easier and more supportable.
SVG - Overview
What is SVG?
- SVG, Scalable Vector Graphics is an XML based language to define vector based graphics.
- SVG is intended to display images over the web.
- Being vector images, SVG image never loses quality no matter how they are zoomed out or resized.
- SVG images supports interactivity and animation.
SVG - Shapes
SVG provides number of shapes which can be used to draw images. Following are the common shapes.
Sr.No. | Shape Type & Description |
---|---|
1 | rect
Used to draw a rectangle. |
SVG - Text
<text> element is used to draw text.
Declaration
Following is the syntax declaration of <text> element. We've shown main attributes only.<text x="x-cordinates" y="y-cordinates"
SVG - Stroke
SVG supports multiple stroke properties.
Following are the main stroke properties used.
Following are the main stroke properties used.
Sr.No. | Stroke Type & Description |
---|---|
1 | stroke − defines color of text, line or outline of any element. |
2 | stroke-width − defines thickness of text, line or outline of any element. |
3 | stroke-linecap − defines different types of ending of a line or outline of any path. |
4 | stroke-dasharray − used to create dashed lines. |
SVG - Filters
SVG uses <filter> element to define filters. <filter>
element uses an id attribute to uniquely identify it.Filters are defined
within <def> elements and then are referenced by graphics
elements by their ids.
SVG provides a rich set of filters. Following is the list of the commonly used filters.
SVG provides a rich set of filters. Following is the list of the commonly used filters.
SVG - Patterns
SVG uses <pattern> element to define patterns. Patterns are
defined using <pattern> element and are used to fill graphics
elements in tiled fashion.
Declaration
Following is the syntax declaration of <pattern> element. We've shown main attributes only.<pattern
SVG - Gradients
Gradient refers to smooth transition of one color to another color within a shape. SVG provides two types of gradients.
- Linear Gradients − Represents linear transition of one color to another from one direction to another.
- Radial Gradients − Represents circular transition of one color to another from one direction to another.
SVG - Interactivity
SVG images can be made responsive to user actions. SVG supports
pointer events, keyboard events and document events. Consider the
following example.
SVG - Linking
<a> element is used to create hyperlink. "xlink:href"
attribute is used to pass the IRI (Internationalized Resource
Identifiers) which is complementary to URI (Uniform Resource
Identifiers).
SVG - Transformation Effects
Page transformation effects works based on snap.svg-min.js,svgLoader.js,and classie.js.A sample example is as shown below.
Circular Effects
Spill Effects
Frame it Effects
Source code available hereSVG - Full Screen Overlay Effects
Some simple and creative overlay styles and effects. From sliding the
overlay into the viewport to using SVG morphing shapes, we explore some
effects for full screen overlays.
Source code available here
Source code available here
SVG - Laylinepainter.js Effects
Lazy Line Painter.Js
Lazy Line Painter is a jQuery plugin for animating SVG paths to animate the drawing sequence.Source code available here
SVG - Demo game
SVG Demo Game
A Simple game is developed with SVG, java script, CSS and HTMLSource code available here
SVG - Real Time SVG AD
Ubuntu is using SVG for making the ads. Below example is one of the
regular ad which can we see in different websites in ad section
Source code available here
Source code available here
SVG - Questions and Answers
SVG Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews.
This section provides a useful collection of sample Interview Questions
and Multiple Choice Questions (MCQs) and their answers with
appropriate explanations.
SVG - Quick Guide
SVG - Overview
What is SVG?
- SVG, Scalable Vector Graphics is an XML based language to define vector based graphics.
- SVG is intended to display images over the web.
- Being vector images, SVG image never loses quality no matter how they are zoomed out or resized.
- SVG images supports interactivity and animation.
SVG - Useful Resources
The following resources contain additional information on SVG. Please use them to get more in-depth knowledge on this topic.
Discuss SVG
Scalable Vector Graphics commonly known as SVG
is a XML based format to draw vector images. It is used to draw two
dimentional vector images. This tutorial will teach you basics of SVG.
Tutorial contains chapters discussing all the basic components of SVG
with suitable examples.
Sencha Touch - Overview
What is Sencha Touch
Sencha Touch is a popular framework of Sencha which is for creating user interface for mobile application.It helps developer to create an mobile app using simple HTML, CSS, JS which supports many mobile devides such as android, IOS, BlackBerry, Windows.
It is based on MVC architecture. The latest version of Sencha Touch is 2.4.
Sencha Touch - Overview
Try it Option Online
We have set up Sencha Touch Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.
Sencha Touch - Naming Convention
Naming convention is a set of rule to be followed for identifiers.
It makes code more readable and understandable to the other programmers as well.
Naming convention in Sencha Touch follows the standard JavaScript convention which is not mandatory but a good practice to follow.
It makes code more readable and understandable to the other programmers as well.
Naming convention in Sencha Touch follows the standard JavaScript convention which is not mandatory but a good practice to follow.
Sencha Touch - Architecture
The bottom layer for any mobile application is OS on top of that any
or everything is built upon. then we have the browers on which we will
be running the we applications. It could be Chrome , Safari, IE
anything. the upper layer to all that is a W3 standards which are common
for all.
Sencha Touch - MVC
MVC stands for Model View Controller. It is an architectural pattern
which separates application into logical components making it more
manageable.
The below diagram shows how MVC archtecture works:
The below diagram shows how MVC archtecture works:
Sencha Touch - First Program
This chapter list down the steps to write first Hello World program in Ext JS:
index.htm
Step 1
Create index.htm page in an editor of our choice. Include the required library files in head section of html page as mentioned below:index.htm
<!DOCTYPE html>
Subscribe to:
Posts (Atom)