Changeset - f98a3f2f9a46
[Not reviewed]
0 3 0
Brian Rosner - 12 years ago 2012-09-20 01:18:29
brosner@gmail.com
added ability to remove content from slots
3 files changed with 28 insertions and 17 deletions:
0 comments (0 inline, 0 general)
symposion/schedule/forms.py
Show inline comments
...
 
@@ -6,17 +6,18 @@ from symposion.schedule.models import Presentation
 

	
 
class SlotEditForm(forms.Form):
 
    
 
    presentation = forms.ModelChoiceField(
 
        queryset=Presentation.objects.all(),
 
        required=True,
 
    )
 
    presentation = forms.ModelChoiceField(queryset=Presentation.objects.all())
 
    
 
    def __init__(self, *args, **kwargs):
 
        presentation = kwargs.get("initial", {}).get("presentation")
 
        content = kwargs.pop("content", None)
 
        if content:
 
            kwargs.setdefault("initial", {})["presentation"] = content
 
        super(SlotEditForm, self).__init__(*args, **kwargs)
 
        queryset = self.fields["presentation"].queryset
 
        if presentation:
 
            queryset = queryset.filter(Q(slot=None) | Q(pk=presentation.pk))
 
        if content:
 
            queryset = queryset.filter(Q(slot=None) | Q(pk=content.pk))
 
            self.fields["presentation"].required = False
 
        else:
 
            queryset = queryset.filter(slot=None)
 
            self.fields["presentation"].required = True
 
        self.fields["presentation"].queryset = queryset
symposion/schedule/models.py
Show inline comments
...
 
@@ -52,11 +52,17 @@ class Slot(models.Model):
 
        Assign the given content to this slot and if a previous slot content
 
        was given we need to unlink it to avoid integrity errors.
 
        """
 
        self.unassign()
 
        content.slot = self
 
        content.save()
 
    
 
    def unassign(self):
 
        """
 
        Unassign the associated content with this slot.
 
        """
 
        if self.content and self.content.slot_id:
 
            self.content.slot = None
 
            self.content.save()
 
        content.slot = self
 
        content.save()
 
    
 
    @property
 
    def content(self):
symposion/schedule/views.py
Show inline comments
...
 
@@ -67,19 +67,23 @@ def schedule_slot_edit(request, slot_pk):
 
    
 
    slot = get_object_or_404(Slot, pk=slot_pk)
 
    
 
    # slot content
 
    try:
 
        content = slot.content
 
    except ObjectDoesNotExist:
 
        content = None
 
    
 
    if request.method == "POST":
 
        form = SlotEditForm(request.POST)
 
        form = SlotEditForm(request.POST, content=content)
 
        if form.is_valid():
 
            presentation = form.cleaned_data["presentation"]
 
            slot.assign(presentation)
 
            if presentation is None:
 
                slot.unassign()
 
            else:
 
                slot.assign(presentation)
 
        return redirect("schedule_edit_singleton")
 
    else:
 
        initial = {}
 
        try:
 
            initial["presentation"] = slot.content
 
        except ObjectDoesNotExist:
 
            pass
 
        form = SlotEditForm(initial=initial)
 
        form = SlotEditForm(content=content)
 
        ctx = {
 
            "form": form,
 
            "slot": slot,
0 comments (0 inline, 0 general)