Now I also know how to pass values to and return values from the
google app engine datastore:


here's my code::::   - default.html, scene.js , scene.xaml, and
silverlight.js (downloadable from the web) are placed in the subfolder
silverlight.  the rest go in the root of the app.


app.yaml:

application: nameofapplicationhere
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /silverlight
  static_dir: silverlight


- url: /.*
  script: helloworld.py



helloworld.py:

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
#from django.conf.urls.defaults import *

import os
from google.appengine.ext.webapp import template

class Greeting(db.Model):
  author = db.UserProperty()
  content = db.StringProperty(multiline=True)
  date = db.DateTimeProperty(auto_now_add=True)
  entryid = db.IntegerProperty()


class MainPage(webapp.RequestHandler):
  def get(self):
    greetings_query = Greeting.all().order('-date')
    greetings = greetings_query.fetch(10)

    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'

    template_values = {
      'greetings': greetings,
      'url': url,
      'url_linktext': url_linktext,
      }

    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))


class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.entryid = eval( self.request.get('entryid') )
    greeting.put()

    self.redirect('/')


class funcGetDataTest(webapp.RequestHandler):
  def get(self):

    greetings_query = Greeting.all().order('-date')
    greetings = greetings_query.fetch(10)

    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'

    template_values = {
      'greetings': greetings,
      'url': url,
      'url_linktext': url_linktext,
      }

    path = os.path.join(os.path.dirname(__file__), 'getDataTest.html')
    self.response.out.write(template.render(path, template_values))


class paramtest(webapp.RequestHandler):
  def get(self  ):

    greetings_query = db.GqlQuery("select * from Greeting  where
entryid=:1  order by date desc",
                        eval(self.request.get('entryid')) )
    greetings = greetings_query.fetch( 1 )

    greetingsmore_query = db.GqlQuery("select * from GreetingMore
where entryid=:1  order by date desc",
                        eval(self.request.get('entryid')) )
    greetingsmore = greetingsmore_query.fetch( 1 )

    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'

    template_values = {
      'greetings': greetings,
      'url': url,
      'url_linktext': url_linktext,
      }

    path = os.path.join(os.path.dirname(__file__), 'getDataTest.html')
    self.response.out.write(template.render(path, template_values))




###########################################################

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/sign', Guestbook),
                                      (r'/paramtest', paramtest),
                                      ('/getdatatest',
funcGetDataTest)
                                      ],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()



getdatatest.html:


<rwrecord>
    {% for greeting in greetings %}
      {% if greeting.author %}
                <fname>{{greeting.author.nickname}}</fname>
                <lname>{{greeting.author.nickname}}</lname>
      {% else %}
                <fname>anonymous</fname>
                <lname>anonymous</lname>
      {% endif %}
                <id>{{ greeting.content|escape }}</id>
                <entryid>{{ greeting.entryid }}</entryid>
    {% endfor %}
</rwrecord>



scene.js:

var xmlhttp;
var senderobject;  //senderobject.findname("objectName");



function setSenderObject(sender, eventargs) {
    senderobject = sender;
}


function loadXMLDoc(url) {
    var ms = new Date().getTime().toString();
    var seed = "&timestamp=" + ms;  //its caching junk - using this to
make the url passed to the app engine always unique
    url = url + seed;

    //alert(url);
    xmlhttp = null;
    if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp != null) {
        xmlhttp.onreadystatechange = state_Change;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }
}

function loadXMLDoc3(sender, eventargs) {
    setSenderObject(sender, eventargs);
    loadXMLDoc('../paramtest?entryid=4');   //paramtest.asp?recordid=1
}

function loadXMLDoc2(sender, eventargs) {
    setSenderObject(sender, eventargs);
    loadXMLDoc('../paramtest?entryid=5');      //dbrwtest.asp');
}

