Wednesday, July 8, 2015

Mongodb proedures




Procedure1

  1. var myCursor = db.card.find();
  2. while (myCursor.hasNext()) {
  3.    var doc = myCursor.next();
  4.        print("deckId id:"+doc.deckId);
  5. print(doc.uiTemplate.widget[0].formFieldName);
  6.     print(doc.uiTemplate.widget[0].fieldDesc);
  7.     print(tojson(doc._id));
  8.     print('========================');
  9. }


Procedure2


  1. var myCursor = db.deck.find({"serviceId":"559b975234772ab9ada732f5"});

  2. while (myCursor.hasNext()) {
  3.    var doc = myCursor.next();
  4.    print("dataId id:"+doc.childrenPartialInfo[0].dataId);
  5.    
  6.    var childrens = doc.childrenPartialInfo;
  7.    for(var i = 0; i < childrens.length; i++) {
  8.        var cardId = childrens[i].dataId;
  9.        print(cardId);
  10.        var cardCursor = db.card.find({"_id":ObjectId(cardId)});
  11.        var cardDoc = cardCursor.next();
  12.        
  13.        print(cardId +" --- "+cardDoc.uiTemplate.widget[0].formFieldName);
  14.        print(cardId +" --- "+cardDoc.uiTemplate.widget[0].formFieldName+","+cardDoc.uiTemplate.widget[0].fieldLabel+","+cardDoc.uiTemplate.widget[0].fieldDesc+","+cardDoc.uiTemplate.widget[0].hint);
  15.    }
  16.     
  17.    print(tojson(doc._id));
  18.    print('========================');
  19. }

Saturday, July 4, 2015

Python Core syllabus


This is the python core syllabus

Introduction                                                   
History                                                                                        
Features                                                                                        
Setting up path                                                                            
Working with Python 
Basic Syntax 
Variable and Data Types 
Operator
Looping                                                           
For  Break
While 
Nested loops
Control Statements
Break 
Continue 
Pass
String Manipulation
Accessing Strings 
Basic Operations 
String slices 
Function and Methods
Lists
Introduction 
Accessing list 
Operations 
Working with lists 
Function and Methods
Tuple
Introduction 
Accessing tuples 
Operations 
Working 
Functions and Methods

Dictionaries
Introduction 
Accessing values in dictionaries 
Working with dictionaries 
Properties 
Functions
Functions
Defining a function 
Calling a function 
Types of functions 
Function Arguments 
Anonymous functions 
Global and local variables
Modules
Importing module 
Math module 
Random module 
Packages 
Composition
Input-Output
Printing on screen 
Reading data from keyboard 
Opening and closing file 
Reading and writing files 
Functions
Exception Handling
Exception 
Exception Handling 
Except clause 
Try ? finally clause 
User Defined Exceptions

Advanced Python




Friday, July 3, 2015

Satyanarayana : Unknown Lifecycle Phase Error in Maven Build

Satyanarayana : Unknown Lifecycle Phase Error in Maven Build: Problem [ERROR] Unknown lifecycle phase  "test1" . You must specify a valid lifecycle phase or a goal in the format &l...

Python Dictionary data type example


  1. #creating dictionary

  2. dict = {'Name' : 'hooper','Sal' : 122,'id':222,'Address':'hyd'};
  3. print dict

  4. #accessing dict elements
  5. print "first element is dict['Name']:", dict['Name'];

  6. #updating dict elements
  7. print "ofter updation dice elements are"

  8. dict['Name']='satya';
  9. dict['comany']='heeperlabs';
  10. print dict

  11. # iteration dictionary elements

  12. for items in dict.items():
  13.  print items

  14. # deleting single element from dictionary
  15. del dict['Sal'];
  16. print dict

  17. # deleting all element from dictionary

  18. dict.clear();
  19. print dict

  20. # deleting entire dictionary

  21. del dict
  22. print dict

Thursday, July 2, 2015

