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


Python models.Folder类代码示例

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


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

示例1: main

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,代码行数:28,代码来源:views.py

示例2: test_model_folder

 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,代码行数:7,代码来源:tests.py

示例3: create_vin

def create_vin(request):
	topics = ['NBA']
	for fld in topics:
		logging.info('Entra en bucle para %s' % fld)
		directory = "media/%s" % fld
		root = Folder.create(fld,request.user.profile,None,'/media/example_folder.png')
		root.save()
		for serie in os.listdir(directory):
			logging.info('Entra en bucle series para %s' % serie)
			if not serie.startswith('.'):
				s = Folder.create(serie,request.user.profile,root,None)
				s.pic = None #TODO revisar codigo inutil
				for season in os.listdir(directory+'/'+serie):
					if not season.startswith('.'):
						if fld == 'NBA':
							pic = '/media/example_folder.png'
						else:
							pic = '/'+directory+'/'+serie+'/'+season+'/season.jpeg'
						if s.pic == None:
							s.pic = pic
							s.save()
						ss = Folder.create(season,request.user.profile,s,pic)
						ss.save()
						for episode in os.listdir(directory+'/'+serie+'/'+season+'/'):
							if not episode.startswith('.') and '.jpeg' not in episode:
								# if fld == 'NBA':
								# 	pic = '/media/example_folder.png'
								# else:
								# 	pic = '/'+directory+'/'+serie+'/'+season+'/season.jpeg'
								url = open(directory+'/'+serie+'/'+season+'/'+episode,'r').readline()
								if url.__len__ > 0:
									c = Card.create(episode,url,ss)
									if fld == 'NBA':
										c.pic = fld+'/'+serie+'/'+season +'/'+ episode+'.jpeg'
									c.save()
开发者ID:albertorb,项目名称:vincula,代码行数:35,代码来源:miscellanea.py

示例4: test_get

    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,代码行数:26,代码来源:tests.py

示例5: folders

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,代码行数:25,代码来源:views.py

示例6: folder_add_typed

def folder_add_typed(request, folder_id=None, response_format='html'):
    "Folder add to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.profile.has_permission(folder, mode='x'):
            folder = None

    if request.POST:
        if 'cancel' not in request.POST:
            folder = Folder()
            form = FolderForm(
                request.user.profile, folder_id, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FolderForm(request.user.profile, folder_id)

    context = _get_default_context(request)
    context.update({'form': form,
                    'folder': folder})

    return render_to_response('documents/folder_add_typed', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:30,代码来源:views.py

示例7: post

 def post(self):
     user = get_user_from_id(session['user_id'])
     name = request.json['name']
     new_folder = Folder(name=name)
     new_folder.user_id = user.id
     db.session.add(new_folder)
     db.session.commit()
     return {'folder': new_folder.as_json()}, 201
开发者ID:avtenyuk,项目名称:supertodo,代码行数:8,代码来源:views.py

示例8: handle_uploaded_json_file

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,代码行数:58,代码来源:views.py

示例9: test_model_document

 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,代码行数:9,代码来源:tests.py

示例10: test_login_required

 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,代码行数:9,代码来源:tests.py

示例11: RPC__Folder__getRoot

    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,代码行数:9,代码来源:handlers.py

示例12: test_model_weblink

 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,代码行数:9,代码来源:tests.py

示例13: test_model_file

 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,代码行数:9,代码来源:tests.py

示例14: test_post

 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,代码行数:10,代码来源:tests.py

示例15: create_folder

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,代码行数:10,代码来源:folders.py


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