function loadXMLDoc1(sender, eventargs) {
    setSenderObject(sender, eventargs);
    loadXMLDoc('../getdatatest?noval=0');  //  http://localhost:8080/
}



scene.xaml:



  <Canvas  xmlns="http://schemas.microsoft.com/client/2007";
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml";>


    <!--  <Canvas.Resources>
      <Storyboard x:Name="mouseEnter">
        <ColorAnimation Duration="00:00:00.25" To="#3DFFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
      </Storyboard>
      <Storyboard x:Name="mouseDown">
        <ColorAnimation Duration="00:00:00.2" To="#22000000"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
      </Storyboard>
      <Storyboard x:Name="mouseUp">
        <ColorAnimation Duration="00:00:00.2" To="#3DFFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
      </Storyboard>
      <Storyboard x:Name="mouseLeave">
        <ColorAnimation Duration="00:00:00.25" To="#00FFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
      </Storyboard>
    </Canvas.Resources>-->


    <Canvas Width="120" Height="44">
      <Rectangle StrokeThickness="4" RadiusX="17" RadiusY="36"
Width="120" Height="44" Stroke="#46000000">
        <Rectangle.Fill>
          <LinearGradientBrush EndPoint="0.5,-0.409"
StartPoint="0.5,1.409">
            <GradientStop Color="gray" Offset="0.242"/>
            <GradientStop Color="black" Offset="0.333"/>
          </LinearGradientBrush>
        </Rectangle.Fill>
      </Rectangle>
      <TextBlock Width="67" Height="23.2" Canvas.Left="29"
Canvas.Top="10" Foreground="#FFEFEFEF" Text="Click Me"
MouseLeftButtonDown="testxmlcodegen" />
      <Rectangle StrokeThickness="4" RadiusX="16" RadiusY="36"
Width="104" Height="32" Canvas.Left="8" Canvas.Top="1.3">
        <Rectangle.Fill>
          <LinearGradientBrush EndPoint="0.5,-0.409"
StartPoint="0.5,1.409">
            <GradientStop Color="#00FFFFFF" Offset="0.13"/>
            <GradientStop Color="#FFFFFFFF" Offset="1"/>
          </LinearGradientBrush>
        </Rectangle.Fill>
      </Rectangle>
      <Rectangle MouseLeftButtonDown="testxmlcodegen" RadiusX="17"
RadiusY="36" Width="114" Height="38" Fill="#00FFFFFF"
x:Name="highlightEllipse" Canvas.Left="3" Canvas.Top="3"/>




      <TextBlock FontSize="50" Canvas.Left="200" x:Name="tbheader"
Width="240"
                 FontFamily="Times New Roman" Visibility="Collapsed">
        <Run Text="Using the HttpRequest Object"/>
      </TextBlock>


<Canvas x:Name="rlboard" Canvas.Left='100' Canvas.Top='250'/>


      <TextBlock FontSize="50" Canvas.Left="527.347"  Canvas.Top="240"
x:Name="tbbutton1"
        Foreground="Brown" MouseLeftButtonDown="loadXMLDoc1"
        Cursor="Hand" FontFamily="Times New Roman">
        <!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
        <Run Text="1 Read Test"/>
      </TextBlock>

      <TextBlock FontSize="50" Canvas.Left="427.347"  Canvas.Top="200"
x:Name="tbbutton2"
        Foreground="Brown" MouseLeftButtonDown="loadXMLDoc2"
        Cursor="Hand" FontFamily="Times New Roman">
        <!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
        <Run Text="2 rw test"/>
      </TextBlock>

      <TextBlock FontSize="50" Canvas.Left="327.347"  Canvas.Top="160"
x:Name="tbbutton3"
        Foreground="Brown"  MouseLeftButtonDown="loadXMLDoc3"
        Cursor="Hand" FontFamily="Times New Roman">
        <!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
        <Run Text="3 param test"/>
      </TextBlock>


      <TextBlock FontSize="50" Canvas.Left="127.347"  Canvas.Top="270"