designing page with iframes with html and css



  1. html code


  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <link rel="stylesheet" type="text/css" href="Style.css">
  6. <style>
  7. a:link {
  8.     text-decoration: none;
  9. }

  10. a:visited {
  11.     text-decoration: none;
  12. }

  13. a:hover {
  14.     text-decoration: underline;
  15. }

  16. a:active {
  17.     text-decoration: underline;
  18. }

  19. #nav {
  20.     line-height:30px;
  21.     background-color:#eeeeee;
  22.     height:500px;
  23.     width:100px;
  24.     float:left;
  25.     padding:5px;
  26.  
  27.     text-align:center;
  28.     padding:15px;
  29.     border:1px solid  black ;
  30.     width:100px;
  31.     border-top:0px;
  32.     border-left:0px;
  33.     border-right:thick 1px balck;    
  34. }


  35. </style>
  36. </head>
  37. <body>
  38. <iframe name="iframe_a" align="center" style="border:none" SCROLLING="yes" ></iframe>

  39. <div class="menu-wrap">
  40.     <nav class="menu">
  41.    
  42.         <ul class="clearfix">
  43.             <li>
  44.            
  45.                 <a href="./About*">About <span class="arrow">&#9660;</span></a>

  46.                 <ul class="sub-menu">
  47.                     <li><a href="./About*" target="iframe_a">introduction</a></li>
  48.                     <li><a href="./About*" target="iframe_a">Informatio</a></li>
  49.                     <li><a href="./About*" target="iframe_a">AboutUs</a></li>
  50.                 </ul>
  51.             </li>
  52.              <li>
  53.                 <a href="./Services*" target="iframe_a">Services <span class="arrow">&#9660;</span></a>
  54.                 <ul class="sub-menu">
  55.                     <li><a href="./Services*" target="iframe_a">Business</a></li>
  56.                     <li><a href="./Services*" target="iframe_a">Hooper App</a></li>
  57.                     <li><a href="./Services*" target="iframe_a">Chat App</a></li>
  58.                    
  59.                 </ul>
  60.             </li>
  61.             <li>
  62.                 <a href="./Clients*" target="iframe_a">Clients <span class="arrow">&#9660;</span></a>

  63.                 <ul class="sub-menu">
  64.                     <li><a href="./Clients*" target="iframe_a">Google</a></li>
  65.                     <li><a href="./Clients*" target="iframe_a">Facebook</a></li>
  66.                     <li><a href="./Clients*" target="iframe_a">Tcs</a></li>
  67.                 </ul>
  68.             </li>
  69.             <li>
  70.                 <a href="./ContactUs*" target="iframe_a">ContactUs <span class="arrow">&#9660;</span></a>

  71.                 <ul class="sub-menu">
  72.                     <li><a href="./ContactUs*" target="iframe_a">MainBranch</a></li>
  73.                     <li><a href="./ContactUs*" target="iframe_a">SubBranch</a></li>
  74.                 </ul>
  75.             </li>
  76.         </ul>
  77.     </nav>
  78. </div>
  79. <div id="nav">

  80. <a href="./Login.jsp" target="iframe_a">Login</a><br>

  81. <a href="./registation.html" target="iframe_a" >Sign up</a>
  82. <br>
  83. </div>
  84. </body>
  85. </html>

  86. css code


  87. iframe {
  88. height: 350px;
  89. width: 500px;
  90. position:absolute;
  91. top: 60%;
  92. margin-top: -175px;
  93. left: 20%;
  94. margin-left: 80px;
  95. FRAMEBORDER="0";
  96. SCROLLING="no";
  97. }

  98. .clearfix:after {
  99.     display:blue;
  100.     clear:both;
  101. }
  102. /*----- Menu Outline -----*/
  103. .menu-wrap {
  104.     width:80%;
  105.     box-shadow:0px 1px 3px rgba(0,0,0,0.2);
  106.     background:blue;
  107. }
  108.  
  109. .menu {
  110.    
  111.     margin:0px auto;
  112.     background-color:#eeeeee;
  113.     color:black;
  114.     text-align:right;
  115.     padding:25px;
  116.     border:1px solid  black ;
  117.     width:1150px;
  118.     border-top:0px;
  119.     border-left:0px;
  120.     border-right:0px;
  121. }
  122.  
  123. .menu li {
  124.     margin:0px;
  125.     list-style:none;
  126.     font-family:'Ek Mukta';
  127. }
  128.  
  129. .menu a {
  130.     transition:all linear 0.15s;
  131.     color:blue;
  132. }
  133.  
  134. .menu li:hover > a, .menu .current-item > a {
  135.     text-decoration:none;
  136.     color:blue;
  137. }
  138.  
  139. .menu .arrow {
  140.     font-size:11px;
  141.     line-height:0%;
  142. }
  143.  
  144. /*----- Top Level -----*/
  145. .menu > ul > li {
  146.     float:left;
  147.     display:inline-blue;
  148.     position:relative;
  149.     font-size:19px;
  150. }
  151.  
  152. .menu > ul > li > a {
  153.     padding:10px 35px;
  154.     display:inline-blue;
  155.     text-shadow:0px 1px 0px rgba(0,0,0,0.4);
  156. }
  157.  
  158. .menu > ul > li:hover > a, .menu > ul > .current-item > a {
  159.     background:#eeeeee;
  160. }
  161.  
  162. /*----- Bottom Level -----*/
  163. .menu li:hover .sub-menu {
  164.     z-index:1;
  165.     opacity:1;
  166. }
  167.  
  168. .sub-menu {
  169.     width:100%;
  170.     padding:5px 0px;
  171.     position:absolute;
  172.     top:100%;
  173.     left:0px;
  174.     z-index:-1;
  175.     opacity:0;
  176.     transition:opacity linear 0.15s;
  177.     box-shadow:0px 2px 3px rgba(0,0,0,0.2);
  178.     background:#eeeeee;
  179. }
  180.  
  181. .sub-menu li {
  182.     display:block;
  183.     font-size:16px;
  184. }
  185.  
  186. .sub-menu li a {
  187.     padding:10px 30px;
  188.     display:block;
  189. }
  190.  
  191. .sub-menu li a:hover, .sub-menu .current-item a {
  192.     background:#eeeeee;
  193. }

