@login_required
def edited_to_published(request, id):
    def check(dict):
        complaints = []
        if dict[u"title"] in [None, u""]:
            complaints.append("You need to give the entry a title first.")
        if dict[u"body"] in [None, u""]:
            complaints.append("You'll need to fill out the article a bit before publishing it.")          
        if complaints == []:
            return True
        else:
            return "\n<br>\n".join(complaints)

    def transform(draft):
        dict = draft.__dict__.copy()
        del dict['id']
        if dict['pub_date'] is None:
            dict['pub_date'] = datetime.datetime.now()
        del dict['edited']
        if dict['slug'] is None and dict['title'] is not None:
            dict['slug'] = sluggify(dict['title'])
        entry = Entry(**dict)
        valid = check(entry.__dict__)
        if valid != True:
            return None, valid
        else:
            entry.save()
            for field in MANY_TO_MANY_FIELDS:
                getattr(entry, field).add(*getattr(draft, field).all())
            return entry, True

    try:
        draft = Draft.objects.get(pk=id)
        entry, result = transform(draft)
        if result == True:
            draft.delete()
            return HttpResponse(u"%s" % entry.pk)
        else:
            return HttpResponseServerError(result)
    except __HOLE__:
        return HttpResponseServerError(u"The draft is missing required fields.")
    except:
        return HttpResponseServerError(u"The update made it to the server, but failed for unknown reasons.")
dataset/ETHPy150Open lethain/lifeflow/editor/views.py/edited_to_published