Пример #1
0
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 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"更新数据库完毕!")
Пример #3
0
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)
Пример #4
0
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()