Wednesday, July 1, 2015

User registration form with CAPTCHA using django-simple-captcha using python

sample web registration in python




  1. import web

  2. # Init our application, this is just about the most basic setup
  3. render = web.template.render('/var/www/templates/')
  4. urls = ('/', 'Index')
  5. app = web.application(urls, globals())

  6. class Index:
  7.     # Create a basic form shared by the class methods
  8.     def __init__(self):
  9.        self.registerForm = web.form.Form(
  10.             # We're adding some fields and a submit button
  11.             # Each field has a validator, which verifies its correctness
  12.             # In this case we check if the field is not null
  13.             # Other attributes are available: description, id, HTML class name, etc
  14.             # See http://webpy.org/form for reference
  15.             web.form.Textbox('username', web.form.notnull, description='User name'),
  16.             web.form.Password('password', web.form.notnull, description='Password'),
  17.             web.form.Password('repeat_password', web.form.notnull,
  18.                               description='Repeat password'),
  19.             web.form.Button('Register'),

  20.             # Whole forms can have validators, too
  21.             # Here, we check if password fields have the same content
  22.             validators = [web.form.Validator("Passwords didn't match.", lambda i:
  23.                                              i.password == i.repeat_password)]
  24.         )

  25.     # GET method is used when there is no form data sent to the server
  26.     def GET(self):
  27.         form = self.registerForm()
  28.         return render.form(content=form)

  29.     # POST method carries form data
  30.     def POST(self):
  31.         # Notice how flawlessly web.py form works, receiving all the data for us
  32.         form = self.registerForm()

  33.         if(not form.validates()):
  34.             return render.form(content=form)
  35.         else:
  36.             return "Form successfuly sent! Username: %s, password: %s" % \
  37.                 (form.d.username, form.d.password)

  38. application = app.wsgifunc()

  39. if __name__=="__main__":
  40.     app.run()




  41. user.py


  42. # Django settings for app project.

  43. # Import the os.path module for doing manipulation with file paths.
  44. import os.path

  45. DEBUG = True
  46. TEMPLATE_DEBUG = DEBUG

  47. ADMINS = (
  48.     # ('Your Name', 'your_email@example.com'),
  49. )

  50. MANAGERS = ADMINS

  51. DATABASES = {
  52.     'default': {
  53.         'ENGINE': 'django.db.backends.sqlite3', # # Using sqlite3
  54.         'NAME': '/var/www/mydb', # Absolute path to the database file
  55.         # The following settings are not used with sqlite3:
  56.         'USER': '',
  57.         'PASSWORD': '',
  58.         'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
  59.         'PORT': '',                      # Set to empty string for default.
  60.     }
  61. }

  62. # Hosts/domain names that are valid for this site; required if DEBUG is False
  63. # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
  64. ALLOWED_HOSTS = []

  65. # Local time zone for this installation. Choices can be found here:
  66. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  67. # although not all choices may be available on all operating systems.
  68. # In a Windows environment this must be set to your system time zone.
  69. TIME_ZONE = 'America/Los_Angeles'

  70. # Language code for this installation. All choices can be found here:
  71. # http://www.i18nguy.com/unicode/language-identifiers.html
  72. LANGUAGE_CODE = 'en-us'

  73. SITE_ID = 1

  74. # If you set this to False, Django will make some optimizations so as not
  75. # to load the internationalization machinery.
  76. USE_I18N = True

  77. # If you set this to False, Django will not format dates, numbers and
  78. # calendars according to the current locale.
  79. USE_L10N = True

  80. # If you set this to False, Django will not use timezone-aware datetimes.
  81. USE_TZ = True

  82. # Absolute filesystem path to the directory that will hold user-uploaded files.
  83. # Example: "/var/www/example.com/media/"
  84. MEDIA_ROOT = ''

  85. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  86. # trailing slash.
  87. # Examples: "http://example.com/media/", "http://media.example.com/"
  88. MEDIA_URL = ''

  89. # Absolute path to the directory static files should be collected to.
  90. # Don't put anything in this directory yourself; store your static files
  91. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  92. # Example: "/var/www/example.com/static/"
  93. STATIC_ROOT = '/var/www/app/static/'

  94. # URL prefix for static files.
  95. # Example: "http://example.com/static/", "http://static.example.com/"
  96. STATIC_URL = '/static/'

  97. # Additional locations of static files
  98. STATICFILES_DIRS = (
  99.     # Put strings here, like "/home/html/static" or "C:/www/django/static".
  100.     # Always use forward slashes, even on Windows.
  101.     # Don't forget to use absolute paths, not relative paths.
  102. )

  103. # List of finder classes that know how to find static files in
  104. # various locations.
  105. STATICFILES_FINDERS = (
  106.     'django.contrib.staticfiles.finders.FileSystemFinder',
  107.     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  108. #    'django.contrib.staticfiles.finders.DefaultStorageFinder',
  109. )

  110. # Make this unique, and don't share it with anybody.
  111. SECRET_KEY = 'vw7__ve*_3j^edw+@9k9(24_efqjnul-k=84yis*ew$xstr&*!'

  112. # List of callables that know how to import templates from various sources.
  113. TEMPLATE_LOADERS = (
  114.     'django.template.loaders.filesystem.Loader',
  115.     'django.template.loaders.app_directories.Loader',
  116. #     'django.template.loaders.eggs.Loader',
  117. )

  118. MIDDLEWARE_CLASSES = (
  119.     'django.middleware.common.CommonMiddleware',
  120.     'django.contrib.sessions.middleware.SessionMiddleware',
  121.     'django.middleware.csrf.CsrfViewMiddleware',
  122.     'django.contrib.auth.middleware.AuthenticationMiddleware',
  123.     'django.contrib.messages.middleware.MessageMiddleware',
  124.     # Uncomment the next line for simple clickjacking protection:
  125.     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  126. )

  127. ROOT_URLCONF = 'app.urls'

  128. # Python dotted path to the WSGI application used by Django's runserver.
  129. WSGI_APPLICATION = 'app.wsgi.application'

  130. TEMPLATE_DIRS = (
  131.     # Include the "templates" directory in the current directory.
  132.     os.path.join(os.path.dirname(__file__), "templates"),
  133.     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
  134.     # Always use forward slashes, even on Windows.
  135.     # Don't forget to use absolute paths, not relative paths.
  136. )

  137. INSTALLED_APPS = (
  138.     'django.contrib.auth',
  139.     'django.contrib.contenttypes',
  140.     'django.contrib.sessions',
  141.     'django.contrib.sites',
  142.     'django.contrib.messages',
  143.     'django.contrib.staticfiles',
  144.     'captcha', # Include the django-simple-captcha application
  145.     'registration', # Include the registration
  146.     # Uncomment the next line to enable the admin:
  147.     # 'django.contrib.admin',
  148.     # Uncomment the next line to enable admin documentation:
  149.     # 'django.contrib.admindocs',
  150. )

  151. # A sample logging configuration. The only tangible logging
  152. # performed by this configuration is to send an email to
  153. # the site admins on every HTTP 500 error when DEBUG=False.
  154. # See http://docs.djangoproject.com/en/dev/topics/logging for
  155. # more details on how to customize your logging configuration.
  156. LOGGING = {
  157.     'version': 1,
  158.     'disable_existing_loggers': False,
  159.     'filters': {
  160.         'require_debug_false': {
  161.             '()': 'django.utils.log.RequireDebugFalse'
  162.         }
  163.     },
  164.     'handlers': {
  165.         'mail_admins': {
  166.             'level': 'ERROR',
  167.             'filters': ['require_debug_false'],
  168.             'class': 'django.utils.log.AdminEmailHandler'
  169.         }
  170.     },
  171.     'loggers': {
  172.         'django.request': {
  173.             'handlers': ['mail_admins'],
  174.             'level': 'ERROR',
  175.             'propagate': True,
  176.         },
  177.     }

  178. }

