Commits

Kai Diefenbach committed 0560951

Exclude current compositor from reference form

Comments (0)

Files changed (1)

lfc_compositor/models.py

                 is_last = False
 
             content += row.render(request, edit, is_first, is_last)
-        
+
         return render_to_string("lfc_compositor/widgets/composite.html", RequestContext(request, {
             "composite" : self,
             "content" : content,
             "content" : content,
             "edit" : edit,
             "first_row" : first_row,
-            "last_row" : last_row,            
+            "last_row" : last_row,
         }))
 
 class Column(models.Model):
         """
         widgets = self.get_widgets()
         amount = len(widgets)-1
-        
+
         content = ""
         for i, widget in enumerate(widgets):
 
                 last_widget = True
             else:
                 last_widget = False
-            
+
             content += widget.render(request, edit, first_widget, last_widget)
 
         columns = self.parent.columns.count()
         return render_to_string("lfc_compositor/widgets/text.html", RequestContext(request, {
             "widget" : self,
             "edit" : edit,
-            "first_widget" : first_widget, 
+            "first_widget" : first_widget,
             "last_widget" : last_widget,
         }))
 
             "widget" : self,
             "image_url" : image_url,
             "edit" : edit,
-            "first_widget" : first_widget, 
-            "last_widget" : last_widget,            
+            "first_widget" : first_widget,
+            "last_widget" : last_widget,
         }))
 
 class ImageWidgetForm(forms.ModelForm):
             "image_url" : image_url,
             "IMAGE_LEFT" : self.image_position == LEFT,
             "edit" : edit,
-            "first_widget" : first_widget, 
-            "last_widget" : last_widget,            
+            "first_widget" : first_widget,
+            "last_widget" : last_widget,
         }))
 
 class TextWithImageWidgetForm(forms.ModelForm):
         return render_to_string("lfc_compositor/widgets/reference.html", RequestContext(request, {
             "widget" : self,
             "edit" : edit,
-            "first_widget" : first_widget, 
-            "last_widget" : last_widget,            
+            "first_widget" : first_widget,
+            "last_widget" : last_widget,
         }))
 
 class ReferenceWidgetForm(forms.ModelForm):
     template = "lfc_compositor/widgets/reference_form.html"
+
+    def __init__(self, *args, **kwargs):
+        composite = kwargs.get("composite")
+        del kwargs["composite"]
+
+        super(ReferenceWidgetForm, self).__init__(*args, **kwargs)
+
+        choices = [("", "-----")]
+        choices.extend([(o.id, o.title) for o in BaseContent.objects.exclude(pk=composite.basecontent_ptr_id)])
+
+        self.fields["reference"].choices = choices
+
     class Meta:
         model = ReferenceWidget
         fields = ("reference", "words", "display_title", "display_link")