Exemplo n.º 1
0
    def setup_method(self):

        # Adds two notes both with two versions
        # One marked as deleted

        flush_db(session)
        note1_1 = models.Note(title='test_note1', content='test_content1')
        note2_1 = models.Note(title='test_note2', content='test_content2')
        session.add_all([note1_1, note2_1])
        session.commit()

        note1_2 = models.Note(id=note1_1.id,
                              version=2,
                              title='updated_test_note1',
                              content='updated_test_content1',
                              deleted=True)

        note2_2 = models.Note(id=note2_1.id,
                              version=2,
                              title='updated_test_note2',
                              content='updated_test_content2')

        session.add_all([note1_2, note2_2])
        session.commit()

        TestViews.note1_id = note1_1.id
        TestViews.note2_id = note2_1.id
Exemplo n.º 2
0
    async def fetch(self) -> List[models.Note]:

        notes = []

        query = "SELECT id, title, data FROM notes"

        query = self._format_query(query)

        try:
            results = await self.storage.performer().fetch(query, *self.params)
        except Exception as e:
            await logger.warning(e)
            raise errors.StorageException

        if results is None:
            return notes

        for result in results:
            note = models.Note()
            note.id = str(result["id"])
            note.title = result["title"]
            note.data = result["data"]
            notes.append(note)

        return notes
Exemplo n.º 3
0
def update_note():

    data = request.get_json()

    if models.Note.validate_update(data):

        note_to_update = get_note_by_id(data['id'])

        new_title = data['title'] if 'title' in data else note_to_update.title
        new_content = data[
            'content'] if 'content' in data else note_to_update.content

        if note_to_update is None:
            return jsonify(NO_NOTE_ERROR)
        else:
            updated_note = models.Note(id=note_to_update.id,
                                       title=new_title,
                                       content=new_content,
                                       created=note_to_update.created,
                                       version=note_to_update.version + 1)
            session.add(updated_note)
            session.commit()

        return jsonify(updated_note.serialize)

    else:
        return jsonify(UPDATE_ERROR), 400
Exemplo n.º 4
0
    def setup_method(self):
        flush_db(session)

        note1 = models.Note(title='test_note1', content='test_content1')

        session.add(note1)
        session.commit()
        TestDelete.note_id = note1.id
Exemplo n.º 5
0
def add_note():

    data = request.get_json()

    if models.Note.validate_create(data):
        new_note = models.Note(title=data['title'], content=data['content'])
        session.add(new_note)
        session.commit()
        return jsonify(new_note.serialize), 201
    else:
        return jsonify(CREATE_ERROR), 400
Exemplo n.º 6
0
    def note_create(self, new_resource):
        user = endpoints.get_current_user()
        if user is None:
            raise endpoints.UnauthorizedException()

        note = models.Note(parent=ndb.Key("User", user.nickname()),
                           title=new_resource.title,
                           content=new_resource.content)
        note.put()
        new_resource.key = note.key.urlsafe()
        new_resource.date_created = note.date_created
        return new_resource
Exemplo n.º 7
0
def note_create():
    """
    Note create api endpoint. Create a new note
    """

    form = forms.NoteForm(request.form)

    if form.validate():
        note = models.Note()
        form.populate_obj(note)
        note.put()

        return jsonify(note.to_data())

    return jsonify(errors=form.errors)
Exemplo n.º 8
0
def admin_entry_create():
    if request.method == "POST":
        note = models.Note()
        note.title = request.form.get('title', '')
        note.content = request.form.get('content')

        # associate note to currently logged in user
        note.user = current_user.get_mongo_doc()
        note.save()

        return redirect('/notes/%s' % note.id)

    else:
        template_data = {'title': 'Create new note', 'note': None}
        return render_template('/note_edit.html', **template_data)
Exemplo n.º 9
0
def generate_data():
    categories = []

    for i in range(1, 11):
        categories.append(models.Category(name='Category-%s' % i))

    for i in range(1, 101):
        models.db.session.add(
            models.Note(
                name='Note-%s' % i,
                private=random.choice((True, False)),
                share_count=random.randint(0, 9999),
                category=random.choice(categories),
            ))

    models.db.session.commit()
Exemplo n.º 10
0
    def setup_method(self):
        flush_db(session)

        # Add a note with a creation date in a past to check
        # if properties Note.created and Note.modified
        # are filled in correctly

        test_date = datetime(2018, 5, 14)

        note1 = models.Note(title='test_note1',
                            content='test_content1',
                            created=test_date,
                            modified=test_date)

        session.add(note1)
        session.commit()
        TestUpdate.note_id = note1.id
Exemplo n.º 11
0
    def update_parsed_message(self):
        logging.debug('update parsed message method called')
        logging.debug('Request: %s' % self.request)
        message = Message.get_by_id(long(self.request.get('id')))

        p = models.Person()
        namespace = "rhok1.com"
        unique_id = uuid.uuid1()
        p.person_record_id = '%s/person.%s' % (namespace, unique_id)
        p.author_name = message.source_phone_number

        for attr in models.PFIF_13_PERSON_ATTRS:
            if self.request.get(attr):
                logging.debug('%s: %s' % (attr, self.request.get(attr)))
                setattr(p, attr, self.request.get(attr))

        for attr in models.PFIF_13_NOTE_ATTRS:
            if self.request.get(attr):
                if not p.notes:
                    n = models.Note()
                    n.note_record_id = '%s/note.%s' % (namespace, unique_id)
                    n.author_name = message.source_phone_number
                    n.source_date = convert_datetime_to_rfc3339(
                        message.message_timestamp)
                    n.text = "raw message text received : " + message.message
                    p.notes.append(n)
                setattr(p.notes[0], attr, self.request.get(attr))

        logging.debug('###### Here')
        message.status_timestamp = datetime.datetime.now()
        errorparsing = False
        if self.request.get('parseable').lower() == 'false':
            message.status = 'UNPARSEABLE'
            errorparsing = True
        else:
            upload_to_personfinder(p)
            message.status = 'SENT'

        logging.debug('Person: %s' % repr(p))
        logging.debug('Message: %s' % message)
        message.put()
        atomic_add_to_counter(counter_name_new, -1)
        return errorparsing
Exemplo n.º 12
0
async def notes_create(self: Controller, params: Dict[str,
                                                      Any]) -> Dict[str, Any]:

    try:
        validator.validate("notes_create", params)
    except validator.ValidationError:
        raise errors.InvalidParams

    note = models.Note(id_=uuid.generate(),
                       title=params["title"],
                       data=params["data"])

    try:
        await self.storage.store_note(note)
    except errors.StorageException:
        raise errors.InternalError

    result = {"id": note.id}

    return result
Exemplo n.º 13
0
    async def fetch_one(self) -> models.Note:

        note = models.Note()

        query = "SELECT id, title, data FROM notes"

        query = self._format_query(query)

        try:
            result = await self.storage.performer().fetchrow(query, *self.params)
        except Exception as e:
            await logger.warning(e)
            raise errors.StorageException

        if result is None:
            return note

        note.id = str(result["id"])
        note.title = result["title"]
        note.data = result["data"]

        return note
Exemplo n.º 14
0
def post_notes(db: Session, note: schemas.Note):
    db_note = models.Note(title=note.title, content=note.content)
    db.add(db_note)
    db.commit()
    db.refresh(db_note)
    return db_note