Exemplo n.º 1
0
    def test_entry_save(self):
        title = 'Testing Entry Save'
        author = 'test'
        content = 'No worries... this is just a unit test'

        entry = Entry(
            title=title,
            author=author,
            content=content
        )
        entry.save()

        t1 = Tag()
        t1.name = 'test01'
        t1.save()

        entry.tags.add(t1)
        entry.save()
Exemplo n.º 2
0
def create(request):
    success = True
    msg = ''

    title = escape(request.POST.get('title', ''))
    author = escape(request.POST.get('author', ''))
    content = escape(request.POST.get('content', ''))
    tagsIn = escape(request.POST.get('tags', ''))
    tags = [x.strip() for x in tagsIn.split(',')]

    if ('' == title):
        success = False
        msg = 'Please enter a title for your rock anthem.'
    elif ('' == content):
        success = False
        msg = 'Please jot down the lyrics for your jam.'
    else:
        entry = Entry(
            title=title,
            author=author,
            content=content
        )
        entry.save()

        for tag in tags:
            tag = tag.lower()
            # lookup the tag, create it if necessary, and add it to the entry
            t = Tag()
            t.name = tag
            t.save()
            entry.tags.add(t)
        entry.save()
        success = True
        msg = entry.id

    data = {}
    data['success'] = success
    data['msg'] = msg
    out = simplejson.dumps(data)
    return HttpResponse(out, mimetype="application/json")