I think that function actually belongs in class Stageable

On Jan 5, 2013, at 10:51 AM, Joe Blaylock <notifications@github.com> wrote:

> In main/courses/files/actions.py:
> 
> > +        if form.is_valid():
> > +            form.save()
> > +            file.commit()
> > +            
> > +            parent_type = request.POST.get('parent')
> > +            if parent_type and parent_type[:4] != 'none':
> > +                parent_type, parent_id = parent_type.split(',')
> > +            else:
> > +                parent_type, parent_id = None, None
> > +            if parent_type:
> > +                parent_ref = ContentGroup.groupable_types[parent_type].objects.get(id=long(parent_id)).image
> > +                content_group_groupid = ContentGroup.add_parent(file.image.course, parent_type, parent_ref.image)
> > +                ContentGroup.add_child(content_group_groupid, 'file', file.image, display_style=request.POST.get('display_style'))
> > +            else: #file should have no parents, so delete its place in a contentgroup if it's a child
> > +                try:
> > +                    cgobj = file.image.contentgroup_set.get()
> Yes, in my branch jrbl-1482-parent-assignment-static-page-edits I abstract this boilerplate into a function call, which explicitly checks the object's .mode and returns object.image if .mode != u'ready'.
> 
> Right now that call is in courses/actions.py, but I debated whether it belonged in the model.
> 
> Or .add_parent and .add_child could just be made mode-aware in this way, of course, but somehow that feels a bit clumsy to me.
> 
> —
> Reply to this email directly or view it on GitHub.
> 
>