コード例 #1
0
ファイル: views.py プロジェクト: heldergg/dre
def settings_form( request, template = 'settings_form.html' ):
    context = {}
    user = request.user

    if request.method == 'POST':
        form = SettingsForm(request.POST.copy())
        if form.is_valid():
            # Cycle through the settings and save them
            data = form.cleaned_data
            for setting in USER_SETTINGS:
                name = setting['name']
                set_setting(user, name, data[name])
            context['saved'] = True
    else:
        # Read user settings and build the form
        settings = {}
        for setting in USER_SETTINGS:
            name = setting['name']
            settings[name] = get_setting(user, name)
        form = SettingsForm(settings)

    context['form'] = form

    return render_to_response(template,
        context, context_instance=RequestContext(request))
コード例 #2
0
def generate_test_file():
    filename="test.dat"
    uuid=b58encode(os.urandom(16))
    file_dir = create_file_directories(uuid)
    file_path = file_dir+"/"+filename
    file_size=1024
    fh = open(file_path, 'w')
    while os.path.getsize(file_path) <= file_size:
        fh.write(os.urandom(16))
    fh.close()
    sha256_hash = hashfile(file_path)
    f=File.objects.create(uuid=uuid, name=filename, file_sha256=sha256_hash)
    f.save()
    set_setting("test_file", str(f.id))
    pass