当前位置: 首页>>代码示例>>Python>>正文


Python Record.save方法代码示例

本文整理汇总了Python中models.Record.save方法的典型用法代码示例。如果您正苦于以下问题:Python Record.save方法的具体用法?Python Record.save怎么用?Python Record.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Record的用法示例。


在下文中一共展示了Record.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rest

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def rest(request):
	admins_email = ['[email protected]']
	content_to_sender = u"Dear %s,\n\nWe have received your application.Please do NOT reply this email directly.\n\nThanks,\nTech Team"
	content_to_admin = u"Received an application from %s %s at %s"
	receive_time_str = strftime("%H:%M:%S %Y-%m-%d", localtime())
	if request.META.has_key('CONTENT_TYPE'):
		info = request.META['CONTENT_TYPE'] 
		if info == 'application/json' and request.method == 'POST':
			data = json.loads(request.body) 
			form = RecordForm(data)

			if form.is_valid():
				r = Record(email = form.cleaned_data['email'],
							first_name = form.cleaned_data['first_name'],
							last_name = form.cleaned_data['last_name'],
							contact_number = form.cleaned_data['contact_number'],
							title = form.cleaned_data['title'],
							content = form.cleaned_data['content'],
							link = form.cleaned_data['link'])
				r.save()

				send_mail(u'Thanks for your application',
							content_to_sender % data['last_name'],
							'[email protected]',
							[data['email']])
				send_mail(u'Application Received from %s' % data['email'],
							content_to_admin % (data['last_name'],data['first_name'],receive_time_str),
							'[email protected]',
							admins_email)
				return HttpResponse('save successful')
		return HttpResponse('data invalid')	
	else:
		return HttpResponse('Please verify Header info')
开发者ID:fl0wjacky,项目名称:rest_test,代码行数:35,代码来源:views.py

示例2: showQuestion

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def showQuestion(request):
    q=Question.objects.filter(id=request.session['qid'])[0]
    #u=User.objects.filter(id=request.session['uid'])[0]
    #request.session['qid']=q.id
     #记录日志
    record=Record()
    record.uid=request.session['uid']
    record.qid=request.session['qid']
    record.result=True
    record.save()

    request.session['answer']=q.answer
    request.session['explain']=q.qexplain

    # 显示最新的和最热的几条讨论
    discuss_new=Discuss.objects.filter(qid=request.session['qid']).order_by('-date')[0:10]
    discuss_hot=Discuss.objects.filter(qid=request.session['qid']).order_by('-support')[0:10]

    #增加一个随机验证码
    if random.randint(1,80)==2:
        request.session['next_verify']=2
    #不同的题型,出现相应不同的模板
    return render_to_response('question_with_base.html', {'q' : q,\
            'includeQuestion':'question%d.html'%(q.qtype),'user':request.session,\
            'discuss_new':discuss_new,'discuss_hot':discuss_hot} )
开发者ID:dhs789520,项目名称:master2015,代码行数:27,代码来源:views-backup.py

示例3: gong

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def gong(request):
    user = "@%s" % request.POST.get("user_name", "somebody")
    reason = request.POST.get("text", "Gonged stuff!")

    slack_message('slack/gonged.slack', {
        'user': user,
        'reason': reason
    })

    attachments = [
        {
            'author_name': user,
            'title': reason,
            'image_url': 'https://curriculum.code.org/images/gong.gif',
            'color': '#00adbc'
        }
    ]
    payload = {
        "response_type": "in_channel",
        "attachments": attachments,
    }

    record = Record(user=user, reason=reason)
    record.save()

    return Response(payload, content_type='application/json')
开发者ID:mrjoshida,项目名称:curriculumbuilder,代码行数:28,代码来源:views.py

示例4: add_record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def add_record(release):
    from models import Record, Artist, Track
    release_discogs_id = release.id
    try:
        # Check if we already have this album
        existing = Record.objects.get(discogs_id=release_discogs_id)
        return existing
    except Record.DoesNotExist:
        # Process record
        record_title = release.title
        if (len(record_title.split('- '))>1):
            record_title = record_title.split('- ')[1]
        record = Record(discogs_id = release_discogs_id, title = record_title, year = release.year, thumb = release.thumb, notes = release.notes)
        record.save()

        # Process artists
        for release_artist in release.artists:
            artist = Artist(discogs_id=release_artist.id, name=release_artist.name)
            artist.save()
            record.artists.add(artist)

        # Process tracklist
        for release_track in release.tracklist:
            track = Track()
            track.position = release_track.position
            track.title = release_track.title
            track.duration = release_track.duration
            track.save()
            record.tracklist.add(track)

        record.save()
        return record
