Ejemplo n.º 1
0
    def post(self):
        user = users.get_current_user()
        jsonNotes = self.request.get("notes")

        if user and jsonNotes:
            notes = simplejson.loads(jsonNotes)
            for note in notes:
                # TODO: Validate the note

                pk = None
                if note.has_key("pk"):
                    pk = note["pk"]

                if pk is not None:
                    logging.error("Has primary key: %s" % pk)
                    n = Note().get_by_id(int(pk))
                else:
                    logging.error("New note")
                    # This is a new note.
                    n = Note()

                n.user = user
                n.text = note["text"]
                n.left = int(note["left"])
                n.top = int(note["top"])
                n.width = int(note["width"])
                n.height = int(note["height"])
                n.put()
Ejemplo n.º 2
0
    def post(self):
        user = users.get_current_user()
        jsonNotes = self.request.get('notes')

        if user and jsonNotes:
            notes = simplejson.loads(jsonNotes)
            for note in notes:
                # TODO: Validate the note

                pk = None
                if note.has_key('pk'):
                    pk = note['pk']

                if pk is not None:
                    logging.error("Has primary key: %s" % pk)
                    n = Note().get_by_id(int(pk))
                else:
                    logging.error("New note")
                    # This is a new note.
                    n = Note()

                n.user = user
                n.text = note['text']
                n.left = int(note['left'])
                n.top = int(note['top'])
                n.width = int(note['width'])
                n.height = int(note['height'])
                n.put()
def import_notes():
    notes = load_json("notes.json")
    notebooks = Notebook.objects.all()
    notebooksl = len(notebooks) - 1
    tags = Tag.objects.all()
    tagsl = len(tags) - 1
    for note in notes:
        new_note = Note()
        new_note.title = note['title']
        new_note.text = note['text']
        new_note.user = USER
        new_note.notebook = notebooks[randint(0, notebooksl)]
        amt_of_tags = randint(0, tagsl)
        new_note.save()
        for i in range(0, amt_of_tags):
            new_note.tags.add(tags[randint(0, tagsl)])
        new_note.save()
    print("Imported Notes.")
Ejemplo n.º 4
0
def edit(request, id=None):
    if request.method == 'GET':
        n = {}
        if id:
            n = Note.objects.get(pk=id)
        return render(request, 'notes/edit.html', {
            "note" : n
        })
    elif request.method == 'POST':
        print('POST')
        print(request.POST)
        pk = request.POST['pk']
        text = request.POST['text']
        if pk:
            n = Note.objects.get(pk=pk)
            #TODO: error handling
        else:
            n = Note(text=text)
        n.text = text
        n.save()
        return HttpResponseRedirect('/')