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


Python Note.user方法代码示例

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


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

示例1: handle_uploaded_json_file

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [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()
开发者ID:Burrito-Bazooka,项目名称:logos-v2,代码行数:60,代码来源:views.py

示例2: add_note

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [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
开发者ID:cs130-tec-tracking,项目名称:cs130-tec-tracking,代码行数:13,代码来源:views.py

示例3: gen

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [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()
开发者ID:lxdiyun,项目名称:haystack_demo,代码行数:17,代码来源:generate.py

示例4: post

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [as 别名]
    def post(self):
        user = self.user
        if user:
            content = self.request.get('note')
            note = Note()
            note.content = content
            note.user = user.key
            note.put()

            # show confirma   tion of successful post creation
            template_values = {
                'message': 'Note created successfully'
            }

            templates.render_page("notes/created", template_values, self)
        else:
            # error about login
            return

        return
开发者ID:tominovak33,项目名称:notes-webapp,代码行数:22,代码来源:handlers.py

示例5: note

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [as 别名]
def note():
    """
    Save a note related to a query.
    """

    logger.debug("NOTE endpoint called")

    user = current_user
    content = request.form['content']
    query_id = request.form['query_id']

    # save note
    tmp = Note()
    tmp.user = user
    tmp.content = content
    tmp.query_id = query_id

    db.session.add(tmp)
    db.session.commit()

    return redirect('/admin/queryview/', code=302)
开发者ID:Jablet,项目名称:odac-ford-housing,代码行数:23,代码来源:views.py

示例6: new_note

# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import user [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)
开发者ID:Burrito-Bazooka,项目名称:logos-v2,代码行数:40,代码来源:views.py


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