x:Name="tbstatus"
        Foreground="Black" FontFamily="Times New Roman">
        <Run Text=""/>
      </TextBlock>

      <TextBlock FontSize="50" Canvas.Left="227.347"  Canvas.Top="270"
x:Name="tbstatustext"
        Foreground="Black" FontFamily="Times New Roman">
        <Run Text=""/>
      </TextBlock>

      <TextBlock FontSize="50" Canvas.Left="327.347"  Canvas.Top="270"
x:Name="tbresponse"
        Foreground="Black" FontFamily="Times New Roman">
        <Run Text=""/>
      </TextBlock>


      <!--<p>
        <b>Status:</b>
        <span id="A1"></span>
      </p>

      <p>
        <b>Status text:</b>
        <span id="A2"></span>
      </p>

      <p>
        <b>Response:</b>
        <br />
        <span id="A3"></span>
      </p>-->


      <!--<Ellipse
       Height="200" Width="200"
       Stroke="Black" StrokeThickness="10" Fill="SlateBlue" />-->

    </Canvas>
  </Canvas>


default.html:

<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
        <title>ScriptWeb1</title>
        <script type="text/javascript" src="silverlight.js"></script>
        <script type="text/javascript" src="scene.js"></script>
<!---        <script type="text/javascript" src="gears_init.js"></
script> -->
    <style type="text/css">
                #errorLocation {
                        font-size: small;
                        color: Gray;
                }
                #silverlightControlHost {
                        height: 480px;
                        width: 640px;
                }

        </style>
</head>

<body>
    <!--  Runtime errors from Silverlight will be displayed here.
        This will contain debugging information and should be removed or
hidden when debugging is completed -->
        <div id='errorLocation'></div>

        <div id="silverlightPlugInHost">
                <script type="text/javascript">
//                  var request = 
google.gears.factory.create('beta.httprequest');
//                  request.open('GET', 'http://matrixneo42.brinkster.net/
testx.htm');
//                  //'http://spreadsheets.google.com/feeds/list/
o09771196949220461566.8140527497938195002/default/public/
basic');  //'http://blogs.msdn.com/sburke/atom.xml');  //'/
index.html');
//                  request.onreadystatechange = function() {
//                      if (request.readyState == 4) {
//                          console.write(request.responseText);
//                      }
//                  };
//                  request.send();


                    if (!window.Silverlight)
                    window.Silverlight = {};

            Silverlight.createDelegate = function(instance, method) {
                    return function() {
                    return method.apply(instance, arguments);
                }
            }

            //var scene = new ScriptWeb1.Scene();

            Silverlight.createObjectEx({
                    source: 'scene.xaml',
                    parentElement:
document.getElementById('silverlightPlugInHost'),
                    id: 'silverlightPlugIn',
                    properties: {
                            width: '100%',
                            height: '100%',
                            background:'white',
                            version: '2.0.31005.0'
                    },
                    events: {
                        onLoad: null,  //Silverlight.createDelegate(scene,
scene.handleLoad)
                            onError: function(sender, args) {
                                        var errorDiv = 
document.getElementById("errorLocation");
                                        if (errorDiv != null) {
                                                var errorText = args.errorType 
+ "- " +
args.errorMessage;

                                                if (args.ErrorType == 
"ParserError") {
                                                        errorText += "<br>File: 
" + args.xamlFile;
                                                        errorText += ", line " 
+ args.lineNumber;
                                                        errorText += " 
character " + args.charPosition;
                                                }
                                                else if (args.ErrorType == 
"RuntimeError") {
                                                        errorText += "<br>line 
" + args.lineNumber;
                                                        errorText += " 
character " +  args.charPosition;
                                                }
                                                errorDiv.innerHTML = errorText;
                                        }
                                }
                    },
                    context: null
            });
                </script>
        </div>
</body>
</html>




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to