Beispiel #1
0
def update(request):
    success = True
    msg = ''

    entry_id = escape(request.POST.get('id', ''))
    entry = Entry.objects.get(pk=entry_id)

    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 entry is None:
        success = False
        msg = 'Entry with id %s not found.' % entry_id
    elif ('' == 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:
        # update the entry
        entry.title = title
        entry.author = author
        entry.content = content
        ## delete the current tags and add them back
        for tag in entry.tags.all():
            tag.delete()
        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")
Beispiel #2
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()
Beispiel #3
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")