开发者ID:chriswait,项目名称:Record-Collection,代码行数:34,代码来源:discogs.py

示例5: update

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def update(POST):
    player_one = Player.objects.get(pk=int(POST['player_one']))
    player_one_score = int(POST['player_one_score'])
    player_two = Player.objects.get(pk=int(POST['player_two']))
    player_two_score = int(POST['player_two_score'])

    record = Record(date=datetime.datetime.now(), player_one_id=player_one.id, player_one_score=player_one_score, player_two_id=player_two.id, player_two_score=player_two_score)
    record.save()

    if player_one.ELO > player_two.ELO:
        expected_one = get_Expected(player_one.ELO, player_two.ELO)
    else:
        expected_one = 1 - get_Expected(player_two.ELO, player_one.ELO)

    update_player(player_one, player_one_score, player_two, player_two_score, expected_one)
    update_player(player_two, player_two_score, player_one, player_one_score, 1-expected_one)
开发者ID:SteveXian,项目名称:ELO-Ranking-Server,代码行数:18,代码来源:elo.py

示例6: add_record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def add_record(request):
	var = request.POST
	data = simplejson.loads(var['data'])
	date = data['date']
	tags = data['tags']
	new_record = Record()
	new_record.amount = float(data['amount']) 	
	new_record.occurrence_time = datetime(int(date['year']),int(date['month']),int(date['day']))
	new_record.detail = data['comment']	
	new_record.save()	
	for tag_id in tags:
		maping = Record_tag_maping()
		maping.record_id = new_record.id
		maping.tag_id = int(tag_id)
		maping.save()
	result = ReturnedData().to_json_string()
	return HttpResponse(result);
开发者ID:zhangwentao,项目名称:accountbook,代码行数:19,代码来源:views.py

示例7: import_csv

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def import_csv(request):
    ret={}
    import csv
    reader = csv.reader(open('programming-sample.tab', 'rb'))
    for index,row in enumerate(reader):
        if index >0:
            m=int(row[1])
            d=int(row[2])
            if m>12:
                my_date= datetime.date(2012,m-12,d)
            else:
                my_date= datetime.date(2011,m,d)
                
            r=Record(body=row[3],title=row[0], date=my_date)
            r.save()
        #~ print 'Month: ' + row[1]
        #~ print 'Day: ' + row[2]
    
    return render_to_response('records/importing.html', ret)
开发者ID:codigodaniel,项目名称:devotionals-try,代码行数:21,代码来源:views.py

示例8: process_record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
 def process_record(record):
     id = record.getAttribute('id')
     refid = record.getAttribute('refid')
     source = record.getAttribute('source')
     values = []
     del record_relations[:]
     for child in elementNodes(record.childNodes):
         values.extend(process_element_set(child))
     # TODO: find existing record to replace
     record = Record()
     record.name = get_first_value(values, lambda v: v.field.name == 'source' and
                                   v.refinement.startswith('refid')) \
                   or get_first_value(values, lambda v: v.field.name == 'title')
     record.save(force_insert=True)
     record.fieldvalue_set.add(*values)
     record.fieldvalue_set.create(field=dc_identifier, value=id)
     # Temporary properties to link records together
     record._core4_ids = (id, refid)
     record._core4_parent = record_relations and record_relations[0] or None
     return record
开发者ID:Blanko2,项目名称:vic-mdid,代码行数:22,代码来源:vracore4import.py

示例9: check_ip

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def check_ip(request):
    try:
        exp = Exp.objects(onlyKey=1)
    except DoesNotExist:
        exp = Exp()
        exp.save()

    _ip = request.POST["IP"]
    try:
        record = Record.objects(ip=_ip)
    except DoesNotExist:
        exp.count += 1
        exp.save()
        record = Record(ip=_ip, seqNo=exp.count)
        record.save()

    if record.time_end is None:
        return HttpResponse(status=200)
    else:
        return HttpResponse(status=400)
开发者ID:noobxinyu,项目名称:lionet_fyp,代码行数:22,代码来源:views.py

