def detail(request, username, id): if request.method == "DELETE": session = checkSession(username) if session == False: docs = Database("https://*****:*****@wazza.cloudant.com/" + username + "/") deldocs = docs #If delete all is checked if id == 'deleteall': #Try to delete with given credientials try: for x in deldocs: temp = deldocs[x] docs.delete(temp) #Or report incorrect credentials except Unauthorized: return HttpResponse( '<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Could not authenticate"></error>' ) else: #Delete individial doc that is checked try: doc = docs[id] #Once again prompt if invalid credentials except: return HttpResponse( '<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "No number/authentication"></error>' ) try: #This is the actual deletion of the doc docs.delete(doc) return HttpResponse( '<?xml version="1.0" Name="WS Project 2D"?> \n <success value = "Number Deleted"></success>' ) #This will never happen as the document will be there if it is listed for deletion #But just in case :) except ResourceNotFound: return HttpResponse( '<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Number not found"></error>' ) else: return HttpResponse( '<?xml version="1.0" Name="WS Project 2C API"?> \n <error value = "Session Expired"></error>' ) else: return HttpResponse('none') #return render_to_response('delete/delete.html',{'rows':docs,'username':u}) #Render success message return HttpResponse('nothing happened')
def deleteAllFoundationDocuments( db : couchdb.Database ): thereAreRecords = True while thereAreRecords : query = db.find( {'selector' : { "source" : { "$eq" : "foundation" } }, "limit" : 10000000 } ) thereAreRecords = False for row in query : db.delete( row ) thereAreRecords = True
def detail(request,username,id): if request.method == "DELETE": session = checkSession(username) if session == False: docs = Database("https://*****:*****@wazza.cloudant.com/"+username+"/") deldocs = docs #If delete all is checked if id=='deleteall': #Try to delete with given credientials try: for x in deldocs: temp = deldocs[x] docs.delete(temp) #Or report incorrect credentials except Unauthorized: return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Could not authenticate"></error>') else: #Delete individial doc that is checked try: doc = docs[id] #Once again prompt if invalid credentials except: return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "No number/authentication"></error>') try: #This is the actual deletion of the doc docs.delete(doc) return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <success value = "Number Deleted"></success>') #This will never happen as the document will be there if it is listed for deletion #But just in case :) except ResourceNotFound: return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Number not found"></error>') else: return HttpResponse('<?xml version="1.0" Name="WS Project 2C API"?> \n <error value = "Session Expired"></error>') else: return HttpResponse('none') #return render_to_response('delete/delete.html',{'rows':docs,'username':u}) #Render success message return HttpResponse('nothing happened')
def login(request): auth = False registration = False #Connect to DB users = Database("https://*****:*****@wazza.cloudant.com/users") session = Database("https://*****:*****@wazza.cloudant.com/session") #This will always be a POST but just incase checking is always good :) if request.method =="POST": #Get username ,password and number u = request.POST['username'] p = request.POST['password'] try: newUser = request.POST['register'] registration = True except: registration = False else: return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "POST Request Expected"></error>') if registration == True: if u == '' or p == '': return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Both Username & Password Required"></error>') try: usr = users[u] return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Username already taken"></error>') except: users[u] = {'username':u,'password':p} server = Server('https://*****:*****@wazza.cloudant.com/') server.create(u) try: session[u] = {'username':u,'timestamp':strftime("%Y-%m-%d %H:%M:%S")} except: session.delete(u) session[u] = {'username':u,'timestamp':strftime("%Y-%m-%d %H:%M:%S")} return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <success value = "Authenticated"></success>') else: for x in users: try: if users[u]: user = users[u] if user['password'] == p: auth = True else: auth = False else: auth = False except: auth = False if auth == True: try: session[u] = {'username':u,'timestamp':strftime("%Y-%m-%d %H:%M:%S")} except: delDoc = session[u] session.delete(delDoc) session[u] = {'username':u,'timestamp':strftime("%Y-%m-%d %H:%M:%S")} return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <success value = "Authenticated"></success>') else: return HttpResponse('<?xml version="1.0" Name="WS Project 2D"?> \n <error value = "Could not authenticate"></error>') return render_to_response('users/ulogin.html')
def logout(request, username): session = Database("https://*****:*****@wazza.cloudant.com/session") delDoc = session[username] session.delete(delDoc) return HttpResponseRedirect('/')
def deleteAllWords( db : couchdb.Database ): for row in db.iterview( 'all_words/all_words', 100 ) : db.delete( row.value )
#!/usr/bin/python from setup_config import setup_config from couchdb import Database from pylons import config from troppotardi.model import Email from troppotardi.lib.utils import send_email if __name__ == '__main__': setup_config() # Set up the database db = Database(config['couchdb_uri']) emails = Email.by_time(db) for email in emails: send_email(body=email.text, subject=email.subject, recipients=email.recipients, sender=email.sender) db.delete(email)