Skip to content

Commit

Permalink
Cambiado modelo del dominio para usar una relacion one-to-many
Browse files Browse the repository at this point in the history
  • Loading branch information
Erick committed Sep 3, 2008
1 parent 1320acc commit 87f775c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 18 deletions.
20 changes: 20 additions & 0 deletions src/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,29 @@ handlers:
- url: /stylesheets
static_dir: stylesheets

- url: /gwt
static_dir: gwt

- url: /load_classes
script: sabandija_classes_loader.py

- url: /load
script: sabandija_loader.py

- url: /
script: sabandija.py


- url: /search
script: sabandija.py


- url: /(.*)
static_files: gwt/\1
upload: gwt/(.*)



- url: /.*
script: sabandija.py

Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% endif %}
<ul>
{% for artifact in artifacts %}
<li>{{ artifact.className }} <a href='{{ artifact.url }}{{ artifact.jarName }}.jar'>download</a></li>
<li>{{ artifact.name }} <a href='{{ artifact.url }}{{ artifact.jarName }}.jar'>download</a></li>
{% endfor %}
</ul>
</body>
Expand Down
11 changes: 11 additions & 0 deletions src/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
58 changes: 46 additions & 12 deletions src/sabandija.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cgi
import os
import json
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext import search
Expand All @@ -11,6 +13,16 @@
from google.appengine.ext.webapp import template


class Artifact( db.Model ):
url = db.StringProperty(multiline=False)
artifactId = db.StringProperty(multiline=False)
groupId = db.StringProperty(multiline=False)
modelVersion = db.StringProperty(multiline=False)
version = db.StringProperty(multiline=False)
size = db.StringProperty(multiline=False)
md5 = db.StringProperty(multiline=False)
sha1 = db.StringProperty(multiline=False)


class MainPage( webapp.RequestHandler ):
def get( self ):
Expand All @@ -22,27 +34,49 @@ def get( self ):
self.response.out.write( template.render( path, template_values ) )

class SearchPage( webapp.RequestHandler ):
def get( self ):
# We use the webapp framework to retrieve the keyword
keyword = self.request.get( 'keyword' )
if keyword:
artifacts = search( keyword )
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write( json.write( artifacts ) )

def post( self ):
# We use the webapp framework to retrieve the keyword
keyword = self.request.get( 'keyword' )

#self.response.headers[ 'Content-Type' ] = 'text/plain'
#self.response.out.write('%s' % keyword)

template_values = { }
if keyword:
# Search the 'Artifact' Entity based on our keyword
query = search.SearchableQuery( 'Artifact' )
query.Search(keyword)
results = query.Run()
template_values = { 'artifacts': results,
if search:
artifacts = self.search( keyword )
template_values = { 'artifacts': artifacts,
'keyword' : keyword
}

path = os.path.join( os.path.dirname(__file__), 'index.html' )
self.response.out.write( template.render( path, template_values ) )
# for result in query.Run():
# self.response.out.write('%s' % result['jarName'] + ".jar")



def search( self, keyword ):
# Search the 'Clazz' Entity based on our keyword
query = search.SearchableQuery( 'Clazz' )
query.Search(keyword)
results = query.Run()
artifacts = []
for result in results:
#get the associated artifact for the class
key = result[ 'artifact' ]
artifact = db.get(key)
if artifact:
item = {
'name' : result[ 'className' ],
'url' : artifact.url
}
artifacts.append( item )
return artifacts;



def main():
application = webapp.WSGIApplication( [
( '/', MainPage ),
Expand Down
30 changes: 30 additions & 0 deletions src/sabandija_classes_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from google.appengine.api import datastore
from google.appengine.ext import bulkload
from google.appengine.api import datastore_types
from google.appengine.ext import search
from google.appengine.ext import db
import logging

class ClazzLoader( bulkload.Loader ):
def __init__( self ):
bulkload.Loader.__init__( self, 'Clazz',
[ ( 'url' , str ),
( 'className' , str )
# ( 'sbjModified' , str )
] )

def HandleEntity( self, entity ):
#Obtain the Artifact entity associated to this model
url = entity['url']
art = datastore.Query('Artifact', {'url': url}).Get(1)
if art[0]:
newent = datastore.Entity( 'Clazz' )
newent[ 'artifact' ] = art[0].key()
newent[ 'className' ] = entity['className']
ent = search.SearchableEntity( newent )
return ent
else:
logging.info("not done :-(")

if __name__ == '__main__':
bulkload.main( ClazzLoader() )
12 changes: 7 additions & 5 deletions src/sabandija_loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from google.appengine.api import datastore
from google.appengine.ext import bulkload
from google.appengine.api import datastore_types
from google.appengine.ext import search
Expand All @@ -6,8 +7,7 @@
class ArtifactLoader( bulkload.Loader ):
def __init__( self ):
bulkload.Loader.__init__( self, 'Artifact',
[ ( 'url' , str ),
( 'jarName' , str ),
[ ( 'url' , str ),
( 'artifactId' , str ),
( 'groupId' , str ),
( 'modelVersion', str ),
Expand All @@ -16,13 +16,15 @@ def __init__( self ):
( 'md5' , str ),
( 'sha1' , str ),
( 'mvnModified' , str ), #lambda x: datetime.datetime.strptime( x, '%d-%m-%Y %H:%M' ) ),
( 'className' , str )
#( 'className' , str )
# ( 'sbjModified' , str )
] )

def HandleEntity( self, entity ):
ent = search.SearchableEntity( entity )
return ent
newent = datastore.Entity( 'Artifact', name = entity[ 'url'] )
newent.update(entity)
#ent = search.SearchableEntity(newent)
return newent

if __name__ == '__main__':
bulkload.main( ArtifactLoader() )

0 comments on commit 87f775c

Please sign in to comment.