コード例 #1
0
def setup(request):
    context = {}
    if request.method == 'POST':  # A form has been submitted
        form = SetupForm(request.POST)  # Create a form bound to POST data
        log.debug("setup view form:" + str(form))
        log.debug("is form valid?" + str(form.is_valid()))
        if form.is_valid():  # All validation rules passed, form is valid
            f = form.cleaned_data  # Process cleaned data
            media_folder = MediaFolder(folder=f['scan_folder'])
            media_folder.save()
            app_config_type = get_object_or_404(Type, code='config.app')
            destination_folder = Configuration(key='destination.folder', \
                                               value=f['destination_folder'], \
                                               type=app_config_type)
            destination_folder.save()
            return home(request)
        else:  # Form has some errors
            pass
    else:  # No form has been submitted this is a view action
        form = SetupForm()  # Create an empty form
    context['form'] = form
    log.debug("setup view context:" + str(context))
    return render(request, 'sorter/setup.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: jlgrady1/mediamanager
def setup(request):
    context = {}
    if request.method == 'POST': # A form has been submitted
        form = SetupForm(request.POST) # Create a form bound to POST data
        log.debug("setup view form:" + str(form))
        log.debug("is form valid?" + str(form.is_valid()))
        if form.is_valid(): # All validation rules passed, form is valid
            f = form.cleaned_data # Process cleaned data
            media_folder = MediaFolder(folder=f['scan_folder'])
            media_folder.save()
            app_config_type = get_object_or_404(Type, code='config.app') 
            destination_folder = Configuration(key='destination.folder', \
                                               value=f['destination_folder'], \
                                               type=app_config_type)
            destination_folder.save()
            return home(request)
        else: # Form has some errors
            pass
    else: # No form has been submitted this is a view action
        form = SetupForm() # Create an empty form
    context['form'] = form
    log.debug("setup view context:" + str(context))
    return render(request, 'sorter/setup.html', context)
コード例 #3
0
ファイル: tests.py プロジェクト: jspeyside/mediamanager
 def test_get_level(self):
     top_folder = MediaFolder(folder='/path/to/my/folder')
     top_folder.save()
     self.assertEqual(top_folder.get_level(), 0)
     child_folder1 = MediaFolder(folder = '/path/to/my/folder/child', \
                                 parent = top_folder)
     child_folder1.save()
     self.assertEqual(child_folder1.get_level(), 1)
     child_folder2 = MediaFolder( \
             folder = '/path/to/my/folder/child/child2', \
             parent = child_folder1)
     child_folder2.save()
     self.assertEqual(child_folder2.get_level(), 2)
     child_folder3 = MediaFolder( \
             folder = '/path/to/my/folder/child/child3', \
             parent = child_folder1)
     child_folder3.save()
     self.assertEqual(child_folder3.get_level(), 2)
コード例 #4
0
ファイル: tests.py プロジェクト: jlgrady1/mediamanager
 def test_get_level(self):
     top_folder = MediaFolder(folder = '/path/to/my/folder')
     top_folder.save()
     self.assertEqual(top_folder.get_level(), 0)
     child_folder1 = MediaFolder(folder = '/path/to/my/folder/child', \
                                 parent = top_folder)
     child_folder1.save()
     self.assertEqual(child_folder1.get_level(), 1)
     child_folder2 = MediaFolder( \
             folder = '/path/to/my/folder/child/child2', \
             parent = child_folder1)
     child_folder2.save()
     self.assertEqual(child_folder2.get_level(), 2)
     child_folder3 = MediaFolder( \
             folder = '/path/to/my/folder/child/child3', \
             parent = child_folder1)
     child_folder3.save()
     self.assertEqual(child_folder3.get_level(), 2)