def post(self): n = Notes(author=self.request.get('author'), text=self.request.get('text'), priority=self.request.get('priority'), status=self.request.get('status')) n.put() return webapp2.redirect('/')
def post(self): n = Notes(author=self.request.get('inputName'), text=self.request.get('inputUsername'), priority=self.request.get('inputPassword'), status=self.request.get('inputPassword')) n.put() return webapp2.redirect('/showusers')
def post(self): n = Notes(author=self.request.get('author'), text=self.request.get('text'), priority=self.request.get('priority'), status=self.request.get('status') , whichuser=users.get_current_user() ) n.put() return webapp2.redirect('/notes')
def post(self, notebook_id): notebook = db.get(db.Key.from_path("Notebooks", notebook_id)) n = Notes( parent=notebook, author=self.request.get("author"), text=self.request.get("text"), priority=self.request.get("priority"), status=self.request.get("status"), ) n.put() return webapp2.redirect("/read/%s" % notebook_id)
def post(self): user = users.get_current_user() if user: n = Notes(author=user.user_id(), title=self.request.get('title'), text=self.request.get('text'), priority=self.request.get('priority'), status=self.request.get('status')) n.put() return webapp2.redirect('/home') else: return webapp2.redirect('/')
def user_login(): if request.method == 'POST': try: description = request.values.get('description') creater_user_id = request.values.get('user_id') if not description: return json.dumps({'error':'discription_IS_MANDOTRY','status':0}) if not creater_user_id: return json.dumps({'error':'PLS_GIVE_CURRENT_USER_ID','status':0}) q = Notes(description=description,creater_user_id=creater_user_id) db.session.add(q) db.session.commit() js={'status':1,'message':'notes created successfully!!'} return json.dumps(js) except Exception as e: print "==SOMETHING WENT WRONG!!",str(e) return json.dumps({'error':'SOMETHING_WENT_WRONG_IN_POSTING_NOTES','status':0}) elif request.method == 'GET': # get all the notes result_set_data=[] q = db.session.query(Notes.description,User.user_firstname,User.id.label('Creator_user_id')) q = q.join(User,Notes.creater_user_id == User.id) q = q.filter(User.status == 'A').all() if q: result_set_data = [u._asdict() for u in q] return json.dumps({'status':1,'data':result_set_data}) elif request.method == 'PUT': #get user id and notes id of the person editing the notes user_id = request.values.get('user_id') notes_id = request.values.get('notes_id') print "==notes_id",notes_id if not user_id: return json.dumps({'error':'user_id_IS_MANDOTRY_FOR_UPDATING RECORDS','status':0}) elif not notes_id: return json.dumps({'error':'notes_id_IS_MANDOTRY_FOR_UPDATING RECORDS','status':0}) # check whether the user has right to change the note if validate_access_for_notes(user_id=user_id,notes_id=notes_id,action='UPDATE'): description = request.values.get('description') if not description: return json.dumps({'error':'discription_IS_MANDOTRY','status':0}) q = db.session.query(Notes).filter(Notes.id == notes_id).update({ 'description':description }) db.session.commit() return json.dumps({'status':1,'message':'notes updated successfully!!'}) else: return json.dumps({'status':0,'error':'ACCESS_DENIED'}) else: return json.dumps({'error':'UNAUTHORISED_METHOD_FOR_ACCESS','status':0})
def post(self): user = users.get_current_user() if user: n = Notes(id=user.user_id(), author=self.request.get('author'), text=self.request.get('text'), priority=self.request.get('priority'), status=self.request.get('status')) n.put() return webapp2.redirect('/') else: self.redirect('/')
def notes(mod): if not is_logged_in(): return jsonify({'reponse': "Not Logged in!"}) user = User.query.get(session['userid']) if request.method == 'POST': if request.is_json: for note in request.json: note_obj = Notes.query.get(note['id']) if note_obj is not None: note_obj.content = note['notes'] else: note_obj = Notes(note['id'], session['userid'], mod, note['notes']) db.session.add(note_obj) db.session.commit() return jsonify( {'reponse': "Updated notes for user " + session['userid']}) return jsonify({'reponse': 'Invalid request!'}) if request.method == 'GET': response = [] for note in user.notes: if note.module == mod: response.append(note.as_json()) return jsonify(response) if request.method == 'DELETE': note = Notes.query.filter(note_id=mod) if note is not None: note.delete() db.session.commit() return jsonify({'reponse': "Deleted note " + mod}) else: return jsonify({'reponse': "Note not found!"})
def save_shared(link): note_id = re.search('[0-9]+', link.split('-')[1]) if note_id is None: flash( 'There seems to be an error here, sorry. We will check into this', 'danger') return redirect(url_for('index')) note_id = int(note_id.group(0)) n = Notes.query.get(note_id) key = str(n.id) + str(n.user_id) if link.split('-')[0] == hashlib.sha224(str(n.title) + "," + key).hexdigest(): if not g.user.notebooks.filter_by(title='Shared Notes').first(): nb = Notebooks(title="Shared Notes", timestamp=datetime.utcnow(), notebook=g.user) db.session.add(nb) else: #User.query.filter_by(nickname = nickname).first() nb = g.user.notebooks.filter_by(title='Shared Notes').first() # this is here due to real server having slightly different encryption # (padding) note_body = decrypt_it(n.body) note_body = note_body.decode('utf8', errors='ignore') nn = Notes(title=n.title, body=encrypt_it(note_body), timestamp=datetime.utcnow(), notes_link=nb, note=g.user) db.session.add(nn) db.session.commit() return redirect(url_for('members')) flash('There has been an error. Sorry, we will look into the problem', 'danger') return redirect(url_for('index'))
def save_note(request, note_id=None): assert request.method == 'POST' form = NoteForm(request.POST) if form.is_valid(): clean_data = form.cleaned_data if note_id: note = Notes.objects.get(owner = request.user, id = note_id) note.text = clean_data['text'] note.title = clean_data['title'] note.importance = clean_data['importance'] note.save() else: note = Notes(title = clean_data['title'], text = clean_data['text'], owner = request.user, importance = clean_data['importance']) note.save() note_id = str(note.id) return HttpResponseRedirect('/note_content/' + note_id)
def add(): ''' This is the function which is responsible to for additon of data to the mongoDb :return: node ''' title = input("Add an Title :") Body = input("Body :") node = Notes.Notes(title, Body) return node pass
def get(self): notes = Notes.all() logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/notes/create' ) else: login = users.create_login_url('/notes/create') self.render_template('index.html', {'notes': notes,'currentuser':currentuser, 'login':login, 'logout': logout})
def post(self): validation = "false" username = self.request.get('inputUsername') password = self.request.get('inputPassword') notes = Notes.all() for note in notes: if note.text == username: if note.priority == password: return webapp2.redirect('/first/' + note.text) return webapp2.redirect('/login')
def create(): form = NotesForm() if request.method == 'POST': if form.validate_on_submit(): note = Notes(form.title.data, form.author.data, form.description.data, form.subject.data) db.session.add(note) db.session.commit() flash('Note saved on database.') return redirect(url_for('list_notes')) return render_template('note.html', form=form)
def get(self): user = users.get_current_user() logging.info('************ ' + user.nickname() + ' on MainPage *******') if user: notes = Notes.all().filter('owner = ', user).order('priority').order('date') nickname = user.nickname() users.create_logout_url('/') self.render_template('index.html', {'notes': notes,'user':user,'nickname':nickname},) else: self.redirect(users.create_login_url(self.request.uri))
def save_note(): """POST to create note takes in a JSON with username, jwt, title and content for the notec might return error if jwt is not valid or expired """ body = request.json user_id = body.get('user_id') token = body.get('token') user = User.get(User.id == user_id).username if not validate_token(user, token): return HTTPResponse(status=400, body={"message": "Validation error."}) note_title = body.get('title') note_content = body.get('content') validation = validate_note(user, note_title, note_content) if validation != "OK": return HTTPResponse(status=500, body={"message": validation}) new_note = Notes(user=user_id, title=note_title, content=note_content) new_note.save() new_token = generate_token(user) ret = {"token": new_token.decode('utf-8'), "user_id": user_id} return HTTPResponse(status=500, body=ret)
def get(self): user = users.get_current_user() if user: notes = Notes.all().filter("id =", user.user_id()) if decorator.has_credentials(): try: http = decorator.http() gplus = service.people().get(userId='me').execute(http=http) self.render_template('index.html', {'notes': notes, 'gplus': gplus, 'users': users}) except client.AccessTokenRefreshError: self.redirect('/') else: self.redirect(decorator.authorize_url()) else: self.redirect(users.create_login_url(self.request.uri))
def newnote(): form = AddNoteForm() if request.method == 'POST': if form.validate() == False: return render_template('newNote.html', form=form) else: #curuser = session['username'] newNote = Notes(form.title.data, form.description.data, session['username'], form.category.data) db.session.add(newNote) db.session.commit() flashmessage = "Note added by %s" % session['username'] flash(flashmessage) return redirect(url_for('notes')) elif request.method == 'GET': return render_template('newNote.html', form=form)
async def post(self, request): data = await request.json() mongo_note = Notes(title=data['title'], description=data['description'], created_at=data['created_at'], created_by=data['created_by'], priority=data['priority']).save() return Response(status=201, body=self.resource.encode({ 'notes': [{ 'title': note.title, 'description': note.description, 'created_at': note.created_at, 'created_by': note.created_by, 'priority': note.priority } for note in Notes.objects] }), content_type='application/json')
def todos(username=None): if request.method == 'GET': notes = Notes.query.filter_by(username=username).first() if username is not None: return jsonify(notes.serialize()), 200 else: return jsonify({"msg": "username not exist "}), 404 if request.method == 'POST': todos = request.get_json('todos') notes = Notes() notes.username = username notes.todos = json.dumps(todos) db.session.add(notes) db.session.commit() return jsonify(notes.serialize()), 201 if request.method == 'PUT': todos = request.json.get('todos') Notes = Notes.query.get(id).first() notes.username = username notes.todos = json.dumps(todos) db.session.commit() return jsonify(notes.serialize()), 200 if request.method == 'DELETE': notes = Notes.query.get(id) db.session.delete(notes) db.session.commit() return jsonify({"resultado": "Notas eliminada"}), 200
def get_all_notes(user_id, token): """GET to list notes for user takes in parameters from url for user and the jwt """ user = User.get(User.id == user_id).username if not validate_token(user, token): return HTTPResponse(status=500, body={"message": "Validation error."}) res = [] for note in Notes.select(): if note.user.id == user_id: new_note = model_to_dict(note) res.append({ "id": new_note['id'], "title": new_note['title'], "content": new_note['content'] }) new_token = generate_token(user) body = { "user_id": user_id, "token": new_token.decode('utf-8'), 'items': res } return HTTPResponse(status=200, body=body)
def zip_ingress(data, study_id): print "Starting zip ingress for study %s" % study_id conn = db.engine.connect() zpf = zipfile.ZipFile(data) print zpf.namelist() for file in zpf.namelist(): if not file.endswith(".csv"): continue if file.startswith("__MACOSX"): continue print "Trying to parse %s" % file # first add empty dataset to get key dataset = Datasets(file, study_id) db.session.add(dataset) db.session.commit() dataset_id = dataset.id # then parse file and add notes and points with Core bulk inserts parsed = parser.parse(zpf.open(file)) selector = generate_selector(parsed['data']) notes = [Notes.dict_from_parsed(note_text, dataset_id) for note_text in parsed['notes']] data_points = [DataPoints.dict_from_parsed(parsed_point, dataset_id, selector) for parsed_point in parsed['data']] # db.session.bulk_insert_mappings(DataPoints, data_points) conn.execute(DataPoints.__table__.insert(), data_points) # db.session.bulk_insert_mappings(Notes, notes) conn.execute(Notes.__table__.insert(), notes) db.session.commit() study = Studies.query.get(study_id) study.update_range()
def update_database(request): if request.is_ajax(): url = "http://www.digitaltruth.com/chart/notes.php" response = urllib2.Request(url, headers=headers) html = urllib2.urlopen(response).read() soup = BeautifulSoup(html, 'lxml', from_encoding='utf8') for tr in soup.find_all(name='tr'): extract_list = tr.find_all(name='td') if (extract_list[0].get_text() == '42' or extract_list[0].get_text() == '43' or extract_list[0].get_text() == '44' or extract_list[0].get_text() == '45'): content = extract_list[1].get_text().split('see')[0].strip() note = Notes(Notes=extract_list[0].get_text(), Remark=content) note.save() elif extract_list[0].get_text() == '46': pass else: note = Notes(Notes=extract_list[0].get_text(), Remark=extract_list[1].get_text()) note.save() return HttpResponse(u"更新数据库完毕!")
def get(self, id): username = id notes = Notes.all() for note in notes: if note.text == username: self.render_template('first.html', {'note': note})
def add_note(from_player, data_list): from_player_object = Player.objects.get(player_name=from_player) to_player_object = Player.objects.get(id=data_list['to_player']) new_note = Notes(from_player=from_player_object, to_player=to_player_object, note=data_list['message']) new_note.save()
def get(self): notes = Notes.all() self.render_template('users_index.html', {'notes': notes})
def members(page=0, booked=0): user = g.user fc, books, notes = g.user.get_books() form = Note_Form() form2 = Note_Title() form3_new_notebook = New_Notebook() form4_new_note_title = Rename_Note() form5_new_notebook_title = Rename_Notebook() form6_new_fc_title = Rename_FileCabinet() form7_new_fc = New_FileCabinet() form8_new_fcnotebook = New_FCNotebook() form9_move_notebook = Move_Notebook() merge = Merge() attach = Attach(csrf_enabled=False) notebook_title = "" # notebook title fcd = 0 note_counter = {} # Pass if this note is passphrased or not if page > 0: page_note = Notes.query.get(page).passphrased else: page_note = "" # Make sure the notebook is theirs if booked > 0: if booked is None: flash( 'Notebook not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) nbid = Notebooks.query.get(int(booked)) if notebook_check_out(nbid): notebook_title = nbid.title fcd = nbid.filecabinet else: return redirect(url_for('members')) # Populate the list choices form9_move_notebook.fc_select.choices = [(fcg.id, fcg.title) for fcg in fc] merge.nt_select.choices = [(nt.id, nt.title) for nt in notes] # Count the notes in each book for badges for book in books: for note in notes: if note.notebooks_id == book.id: if book.id in note_counter: note_counter[book.id] += 1 else: note_counter[book.id] = 1 elif note.notebooks_id is None: # delete the orphans n = Notes.query.get(note.id) db.session.delete(n) db.session.commit() # New note if form2.validate_on_submit(): nbid = form2.hidden2.data if nbid is None: flash( 'Notebook not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) nb = Notebooks.query.get(int(nbid)) if notebook_check_out(nb): tt = nohtml(form2.notetitle.data) if len(tt) > 40: flash('Can you make it smaller please?', 'danger') return redirect(url_for('members')) nn = Notes(title=tt, body=" ", timestamp=datetime.utcnow(), notes_link=nb, note=g.user) db.session.add(nn) db.session.commit() return redirect(url_for('members', page=nn.id, booked=int(nbid))) # New notebook if form3_new_notebook.validate_on_submit(): nb_title = nohtml(form3_new_notebook.book_title.data) if len(nb_title) > 40: flash('Please make the Notebook title shorter', 'danger') return redirect(url_for('members')) nb = Notebooks(title=nb_title, timestamp=datetime.utcnow(), notebook=g.user) db.session.add(nb) nn_title = nohtml(form3_new_notebook.new_note_title.data) if len(nn_title) > 40: flash('Please make the Note title shorter', 'danger') nn = Notes(title=nn_title, body=" ", timestamp=datetime.utcnow(), notes_link=nb, note=g.user) db.session.add(nn) db.session.commit() return redirect(url_for('members', page=nn.id, booked=nb.id)) # Rename note if form4_new_note_title.validate_on_submit(): ids = re.search('[0-9]+', form4_new_note_title.hidden_note_id.data) if ids is None: flash( 'Note not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) n = Notes.query.get(int(ids.group(0))) if note_check_out(n): nn_title = nohtml(form4_new_note_title.new_title.data) if len(nn_title) > 40: flash('Please make the Note title shorter', 'danger') n.title = nn_title db.session.add(n) db.session.commit() return redirect( url_for('members', page=n.id, booked=n.notebooks_id)) return redirect(url_for('members')) # Rename notebook if form5_new_notebook_title.validate_on_submit(): nbid = re.search('[0-9]+', form5_new_notebook_title.hidden_book_id.data) if nbid is None: flash( 'Notebook not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) nb = Notebooks.query.get(int(nbid.group(0))) if notebook_check_out(nb): nb_title = nohtml(form5_new_notebook_title.new_nbtitle.data) if len(nb_title) > 40: flash('Please make the Notebook title shorter', 'danger') return redirect(url_for('members')) nb.title = nb_title db.session.add(nb) db.session.commit() return redirect(url_for('members', page=0, booked=nb.id)) return redirect(url_for('members')) # Rename file cabinet title if form6_new_fc_title.validate_on_submit(): fcid = re.search('[0-9]+', form6_new_fc_title.hidden_fc_id.data) if fcid is None: flash( 'File Cabinet not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) nfc = Filecabinets.query.get(int(fcid.group(0))) if filecabinet_check_out(nfc): fc_title = nohtml(form6_new_fc_title.new_fctitle.data) if len(fc_title) > 40: flash('Please make the File Cabinet title shorter', 'danger') return redirect(url_for('members')) nfc.title = fc_title db.session.add(nfc) db.session.commit() return redirect(url_for('members')) return redirect(url_for('members')) # New file cabinet if form7_new_fc.validate_on_submit(): fc_title = nohtml(form7_new_fc.fc_title.data) if len(fc_title) > 40: flash('Please make the File Cabinet title shorter', 'danger') return redirect(url_for('members')) nfc = Filecabinets(title=fc_title, filecabinet=g.user) db.session.add(nfc) nb_title = nohtml(form7_new_fc.nb_title.data) if len(nb_title) > 40: flash('Please make the Notebook title shorter', 'danger') nb = Notebooks(title=nb_title, timestamp=datetime.utcnow(), notebook=g.user, notebook_link=nfc) db.session.add(nb) db.session.commit() return redirect(url_for('members', page=0, booked=nb.id)) # New notebook in a file cabinet if form8_new_fcnotebook.validate_on_submit(): fcid = re.search('[0-9]+', form8_new_fcnotebook.hidden_fc_id2.data) if fcid is None: flash( 'File Cabinet not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) nfc = Filecabinets.query.get(int(fcid.group(0))) if filecabinet_check_out(nfc): nb_title = nohtml(form8_new_fcnotebook.fcbook_title.data) if len(nb_title) > 40: flash('Please make the Notebook title shorter', 'danger') return redirect(url_for('members')) nb = Notebooks(title=nb_title, timestamp=datetime.utcnow(), notebook=g.user, notebook_link=nfc) db.session.add(nb) nn_title = nohtml(form8_new_fcnotebook.fcnew_note_title.data) if len(nn_title) > 40: flash('Please make the Note title shorter', 'danger') nn = Notes(title=nn_title, body=" ", timestamp=datetime.utcnow(), notes_link=nb, note=g.user) db.session.add(nn) db.session.commit() return redirect(url_for('members', page=nn.id, booked=nb.id)) return redirect(url_for('members')) # Move notebooks to file cabinets if form9_move_notebook.validate_on_submit(): new_fc_id = form9_move_notebook.fc_select.data if new_fc_id is None or not isinstance(new_fc_id, int): flash( 'There seems to be a problem. If you think this is in error, please contact us.', 'danger') fc = Filecabinets.query.get(int(new_fc_id)) if filecabinet_check_out(fc): nb_id = re.search('[0-9]+', form9_move_notebook.hidden_nb_id2.data) if nb_id is None: flash( 'There seems to be a problem. If you think this is in error, please contact us.', 'danger') nb = Notebooks.query.get(int(nb_id.group(0))) if notebook_check_out(nb): nb.notebook_link = fc db.session.add(nb) db.session.commit() return redirect(url_for('members', page=0, booked=nb.id)) return redirect(url_for('members')) return redirect(url_for('members')) # Merge two notes if merge.validate_on_submit(): mergee_id = re.search('[0-9]+', merge.merge_note_id.data) if mergee_id is None: flash( 'Note not found. If you think this is in error, please contact us.', 'danger') return redirect(url_for('members')) n = Notes.query.get(int(mergee_id.group(0))) merger_id = merge.nt_select.data if int(mergee_id.group(0)) == int(merger_id): flash('You can not merge a Note into itself', 'danger') return redirect(url_for('members')) if n.passphrased: flash('You can not merge a passphrased note', 'danger') return redirect(url_for('members')) nn = Notes.query.get(int(merger_id)) if nn.passphrased: flash('You can not merge a passphrased note', 'danger') return redirect(url_for('members')) if note_check_out(n) and note_check_out(nn): if len(n.body) < 2 or len(nn.body) < 2: flash('You can not merge an empty note', 'danger') return redirect(url_for('members')) mergee = decrypt_it(n.body) merger = decrypt_it(nn.body) new_note = mergee.decode('utf8', errors='ignore') + merger.decode( 'utf8', errors='ignore') if len(new_note) <= 524279: n.body = encrypt_it(new_note) db.session.add(n) db.session.delete(nn) db.session.commit() return redirect( url_for('members', page=n.id, booked=n.notebooks_id)) return redirect(url_for('members')) return render_template( "members.html", title='Members', user=user, form=form, form2=form2, form3_new_notebook=form3_new_notebook, form4_new_note_title=form4_new_note_title, form5_new_notebook_title=form5_new_notebook_title, form6_new_fc_title=form6_new_fc_title, form7_new_fc=form7_new_fc, form8_new_fcnotebook=form8_new_fcnotebook, form9_move_notebook=form9_move_notebook, merge=merge, note_counter=note_counter, fc=fc, fcd=fcd, page=page, # reload with right note selected page_passphrased=page_note, attach=attach, booked=booked, # reload with right notebook selected notebook_title=notebook_title, books=books, notes=notes)
def main(): ''' This is the main Function which will be responsible for running all the functions for the version 1 , console application :return: ''' path = str(config.getConfig()['MongoDb']['URL']) print("Connecting to Database") con = connection.Mongo(path) n = Notes.Notes("", "") data = con.FindAll(n.tablename) if data: for i in data: allNotes.append( Notes.Notes(i['name'], i['data'], i['_id'], i['created_at'])) print(allNotes[-1]) while True: os.system("clear") try: print("Welcome To Notes Application , version 1.0.0") print( "1.Add a Note\n2.Find a note\n3.Delete a Note\n4.See all Notes\n5.exit" ) try: n = int(input("Enter Your Choice >>")) except ValueError: continue if n == 5: raise KeyboardInterrupt elif n == 1: node = add() id = con.Insert(node.tablename, node.retData()) node.setId(id) allNotes.append(node) print("Added") time.sleep(2) elif n == 2: result = find() if result['status'] == 'OK': for i in result['data']: print(i) else: name = result['name'] node = Notes.Notes(name, "") data = con.Find(node.tablename, node.name) if data: for i in data: allNotes.append( Notes.Notes(i['name'], i['data'], i['_id'], i['created_at'])) print(allNotes[-1]) input() elif n == 3: arr = delete() if not arr: continue if len(arr) <= 0: print("Enter The Correct Indexes again please !!") time.sleep(1.2) continue n = Notes.Notes("", "") count = con.Delete(n.tablename, arr) print("Delete Count: {}".format(count)) input() elif n == 4: if not findAll(): n = Notes.Notes("", "") data = con.FindAll(n.tablename) if data: for i in data: allNotes.append( Notes.Notes(i['name'], i['data'], i['_id'], i['created_at'])) print(allNotes[-1]) pass input() else: continue except Exception as E: print("Exception has occured {} \n".format(E)) raise KeyboardInterrupt except KeyboardInterrupt: print("quitting...") exit(1)
def get(self): notes = Notes.all() self.render_template('index.html', {'notes': notes, 'users': users})
def get(self): user = users.get_current_user() notes = Notes.all().filter("author =", user.user_id()) self.render_template('home.html', {'notes': notes, 'users': users})