示例10: acquisition

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def acquisition(request):
    record_data = {}
    record = None

    if request.GET.get('isbn'):
        isbn = request.GET.get('isbn')
        if isbnpy.isValid(isbn):
            url = 'http://openlibrary.org/api/volumes/brief/json/isbn:' + isbn
            response = urllib2.urlopen(url)
            # response = urllib2.urlopen('http://127.0.0.1/json/3.json')
            data = json.load(response)
            if isbnpy.isI10(isbn):
                isbn = isbnpy.convert(isbn)
            if data == {}:
                record_data['isbn13'] = isbn
                record_form = RecordForm(instance=record)
                return render(request, 'acquisition.html', {'data': record_data, 'form': record_form})
            data = data.itervalues().next()['records'].itervalues().next()

            try:
                record = Record.objects.get(isbn13=isbn)
                new_record = False
            except Record.DoesNotExist:
                record = Record(isbn13=isbn)
                new_record = True
                # pp(data)
            if record.book_id:
                book = record.book
            else:
                book = Book()

            book.title = data['data']['title']
            if data['details']['details'].has_key('subtitle'):
                book.subtitle = data['details']['details']['subtitle']
            book.save()

            if data['details']['details'].has_key('pagination'):
                record.pagination = data['data']['pagination']
            elif data['details']['details'].has_key('number_of_pages'):
                record.pagination = str(data['data']['number_of_pages']) + ' p.'

            if data['details']['details'].has_key('physical_format'):
                record.format = data['details']['details']['physical_format']
                if record.format.startswith('electronic'):
                    record.format = 'eBook'
                    # record.openlibrary_url = data['data']['url']

            if data['details']['details'].has_key('weight'):
                record.weight = data['details']['details'].get('weight')
            if data['details']['details'].has_key('physical_dimensions'):
                record.dimensions = data['details']['details'].get('physical_dimensions')

            if data['data'].has_key('classifications'):
                if data['data']['classifications'].has_key('dewey_decimal_class'):
                    record.ddc = data['data']['classifications'].get('dewey_decimal_class')[0]
                if data['data']['classifications'].has_key('lc_classifications'):
                    record.lcc = data['data']['classifications'].get('lc_classifications')[0]

            try:
                record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%B %d, %Y').date()
                record.publication_has_month = True
                record.publication_has_day = True
            except ValueError:
                try:
                    record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%Y').date()
                    record.publication_has_month = False
                    record.publication_has_day = False
                except ValueError:
                    try:
                        record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%B %Y').date()
                        record.publication_has_day = False
                        record.publication_has_month = True
                    except ValueError:
                        record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%m/%d/%Y').date()
                        record.publication_has_day = True
                        record.publication_has_month = True

            if data['data'].has_key('identifiers'):
                if data['data']['identifiers'].has_key('openlibrary'):
                    record.openlibrary_id = data['data']['identifiers']['openlibrary'][0]
                if data['data']['identifiers'].has_key('goodreads'):
                    record.goodreads_id = data['data']['identifiers']['goodreads'][0]
                if data['data']['identifiers'].has_key('librarything'):
                    record.librarything_id = data['data']['identifiers']['librarything'][0]
                if data['data']['identifiers'].has_key('oclc'):
                    record.oclc_id = data['data']['identifiers']['oclc'][0]
                if data['data']['identifiers'].has_key('lccn'):
                    record.lccn_id = data['data']['identifiers']['lccn'][0]

            if data['data'].has_key('by_statement'):
                record.by_statement = data['data'].get('by_statement')

            if data['data'].has_key('notes'):
                record.notes = data['data'].get('notes')

            if data['data'].has_key('excerpts'):
                record.excerpt = data['data'].get('excerpts')[0].get('text')

            record.book = book

#.........这里部分代码省略.........
开发者ID:ratna1234,项目名称:nerp,代码行数:103,代码来源:views.py

