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


Python Folder.save方法代码示例

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


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

示例1: main

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
def main(request, rest_of_address):
	address = Address(rest_of_address)
	#import pdb; pdb.set_trace()
	if not address.folder:
		return render_to_response('documents_folders/error.html', {'error':'no_folder', 'current_folder_path': address.folder_path})
	if address.file_path and not address.file:
		return render_to_response('documents_folders/error.html', {'error':'no_file', 'current_folder': address.folder_path, 'open_file':address.file_path})
	if 'submit_comment' in request.POST: 
		add_comment(request, address)
	#Create new folder
	if 'file' in request.FILES:
		upload_file(request, address.folder.id)
	if 'new_folder_name' in request.POST:
		folder_name = str(request.POST.get('new_folder_name'))
		if folder_name.strip():
			p = Folder(name = folder_name, parent_folder = address.folder.id, folder_path = address.folder_path+'/'+folder_name)
			p.save()
	#Remove folder and all sub-folders of that folder
	for folder_id in [a for a, b in request.POST.iteritems() if b == 'Delete']:
		remove_folder(folder_id)
	sub_folders = Folder.objects.filter(parent_folder=address.folder.id)
	sub_files = File.objects.filter(parent_folder = address.folder.id)
	relevant_comments = Comment.objects.filter(attached_to_type = address.type, attached_to_id = address.id)
	try:
		parent_folder = Folder.objects.get(id = address.folder.parent_folder)
	except:
		parent_folder = None
	return render_to_response('documents_folders/blah.html', {'relevant_comments':relevant_comments, 'sub_folders': sub_folders, 'current_folder_path': address.folder.folder_path, 'parent_folder': parent_folder, 'sub_files':sub_files, 'open_file':address.file_path, 'current_path': '/documents/'+rest_of_address}, context_instance=RequestContext(request))
开发者ID:oliverrourke,项目名称:Macademia,代码行数:30,代码来源:views.py