Pythan hello rest full service in pycharm IDE



echo_service:

import tornado.ioloop
import pyrestful.rest

from pyrestful import mediatypes
from pyrestful.rest import get
class EchoService(pyrestful.rest.RestHandler):
      @get(_path="/echo/{name}", _produces=mediatypes.APPLICATION_JSON)
      def sayHello(self, name):
           return {"Hello":name}

if __name__ == "__main__":

           print "Start the echo service"           app = pyrestful.rest.RestService([EchoService])
           app.listen(8080)
           tornado.ioloop.IOLoop.instance().start()
           print "\nStop the echo service"




new_service


__author__ = 'LENOVO'from datetime import date
import tornado.escape
import tornado.ioloop
import tornado.web

class VersionHandler(tornado.web.RequestHandler):
    def get(self):
        response = { 'version': '3.5.1',
                     'last_build':  date.today().isoformat() }
        self.write(response)

class GetGameByIdHandler(tornado.web.RequestHandler):
    def get(self, id):
        response = { 'id': int(id),
                     'name': 'satya',
                     'release_date': date.today().isoformat() }
        self.write(response)

application = tornado.web.Application([
    (r"/getgamebyid/([0-9]+)", GetGameByIdHandler),
    (r"/version", VersionHandler)
])

class GetNamebySal(tornado.web.RequestHandler):
    def get(self, sal):
        response = { 'id': int(sal),
                     'name': 'satya',
                     'release_date': date.today().isoformat() }
        self.write(response)

application = tornado.web.Application([
    (r"/getnamebysal/([0-9]+)", GetNamebySal),
    (r"/version", VersionHandler)
])

if __name__ == "__main__":
    print "starting service"    application.listen(8080)
    tornado.ioloop.IOLoop.instance().start()