def submit(request): """ submit new object description, expected data: id, class, description (human readable), object_description and an arbitrary number of binary files.""" if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: # Hbase row and upload files files = {} for k,v in request.FILES.items(): files[request.POST[k]] = v if transaction.set(id_=request.POST['id'], author=request.user.username, class_=request.POST['class'], description=request.POST['description'], object_description=request.POST['object_description'], files=files): return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/objects", errorType=2, errorMessage="Object already exist. Please choose another Identifier")) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/objects", errorType=2, errorMessage=err.__str__()))
def submit(request): """ submit new action recipe, expected data: id, class, (human readable) description, recipe """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == "POST": try: if transaction.set( id_=request.POST["id"], class_=request.POST["class"], description=request.POST["description"], recipe=request.POST["recipe"], author=request.user.username, ): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/recipes", errorType=2, errorMessage="Recipe already exist. Please choose another Identifier", ) ) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/recipes", errorType=2, errorMessage=err.__str__()))
def submit(request): """ submit new action recipe, expected data: id, class, (human readable) description, recipe """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.set(id_=request.POST['id'], class_=request.POST['class'], description=request.POST['description'], recipe=request.POST['recipe'], author=request.user.username): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/recipes", errorType=2, errorMessage= "Recipe already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/recipes", errorType=2, errorMessage=err.__str__()))
def submit(request): """ submit new environment, expected data: id, class, (human readable) description, environment, lat (optional), lng (optional) For the class "osm" the database will perfom osm based geocoding based on the "id" string""" if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: lat = None lng = None if request.POST.has_key('addGeodata'): lat = request.POST['lat'] lng = request.POST['lng'] files = {} for k,v in request.FILES.items(): files[request.POST[k]] = v if transaction.set(id_=request.POST['id'], class_=request.POST['class'], description=request.POST['description'], environment=request.POST['environment'], lat = lat, lng = lng, author=request.user.username, files = files): return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/recipes", errorType=2, errorMessage="Environment already exist. Please choose another Identifier")) except (roboearth.DBWriteErrorException, roboearth.DBException, roboearth.FormInvalidException), err: return HttpResponse(views.error(request, nextPage="/environments", errorType=2, errorMessage=err.__str__()))
def update(request): """ update existing object description, expected data: complete id (class.id), object description and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.update(id_=request.POST['id'], author=request.user.username, data=request.POST): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/", errorType=2, errorMessage= "Object already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/", errorType=2, errorMessage=err.__str__()))
def submit(request): """ submit new robot location, expected data: id, complete id of an already stored environment, description and a picture of the robot""" if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: transaction.set(id_=request.POST['id'], author=request.user.username, description=request.POST['description'], srdl=request.POST['srdl'], picture=request.FILES['picture']) return HttpResponse(views.success(request)) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/robots", errorType=2, errorMessage=err.__str__())) except (roboearth.FormInvalidException, roboearth.NoDBEntryFoundException), err: return HttpResponse( views.error(request, nextPage="/robots", errorType=1, errorMessage=err.__str__()))
def request(request): """ handle search request and return the result """ def output(environments, query, semantic): template = loader.get_template('showEnvironment.html') values = { 'Environments': environments, 'is_auth': request.user.is_authenticated(), 'Query': query, 'Semantic': semantic } return render_to_response('showEnvironment.html', roboearth.webpage_values(request, values)) try: if request.method == 'GET': if request.user.is_authenticated(): username = request.user.username else: username = "" result = list() semantic = False # syntactic query if request.GET.has_key('query'): query = request.GET['query'] #semantic query else: semantic = True query = request.GET['semanticQuery'] if request.GET.has_key('exact') and request.GET['exact'] == "True": exact = True else: exact = False environments_list = transaction.get(query=query, semanticQuery=semantic, user=username, exact=exact) paginator = Paginator(environments_list, 10) page = request.GET.get('page') try: environments = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. environments = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. environments = paginator.page(paginator.num_pages) return output(environments, urllib2.quote(query.encode("utf8")), semantic) else: return requestForm(request) except roboearth.DBReadErrorException, err: return HttpResponse( views.error(request, nextPage="/environments/request/", errorType=3, errorMessage=err.__str__()))
def submit(request): """ submit new environment, expected data: id, class, (human readable) description, environment, lat (optional), lng (optional) For the class "osm" the database will perfom osm based geocoding based on the "id" string""" if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: lat = None lng = None if request.POST.has_key('addGeodata'): lat = request.POST['lat'] lng = request.POST['lng'] files = {} for k, v in request.FILES.items(): files[request.POST[k]] = v if transaction.set(id_=request.POST['id'], class_=request.POST['class'], description=request.POST['description'], environment=request.POST['environment'], lat=lat, lng=lng, author=request.user.username, files=files): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/recipes", errorType=2, errorMessage= "Environment already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException, roboearth.FormInvalidException), err: return HttpResponse( views.error(request, nextPage="/environments", errorType=2, errorMessage=err.__str__()))
def change_password(request): """ change password of the authenticated user """ if request.user.check_password(request.POST['password_old']) and request.POST['password_new0'] == request.POST['password_new1']: request.user.set_password(request.POST['password_new0']) request.user.save() return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/profile", errorType=0, errorMessage="Couldn't change your password, please try again!"+request.user.password))
def create(request): """ create new user account. The user have to provide first name, last name, username, password and a valid email address """ firstname = request.POST['firstname'] lastname = request.POST['lastname'] username = request.POST['username'] password = request.POST['password'] email = request.POST['email'] try: User.objects.get(username__exact=username) return HttpResponse(registerForm(request, error=True)) except: pass user = User.objects.create_user(username, email, password) #user.is_active=False user.is_active=True # for ICRA user.first_name = firstname user.last_name = lastname user.save() #generate API key salt = str(datetime.datetime.now()) hashvalue = hashlib.sha1(username+password+email+salt).hexdigest() for c in username: hashvalue = hex(ord(c)).lstrip("0x")+hashvalue api_key = api_keys(username=username, key=hashvalue) api_key.save() transaction.create(username) # send mail to admin message = """ A new user asks for access to the RoboEarth platform: Username: %(username)s First Name: %(firstname)s Last Name: %(lastname)s E-Mail: %(email)s """ % {'username' : roboearth.replace_unicode(username), 'firstname' : roboearth.replace_unicode(firstname), 'lastname' : roboearth.replace_unicode(lastname), 'email' : roboearth.replace_unicode(email)} msg = MIMEText(message) msg['Subject'] = "new user registered" msg['From'] = roboearth.ADMIN msg['To'] = roboearth.ADMIN try: smtpObj = smtplib.SMTP('hermes') smtpObj.sendmail(roboearth.ADMIN, roboearth.ADMIN, msg.as_string()) smtpObj.quit() except Exception, e: return HttpResponse(views.error(request, errorType=2, errorMessage=e.__str__()))
def update(request): """ update existing object description, expected data: complete id (class.id), object description and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.update(id_=request.POST['id'], author=request.user.username, data=request.POST): return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/", errorType=2, errorMessage="Object already exist. Please choose another Identifier")) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/", errorType=2, errorMessage=err.__str__()))
def request(request): """ handle search request and return the result """ def output(objects, query, semantic): template = loader.get_template('showObject.html') values = {'Objects' : objects, 'is_auth' : request.user.is_authenticated(), 'Query' : query, 'Semantic' : semantic} return render_to_response('showObject.html', roboearth.webpage_values(request,values)) try: if request.method == 'GET': if request.user.is_authenticated(): username = request.user.username else: username = "" result = list() semantic = False # syntactic query print request.GET if request.GET.has_key('query'): query = request.GET['query'] else: semantic = True query = request.GET['semanticQuery'] if request.GET.has_key('exact') and request.GET['exact'] == "True": exact = True else: exact = False objects_list = transaction.get(query=query, semanticQuery=semantic, user=username, exact=exact) paginator = Paginator(objects_list, 10) page = request.GET.get('page') try: objects = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. objects = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. objects = paginator.page(paginator.num_pages) print 'query:', query return output(objects, urllib2.quote(query.encode("utf8")), semantic) else: return requestForm(request) except roboearth.DBReadErrorException, err: return HttpResponse(views.error(request, nextPage="/objects/request/", errorType=3, errorMessage=err.__str__()))
def submit(request): """ submit new object description, expected data: id, class, description (human readable), object_description and an arbitrary number of binary files.""" if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: # Hbase row and upload files files = {} for k, v in request.FILES.items(): files[request.POST[k]] = v if transaction.set( id_=request.POST['id'], author=request.user.username, class_=request.POST['class'], description=request.POST['description'], object_description=request.POST['object_description'], files=files): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/objects", errorType=2, errorMessage= "Object already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/objects", errorType=2, errorMessage=err.__str__()))
def unsubscribe(request): """ subscribe to a datum """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") try: transaction.unsubscribe(username = request.user.username, table = request.POST['table'], uid = request.POST['rowKey']) return HttpResponse(views.success(request)) except Exception, err: return HttpResponse(views.error(request, nextPage="/", errorType=2, errorMessage=err.__str__()))
def subscriptions(request): """ show all subscriptions of a user """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") try: values = {'Domain' : roboearth.DOMAIN, 'Subscriptions' : transaction.getSubscriptions(username=request.user.username), } return render_to_response('subscriptions.html', roboearth.webpage_values(request,values)) except Exception, err: return HttpResponse(views.error(request, nextPage="/", errorType=2, errorMessage=err.__str__()))
def request(request): """ handle search request and return the result """ def output(recipes, query, semantic): values = {"Recipes": recipes, "is_auth": request.user.is_authenticated(), "Query": query, "Semantic": semantic} return render_to_response("showRecipe.html", roboearth.webpage_values(request, values)) try: if request.method == "GET": if request.user.is_authenticated(): username = request.user.username else: username = "" result = list() semantic = False # syntactic query if request.GET.has_key("query"): query = request.GET["query"] # semantic query else: semantic = True query = request.GET["semanticQuery"] if request.GET.has_key("exact") and request.GET["exact"] == "True": exact = True else: exact = False recipes_list = transaction.get(query=query, semanticQuery=semantic, user=username, exact=exact) paginator = Paginator(recipes_list, 10) page = request.GET.get("page") try: recipes = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. recipes = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. recipes = paginator.page(paginator.num_pages) return output(recipes, urllib2.quote(query.encode("utf8")), semantic) else: return requestForm(request) except roboearth.DBReadErrorException, err: return HttpResponse(views.error(request, nextPage="/recipes/request/", errorType=3, errorMessage=err.__str__()))
def submit(request): """ submit new object location, expected data """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: transaction.setLocation(environment=request.POST['environment'], author=request.user.username, room_number = request.POST['room_number'], posX=request.POST['posX'], posY=request.POST['posY'], posZ=request.POST['posZ'], delta=request.POST['delta'], object_=request.POST['object']) return HttpResponse(views.success(request)) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/locations/objects", errorType=2, errorMessage=err.__str__()))
def submit(request): """ submit new object location, expected data """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: transaction.setLocation(environment=request.POST['environment'], author=request.user.username, room_number=request.POST['room_number'], posX=request.POST['posX'], posY=request.POST['posY'], posZ=request.POST['posZ'], delta=request.POST['delta'], object_=request.POST['object']) return HttpResponse(views.success(request)) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/locations/objects", errorType=2, errorMessage=err.__str__()))
except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/robots", errorType=2, errorMessage=err.__str__())) except (roboearth.FormInvalidException, roboearth.NoDBEntryFoundException), err: return HttpResponse( views.error(request, nextPage="/robots", errorType=1, errorMessage=err.__str__())) else: return HttpResponse( views.error(request, nextPage='/robots', errorType=1)) def request(request): """ handle search request and return the result """ def output(robots, query): template = loader.get_template('showRobot.html') values = { 'Robots': robots, 'Query': query, 'is_auth': request.user.is_authenticated() } return render_to_response('showRobot.html', roboearth.webpage_values(request, values))
class_=request.POST['class'], description=request.POST['description'], environment=request.POST['environment'], lat = lat, lng = lng, author=request.user.username, files = files): return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/recipes", errorType=2, errorMessage="Environment already exist. Please choose another Identifier")) except (roboearth.DBWriteErrorException, roboearth.DBException, roboearth.FormInvalidException), err: return HttpResponse(views.error(request, nextPage="/environments", errorType=2, errorMessage=err.__str__())) else: return HttpResponse(views.error(request, nextPage='/environments', errorType=1)) def update(request): """ update an existing environment, expected data: complete id (class.id), environment and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: # now create the Hbase row if transaction.update(id_=request.POST['id'], data=request.POST, author=request.user.username): return HttpResponse(views.success(request))
request, nextPage="/objects", errorType=2, errorMessage= "Object already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/objects", errorType=2, errorMessage=err.__str__())) else: return HttpResponse( views.error(request, nextPage='/objects', errorType=1)) def update(request): """ update existing object description, expected data: complete id (class.id), object description and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.update(id_=request.POST['id'], author=request.user.username, data=request.POST): return HttpResponse(views.success(request))
views.error( request, nextPage="/recipes", errorType=2, errorMessage= "Recipe already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse( views.error(request, nextPage="/recipes", errorType=2, errorMessage=err.__str__())) else: return HttpResponse( views.error(request, nextPage='/recipes', errorType=1)) def update(request): """ update existing action recipe, expected data: complete id (class.id), new recipe and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.update(id_=request.POST['id'], data=request.POST, author=request.user.username): return HttpResponse(views.success(request)) else:
nextPage="/recipes", errorType=2, errorMessage= "Environment already exist. Please choose another Identifier" )) except (roboearth.DBWriteErrorException, roboearth.DBException, roboearth.FormInvalidException), err: return HttpResponse( views.error(request, nextPage="/environments", errorType=2, errorMessage=err.__str__())) else: return HttpResponse( views.error(request, nextPage='/environments', errorType=1)) def update(request): """ update an existing environment, expected data: complete id (class.id), environment and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: # now create the Hbase row if transaction.update(id_=request.POST['id'], data=request.POST, author=request.user.username):
if transaction.set(id_=request.POST['id'], author=request.user.username, class_=request.POST['class'], description=request.POST['description'], object_description=request.POST['object_description'], files=files): return HttpResponse(views.success(request)) else: return HttpResponse(views.error(request, nextPage="/objects", errorType=2, errorMessage="Object already exist. Please choose another Identifier")) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/objects", errorType=2, errorMessage=err.__str__())) else: return HttpResponse(views.error(request, nextPage='/objects', errorType=1)) def update(request): """ update existing object description, expected data: complete id (class.id), object description and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == 'POST': try: if transaction.update(id_=request.POST['id'], author=request.user.username, data=request.POST): return HttpResponse(views.success(request))
): return HttpResponse(views.success(request)) else: return HttpResponse( views.error( request, nextPage="/recipes", errorType=2, errorMessage="Recipe already exist. Please choose another Identifier", ) ) except (roboearth.DBWriteErrorException, roboearth.DBException), err: return HttpResponse(views.error(request, nextPage="/recipes", errorType=2, errorMessage=err.__str__())) else: return HttpResponse(views.error(request, nextPage="/recipes", errorType=1)) def update(request): """ update existing action recipe, expected data: complete id (class.id), new recipe and/or human readable description """ if not request.user.is_authenticated(): return HttpResponseRedirect("/login") if request.method == "POST": try: if transaction.update(id_=request.POST["id"], data=request.POST, author=request.user.username): return HttpResponse(views.success(request)) else: return HttpResponse( views.error(