示例11: save_acquisition

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def save_acquisition(request):
    if request.POST.get('book').isnumeric():
        book = Book.objects.get(id=request.POST.get('book'))
        new_book = False
    else:
        book = Book(title=request.POST.get('book'))
        new_book = True
    book.subtitle = request.POST.get('subtitle')
    book.save()

    if request.POST.get('isbn'):
        isbn = request.POST.get('isbn')
        if isbnpy.isValid(isbn):
            if isbnpy.isI10(isbn):
                isbn = isbnpy.convert(isbn)
            try:
                record = Record.objects.get(isbn13=isbn)
                new_record = False
            except Record.DoesNotExist:
                record = Record(isbn13=isbn)
                new_record = True
    else:
        if not new_book:
            try:
                record = Record.objects.get(book=book, edition=request.POST.get('book'))
                new_record = False
            except Record.DoesNotExist:
                record = Record(book=book)
                new_record = True
        else:
            record = Record(book=book)
            new_record = True

    record.book = book
    record.format = request.POST.get('format')
    if record.format != 'ebook':
        if new_record:
            record.quantity = request.POST.get('quantity')
        else:
            record.quantity += int(request.POST.get('quantity'))

    record.excerpt = request.POST.get('excerpt')
    record.edition = request.POST.get('edition')
    record.notes = request.POST.get('notes')
    record.ddc = request.POST.get('ddc')
    record.lcc = request.POST.get('lcc')
    record.pagination = request.POST.get('pagination')
    record.format = request.POST.get('format')
    record.type = request.POST.get('type')
    if record.format != 'eBook':
        record.quantity = request.POST.get('quantity')

    record.publication_has_month = False
    record.publication_has_day = False
    if request.POST.get('year'):
        dt = datetime(int(request.POST.get('year')), 1, 1)
        if request.POST.get('month'):
            record.publication_has_month = True
            dt = dt.replace(month=int(request.POST.get('month')))
            if request.POST.get('day'):
                record.publication_has_day = True
                dt = dt.replace(day=int(request.POST.get('day')))
        record.date_of_publication = dt
    else:
        record.date_of_publication = None

    if request.FILES.get('small_cover'):
        record.small_cover = request.FILES.get('small_cover')
    if request.FILES.get('medium_cover'):
        record.medium_cover = request.FILES.get('medium_cover')
    if request.FILES.get('large_cover'):
        record.large_cover = request.FILES.get('large_cover')

    if not record.date_added:
        record.date_added = datetime.today()

    record.save()

    if request.FILES.get('ebook'):
        ebooks = request.FILES.getlist('ebook')
        for ebook in ebooks:
            ebook_file = BookFile(record=record, file=ebook)
            existing_files = record.ebooks(ebook_file.format)
            for existing_file in existing_files:
                existing_file.delete()
            ebook_file.save()

    book.subjects.clear()
    for subject in request.POST.getlist('subjects'):
        if subject.isnumeric():
            book.subjects.add(Subject.objects.get(id=subject))
        else:
            new_subject = Subject(name=subject)
            new_subject.save()
            book.subjects.add(new_subject)

    record.authors.clear()
    for author in request.POST.getlist('authors'):
        if author.isnumeric():
            record.authors.add(Author.objects.get(id=author))
#.........这里部分代码省略.........
开发者ID:ratna1234,项目名称:nerp,代码行数:103,代码来源:views.py

示例12: add_record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]
def add_record(sender, kind, value, text):
    record  = Record(sender=sender, kind=kind, value=value, text=text, date=datetime.now())
    return record.save()
开发者ID:eliane,项目名称:rapidsms,代码行数:5,代码来源:app.py

示例13: record

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import save [as 别名]

#.........这里部分代码省略.........
            title = forms.CharField(widget=DisplayOnlyTextWidget)
            member = forms.BooleanField(required=False)
            shared = forms.BooleanField(required=False)

        fieldvalues_readonly = []
        if customize or context:
            fieldvalues = record.get_fieldvalues(
                owner=request.user, context=context, hidden=True
            ).filter(owner=request.user)
        else:
            fieldvalues = record.get_fieldvalues(hidden=True)

        field_value_formset = modelformset_factory(
            FieldValue,
            form=FieldValueForm,
            fields=FieldValueForm.Meta.fields,
            can_delete=True,
            extra=3
        )

        collection_formset = formset_factory(CollectionForm, extra=0)

        if request.method == 'POST':
            formset = field_value_formset(
                request.POST, request.FILES, queryset=fieldvalues, prefix='fv')
            if not (customize or context):
                collectionformset = collection_formset(
                    request.POST, request.FILES, prefix='c')
            else:
                collectionformset = None
            if formset.is_valid() and (
                    customize or context or collectionformset.is_valid()):

                record.save()

                if not (customize or context):
                    collections = dict(
                        (c['id'], c)
                        for c in collectionformset.cleaned_data
                        if c['id'] in valid_collections
                    )
                    for item in record.collectionitem_set.filter(
                            collection__in=valid_collections):
                        if item.collection_id in collections:
                            if not collections[item.collection_id]['member']:
                                item.delete()
                            elif collections[item.collection_id]['shared'] == \
                                    item.hidden:
                                item.hidden = not item.hidden
                                item.save()
                            del collections[item.collection_id]
                    for coll in collections.values():
                        if coll['member']:
                            CollectionItem.objects.create(
                                record=record,
                                collection_id=coll['id'],
                                hidden=not coll['shared']
                            )

                instances = formset.save(commit=False)
                # Explicitly remove deleted objects
                for instance in formset.deleted_objects:
                    instance.delete()
                o1 = fieldvalues and max(v.order for v in fieldvalues) or 0
                o2 = instances and max(v.order for v in instances) or 0
                order = max(o1, o2, 0)
开发者ID:hanleybrand,项目名称:rooibos,代码行数:70,代码来源:views.py


注:本文中的models.Record.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。