示例2: test_model_folder

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_model_folder(self):
     """Test Folder Model"""
     obj = Folder(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:9,代码来源:tests.py

示例3: test_get

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
    def test_get(self):
        """A logged in user ask to move a valid favorite."""
        godzilla = self.user('godzilla')
        self.client.login(username='godzilla', password='godzilla')
        dummy = DummyModel()
        dummy.save()
        favorite = Favorite.objects.create_favorite(dummy, godzilla)
        folders = []
        for i in range(10):
            folder = Folder(name="folder-%s" % i, user=godzilla)
            folder.save()
            folders.append(folder)
        target_url = reverse('favorites:favorite_move',
                             kwargs = {
    'object_id': favorite.pk,
})
        response = self.client.get(target_url)
        self.assertEquals(response.status_code, 200)

        instance = response.context['favorite']
        self.assertEquals(instance.pk, favorite.pk)
        favorite.delete()
        godzilla.delete()
        for folder in folders:
            folder.delete()
        dummy.delete()
开发者ID:HARISARMA,项目名称:django-favorites,代码行数:28,代码来源:tests.py

示例4: folders

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
def folders(request):
    folders = Folder.objects.filter(user=request.user)
    context = {'folders':folders}
    if request.method == 'POST':
        # changing to a different folder
        if "change_folder" in request.POST:
            request.session['notes_folder'] = request.POST['folder']
            # If we are changing folders we don't 
            # want to keep to what page we were on in
            # the other folder.
            if 'page' in request.session:
                del request.session['page']
            return redirect('cloud_notes.views.list')
        if "create_folder" in request.POST:
            form = NewFolderForm(request.POST)
            if form.is_valid():
                folder_name = form.cleaned_data['folder']
                folder = Folder(name = folder_name)
                folder.save()
                return redirect('cloud_notes.views.list')
            else:
                context['form'] = form
                return render(request, 'cloud_notes/folders.html', context)
    else:
        return render(request, 'cloud_notes/folders.html', context)
开发者ID:Burrito-Bazooka,项目名称:logos-v2,代码行数:27,代码来源:views.py

示例5: handle_uploaded_json_file

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

示例6: test_model_document

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_model_document(self):
     """Test Document Model"""
     folder = Folder(name='test')
     folder.save()
     obj = Document(title='test', folder=folder)
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:11,代码来源:tests.py

示例7: test_model_file

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_model_file(self):
     """Test File Model"""
     folder = Folder(name='test')
     folder.save()
     obj = File(name='test', folder=folder)
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:11,代码来源:tests.py

示例8: test_model_weblink

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_model_weblink(self):
     """Test WebLink Model"""
     folder = Folder(name='test')
     folder.save()
     obj = WebLink(title='test', folder=folder, url='test')
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:11,代码来源:tests.py

示例9: test_login_required

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_login_required(self):
     """User should be logged it to delete an object."""
     godzilla = self.user('godzilla')
     folder = Folder(name='japan', user=godzilla)
     folder.save()
     response = self.client.get(reverse('favorites:folder_update', args=(folder.pk,)))
     self.assertEquals(response.status_code, 302)
     folder.delete()
     godzilla.delete()
开发者ID:HARISARMA,项目名称:django-favorites,代码行数:11,代码来源:tests.py

示例10: RPC__Folder__getRoot

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
    def RPC__Folder__getRoot(self):
        """Return the main folder for the current user ("My folders"). """
        try:
            folder = Folder.objects.get(user=self.user, parent=None)
        except Folder.DoesNotExist:
            folder = Folder(user=self.user, name="My folders")
            folder.save()

        self.return_api_result({'uuid': folder.uuid, 'name': folder.name})
开发者ID:certik,项目名称:femhub-online-lab,代码行数:11,代码来源:handlers.py

示例11: create_folder

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
def create_folder(user, folder_name):
    """
    Args:
        user: django.contrib.auth.models.User
    returns:
        models.Folder
    """
    f = Folder(name=folder_name, user=user, times_used=0)
    f.save()
    return f
开发者ID:leifos,项目名称:dragndrop,代码行数:12,代码来源:folders.py

示例12: test_post

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_post(self):
     """Submit a delete form with good credentials. Returns a redirect."""
     godzilla = self.user('godzilla')
     folder = Folder(name='japan', user=godzilla)
     folder.save()
     self.client.login(username='godzilla', password='godzilla')
     response = self.client.post(reverse('favorites:folder_delete', args=(folder.pk,)), {'object_id': folder.pk})
     self.assertEquals(response.status_code, 302)
     self.assertEquals(Folder.objects.filter(user=godzilla).count(), 0)
     godzilla.delete()
开发者ID:HARISARMA,项目名称:django-favorites,代码行数:12,代码来源:tests.py

示例13: test_invalid_permission

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_invalid_permission(self):
     """Try to delete a folder owned by someone else. Returns a 403."""
     godzilla = self.user('godzilla')
     folder = Folder(name='japan', user=godzilla)
     folder.save()
     leviathan = self.user('leviathan')
     self.client.login(username='leviathan', password='leviathan')
     response = self.client.post(reverse('favorites:folder_delete', args=(folder.pk,)), {'object_id': folder.pk})
     self.assertEquals(response.status_code, 403)
     godzilla.delete()
     leviathan.delete()
开发者ID:HARISARMA,项目名称:django-favorites,代码行数:13,代码来源:tests.py

示例14: create_folder

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
def create_folder(request, internal=False):
    folder_form = FolderForm(request.POST or None)
    if folder_form is not None and folder_form.is_valid():
        title = folder_form.cleaned_data['title']
        owner = Searcher.objects.filter(user_profile=request.user)[0]
        new_folder = Folder(title=title, owner=owner)
        new_folder.save()
    else:
        print "error"
    if internal:
        return new_folder
开发者ID:westonnovelli,项目名称:openbar,代码行数:13,代码来源:views.py

示例15: test_invalid_permission_on_favorite

# 需要导入模块: from models import Folder [as 别名]
# 或者: from models.Folder import save [as 别名]
 def test_invalid_permission_on_favorite(self):
     """User should own the folder to delete it. Returns a 403."""
     godzilla = self.user('godzilla')
     leviathan = self.user('leviathan')
     self.client.login(username='godzilla', password='godzilla')
     folder = Folder(name='japan', user=leviathan)
     folder.save()
     response = self.client.get(reverse('favorites:folder_update', args=(folder.pk,)))
     self.assertEquals(response.status_code, 403)
     godzilla.delete()
     leviathan.delete()
     folder.delete()
开发者ID:HARISARMA,项目名称:django-favorites,代码行数:14,代码来源:tests.py


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