首页 \ 问答 \ 跳过步骤x到步骤y并验证步骤x数据(skipping step x to step y and validate step x data)

跳过步骤x到步骤y并验证步骤x数据(skipping step x to step y and validate step x data)

我实际上在django向导表单上有一个大问题。

我有3个步骤。 第二步可以包含数据。 最后一步是文件上传步骤。

在WizardForm类中,我重写了get_context_data方法并将其包含在其中:

if self.steps.current == 'against_indication':
        questions = None
        try:
            # get the machine
            machine_id = self.kwargs['pk']
            machine = Machine.objects.get(pk=int(machine_id))
            # check if there is against indications
            if machine.type_question is False:
                questions = YhappsQuestion.objects.filter(type_modalite=machine.type)
            else:
                questions = CustomQuestion.objects.filter(machine=machine)
        except Machine.DoesNotExist:
                pass
        if len(questions) == 0:
            # we modify the form wizard to skip against indication step
            self.render_next_step(form, **kwargs)
            #self.render_goto_step(step='against_indication', goto_step='prescription', **kwargs)

如你所见,如果没有问题,我跳过第二步(against_indication)进入下一步(处方)。

问题出现在这里。 呈现最后一步时,向导表单中没有足够的数据。 在ddt的请求中有它: 跳过步骤 。 因此,如果我上传文件,它将填写against_indication数据而不是处方数据,并重新渲染我最后一步...

我试图在不跳过第二步的情况下完成所有这些操作,看看ddt的请求是如何看的: 没有跳过步骤

,当我跳过步骤时,有人有一个允许拥有正确数据的解决方案,PLZ?

感谢您的进一步答复


I have actually a big problem on a django wizard form.

I have 3 steps. The second step can contains data or not. The last step is a file upload step.

In the WizardForm class, i overrided the get_context_data method and include this in it :

if self.steps.current == 'against_indication':
        questions = None
        try:
            # get the machine
            machine_id = self.kwargs['pk']
            machine = Machine.objects.get(pk=int(machine_id))
            # check if there is against indications
            if machine.type_question is False:
                questions = YhappsQuestion.objects.filter(type_modalite=machine.type)
            else:
                questions = CustomQuestion.objects.filter(machine=machine)
        except Machine.DoesNotExist:
                pass
        if len(questions) == 0:
            # we modify the form wizard to skip against indication step
            self.render_next_step(form, **kwargs)
            #self.render_goto_step(step='against_indication', goto_step='prescription', **kwargs)

As you see, if there is no questions, i skip the second step (against_indication) to go into the next step (prescription).

The problem appears here. When the last step is rendered, there is not enough data in the wizard form. In the ddt's request there is it : with skip step. So if i upload the file, it gonna fill the against_indication datas instead of prescription datas, and re-renderer me the last step...

I tried to do all of this without skip the second step, and see how look the ddt's request : without skip step.

Someone has a solution to permit have the right datas when i skip step, plz ?

Thanks for your further answers


原文:https://stackoverflow.com/questions/34904918
更新时间:2024-01-30 13:01

相关问答

更多
  • 最简单的方法是使用XamlWriter将WPF对象保存为字符串。 Save方法将序列化逻辑树中的对象及其所有子对象。 现在您可以创建一个新对象并使用XamlReader加载它。 例如:将对象写入xaml(让我们说对象是一个Grid控件): string gridXaml = XamlWriter.Save(myGrid); 将它加载到一个新对象中: StringReader stringReader = new StringReader(gridXaml); XmlReader xmlReader = X ...
  • 如果您的类是Serializable ,那么您可以将对象序列化为ByteStream,并将该流反 序列化为 新的对象 。 If your class is Serializable than you can serialize the object to ByteStream and Deserialize that stream to a new object.
  • 使用Reflect.copy() : var newConfig = Reflect.copy(config); 请注意,它只能保证在匿名结构上工作。 对于其他对象,请使用适当的Reflect方法。 Use Reflect.copy(): var newConfig = Reflect.copy(config); Note that it only guaranteed to work on anonymous structures. For other objects, use the appropr ...
  • 一个优雅的解决方案是覆盖__get() : public function __get($name) { return $this->mvc->$name; } 每当你尝试访问你的类的一个不存在的属性时, __get()就会被调用。 这样,你不必复制你的类中的每个mvc属性(这可能会覆盖你的类中的属性)。 如果需要,您还可以使用property_exists检查mvc是否存在$name 。 An elegant solution would be to override __get(): publ ...
  • 一般建议:使用复制构造函数 。 事实上,只有一个类本身知道如何创建自己的克隆。 没有类可以克隆另一个类的实例。 这个想法是这样的: public class Foo { public List bars = new ArrayList(); private String secret; // Copy constructor public Foo(Foo that) { // new List this.bars = new ArrayList ...
  • 好的,所以我终于开始工作了。 这是我尝试过的解决方案 $("#divLocatePops").find('.original').draggable({ helper: 'clone', revert: 'invalid' }); $('#divGeneralLayOutContentBody').droppable({ drop: function(event, ui) { var cloneTop=ui.helper.offset().top, ...
  • 您似乎已经意识到Java中的Cloneable已经崩溃。 以下是对有效Java第二版作者Josh Bloch的采访中的一些引用: 如果您已经阅读了我的书中有关克隆的项目,特别是如果您在这些内容之间进行了阅读,您将会知道我认为clone已经深受打击。 存在一些设计缺陷,其中最大的一个是Cloneable接口没有clone方法。 这意味着它根本不起作用:制作一些Cloneable并没有说明你可以用它做什么。 相反,它说明了内部可以做些什么。 它说如果通过反复调用super.clone它最终调用Object的cl ...
  • 对于data class ,您可以使用编译器生成的copy()方法 。 请注意,它将执行浅拷贝。 要创建集合的副本,请使用toList()或toSet()方法,具体取决于所需的集合类型。 这些方法总是创建集合的新副本; 他们也执行浅拷贝。 对于其他类,没有Kotlin特定的克隆解决方案。 如果它符合您的要求,您可以使用.clone()如果不符合,则可以构建不同的解决方案。 For a data class, you can use the compiler-generated copy() method. ...
  • 使用反射查看对象上的字段并使用它来填充新实例。 这假设存在一个不带参数的构造函数。 Type t = typeof(typeToClone); var fields = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var copy = Activator.CreateInstance(t); for(int i = 0; i < fields.Length; i++) fields[ ...
  • 您应该查看以下示例 x = 20; echo $a->x."
    "; $b = clone $a; $a->x = 30; echo $a->x."
    "; echo $b->x."
    "; // 20 because x was 20 before cloning $a to $b $a->x = 50; echo $a->x."

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)