本文整理汇总了Python中models.Note.save方法的典型用法代码示例。如果您正苦于以下问题:Python Note.save方法的具体用法?Python Note.save怎么用?Python Note.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Note
的用法示例。
在下文中一共展示了Note.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def index(request):
if request.GET:
new_data = ''
data = request.GET.get('text')
if 'shifr' == request.GET.get('command'):
step = int(request.GET.get('code'))
else:
step = -int(request.GET.get('code'))
capital_letters = [chr(letter) for letter in range(65, 91)]
capital_letters_step = [capital_letters[(i+step+26) % 26] for i in range(0, 26)]
low_letters = [chr(letter) for letter in range(97, 123)]
low_letters_step = [low_letters[(i+step+26) % 26] for i in range(0, 26)]
for letter in data:
if letter in capital_letters:
new_data += capital_letters_step[(ord(letter)-65) % 26]
elif letter in low_letters:
new_data += low_letters_step[(ord(letter)-97) % 26]
else:
new_data += letter
note = Note(shifr=request.GET.get('text'), ROT=int(request.GET.get('code')), label=request.GET.get('label'))
note.save()
return HttpResponse(JsonResponse({'text': new_data }))
else:
form = ShifrForm()
context = {
'form': form,
}
return render(request, 'content.html', context)
示例2: finish_plan_api
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def finish_plan_api():
pk = flask.request.form.get('pk')
user_id = flask.session['user_id']
plan = Plan.fetchone(pk=pk)
if not plan:
raise error.PlanNoteFound()
plan_log = PlanLog()
plan_log.user_id = user_id
plan_log.plan_id = plan.pk
plan_log.create_at = datetime.now()
plan_log.update_at = datetime.now()
plan_log.is_enable = 1
plan_log.save(commit=False)
for item in plan.plan_items:
note = Note()
note.kind_id = item.kind.pk
note.user_id = user_id
note.quantity = item.quantity
note.plan_log_id = plan_log.pk
note.create_at = datetime.now()
note.update_at = datetime.now()
note.save()
return {'pk': pk}
示例3: handle_uploaded_json_file
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def handle_uploaded_json_file(f, user):
def convert_date(str_date):
new_str = str_date.replace('+00:00','')
try:
new_dt = datetime.strptime(new_str, '%Y-%m-%d %H:%M:%S.%f')
except ValueError:
new_dt = datetime.strptime(new_str, '%Y-%m-%d %H:%M:%S')
return new_dt
with open('notes.json', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
f.close()
with open('notes.json', 'r') as fh:
json_data = json.load(fh)
fh.close()
version, notes = json_data
# for user in User.objects.all():
# if not Folder.)objects.filter(user = user, name = "Main").exists():
# folder = Folder(name="Main", user = user)
# folder.save()
# if not Folder.objects.filter(user = user, name = ")Trash").exists():
# folder = Folder(name="Trash", user = u)ser)
# folder.save()
for note in notes:
created_at = convert_date(note['created_at'])
title = note['title']
username = note['user']
# TODO: If user is blank we need to assign to a default user. For now just skip.
# Its technically a database integrity violation anyway.
if username is None: continue
user = User.objects.get(username = username)
if not Note.objects.filter(title = title,
created_at = created_at).exists():
new_note = Note()
new_note.title = title
new_note.created_at = created_at
new_note.modified_at = convert_date(note['modified_at'])
new_note.note_type = note['post_type']
new_note.note = note['note']
foldr = note['folder']
try:
folder = Folder.objects.get(name = foldr, user = user)
except Folder.DoesNotExist:
folder = Folder(name = foldr, user = user)
folder.save()
new_note.folder = folder
new_note.user = user
new_note.save()
示例4: note_add
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def note_add(request, event_id):
event = get_object_or_404(Event, pk=event_id)
if request.method == 'POST': # If the form has been submitted...
form = NoteForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
note = Note(event=event, user=request.user, note = form.cleaned_data['note'])
note.save()
messages.success(request, _("Saved note"))
return HttpResponseRedirect(reverse('event', args=[event.id]))
示例5: add_note
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def add_note(self, message, user):
if message:
note = Note(activity=self.object)
note.message = message
note.user = user
note.save()
messages.success(self.request, 'Note added successfully.')
return True
else:
messages.error(self.request, 'Message cannot be empty.')
return False
示例6: save
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def save(self, account):
cd = self.cleaned_data
note = Note(
amount=cd['amount'],
timestamp=cd['timestamp'],
description=cd['description'],
category=cd['category'],
account=account
)
note.save()
account.balance = account.balance + cd['amount']
account.save()
示例7: createNote
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def createNote(request):
username = request.POST['username']
note = request.POST['note']
date_time = helpers.get_datetime(note)
newNote = Note(user=username, text_body=note, time=date_time)# TODO: START and EXPIRATION date objects
newNote.save()
# SHOULD REDIRECT TO LOGIN PAGE
return redirect("index")
示例8: test_book_autodelete
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def test_book_autodelete(self):
note1 = Note(text='text')
note1.save()
note2 = Note(text='text')
note2.save()
book = Book(title='title')
book.save()
book.notes.add(*[note1, note2])
note1.delete()
self.assertTrue(Book.objects.all())
note2.delete()
self.assertFalse(Book.objects.all())
示例9: gen
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def gen(count, dicts, get_string_function):
user = User.objects.all()[0]
date_now = now()
total = count
while 0 < count:
stdout.write("%d\r" % (total - count))
stdout.flush()
count -= 1
note = Note()
note.user = user
note.pub_date = date_now
note.title = get_string_function(dicts, randrange(20, 100))
note.body = get_string_function(dicts, randrange(500, 1000))
note.save()
示例10: test_evaluated_queryset_as_argument
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def test_evaluated_queryset_as_argument(self):
"#13227 -- If a queryset is already evaluated, it can still be used as a query arg"
n = Note(note='Test1', misc='misc')
n.save()
e = ExtraInfo(info='good', note=n)
e.save()
n_list = Note.objects.all()
# Evaluate the Note queryset, populating the query cache
list(n_list)
# Use the note queryset in a query, and evalute
# that query in a way that involves cloning.
try:
self.assertEquals(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
except:
self.fail('Query should be clonable')
示例11: create
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def create(request):
# TODO Receive a `timestamp` parameter and return all the
# notes that is modified after `timestamp`. Because
# in rare cases uses open the same page multiple times
# , and if we just return the note just added we would
# miss some notes submitted in other pages.
if request.method == 'POST':
form = NewNoteForm(request.POST)
if form.is_valid():
note = Note(author=request.user,
content=form.cleaned_data['content'])
note.save()
data = [note.get_serializable()]
return HttpResponse(simplejson.dumps(data),
mimetype='application/json')
return HttpResponse('false', mimetype='application/json')
示例12: _ajax
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def _ajax(request):
"""Wrapper"""
if not request.is_ajax():
return {'status': 403}
a = request.POST.get('a')
if a not in ['move', 'edit', 'delete', 'new']:
return {'status': 403}
if a in ['move', 'edit', 'delete']:
n = request.POST.get('note')
id = int(n[5:])
note = get_object_or_404(Note, pk=id)
try:
note = Note.objects.get(pk=id)
except ObjectDoesNotExist:
return {'status': 403}
if a in ['edit', 'new']:
content = request.POST.get('content')
if a == 'move':
st = request.POST.get('section')
if st not in STATES:
return {'status': 403}
note.state = st
elif a == 'delete':
note.delete()
return {'status': 200}
elif a == 'new':
p = request.POST.get('project')
p = get_object_or_404(Project, id=p)
note = Note(
content=content,
author=request.user,
project=p)
note.save()
return {
'status': 200,
'content': _note(note)
}
else:
note.content = content
note.save()
return {'status': 200}
示例13: create_note_api
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def create_note_api():
kind_id = flask.request.form.get('kind_id')
quantity = flask.request.form.get('quantity')
content = flask.request.form.get('content')
user_id = int(flask.session['user_id'])
# Check kind owner
note_kind = NoteKind.fetchone(pk=kind_id, user_id=user_id)
if not note_kind:
raise error.KindNotExistError()
note = Note()
note.kind_id = kind_id
note.user_id = user_id
note.content = content
note.quantity = quantity
note.save()
return {'pk': note.pk}
示例14: add_note
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def add_note():
"""Add a note."""
form = ArticleForm()
if request.method == 'POST':
if form.validate_on_submit():
# Get the right number - the article ID
number = 1
notes = Note.all().order('-number')
if notes.count() > 0:
number = notes[0].number + 1
note = Note(
number=number,
title=form.title.data,
content=form.content.data,
tags=form.tags.data,
)
note.save()
return redirect(note.get_absolute_url())
action_url = url_for('add_note')
return render_template('add_note.html', form=form, action_url=action_url)
示例15: new_note
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import save [as 别名]
def new_note(request):
if request.method == 'GET':
context = {'suppress_menu':True}
return render(request, 'cloud_notes/new.html', context)
elif request.method == 'POST':
if "cancel" in request.POST:
return redirect('cloud_notes.views.list')
else:
form = NoteForm(request.POST)
context = {'form':form}
if form.is_valid():
# do stuff
# ...
if 'notes_folder' in request.session:
fldr = Folder.objects.get(pk=request.session['notes_folder'], user=request.user)
else:
fldr = Folder.objects.get(name="Main", user=request.user)
# Don't allow user to inadvertently create note in Trash
if fldr.name == 'Trash':
fldr = Folder.objects.get(name="Main", user=request.user)
obj = Note()
obj.title = form.cleaned_data['title']
obj.note = form.cleaned_data['note']
obj.post_type = 'note'
obj.created_at = datetime.utcnow()
obj.modified_at = datetime.utcnow()
obj.user = request.user
obj.folder = fldr
obj.save()
return redirect('cloud_notes.views.list')
else:
print form.errors
return render(request, 'cloud_notes/new.html', context)