Ejemplo n.º 1
0
def manage_folder(request, folder_id):
    folders = Folder.objects.filter(id=folder_id, user=request.user.id)[:1] 
    if len(folders) > 0:
        folder_instance = folders[0]
        if folder_instance.folder_name == "Archive":
            return HttpResponseRedirect(settings.BASE_URL + "dashboard")
        folderForm = FolderForm(instance=folder_instance, user=request.user.id)
        if request.method == 'POST':
            folderForm = FolderForm(request.POST, instance=folder_instance, user=request.user.id)
            if folderForm.is_valid():
                folder_instance.parent = Folder.objects.filter(id=folderForm["parent_folder"].data)[0]
                folder_instance.save()
                return HttpResponseRedirect(settings.BASE_URL + "dashboard")
        else:
            folderForm = FolderForm(instance=folder_instance, user=request.user.id) 
        return render_to_response("marnie/manage_folder.html", { "form": folderForm, }, RequestContext(request))
    else:
        raise Http404
Ejemplo n.º 2
0
def add(request):
    c = {}
    c.update(csrf(request))

    bookmarkForm = BookmarkForm(user=request.user.id)
    TagFormSet = formset_factory(TagForm)
    AuthorFormSet = formset_factory(AuthorForm)
    folderForm = FolderForm(user=request.user.id)

    if request.method == 'POST':
        bookmarkForm = BookmarkForm(request.POST, user=request.user.id)
        tagFormSet = TagFormSet(request.POST)
        authorFormSet = AuthorFormSet(request.POST)
        folderForm = FolderForm(request.POST, user=request.user.id)

        if 'add_bookmark' in request.POST:
                form = bookmarkForm
                if form.is_valid() and form.has_changed():
                    internal_id = uuid.uuid4()
                    type = "B"
		    title = form.cleaned_data["title"]
		    urls = form.cleaned_data["urls"]
                    user = request.user
                    description = form.cleaned_data["description"]
                    date = datetime.datetime.now()
                    publication_date = form.cleaned_data["pub_date"]                     
                    folder = form.cleaned_data["folder"]
                    notes = form.cleaned_data["notes"]
                    
                    bookmark = Bookmark(type=type, 
                        internal_id=internal_id, 
                        title=title, 
                        description=description, 
                        date=date, 
                        pub_date=publication_date,
                        folder=folder,
                        notes=notes,
                        user=user)
                    bookmark.save()                     
                   
                    for url in urls.split():
                        path = handle_snapshot(url, internal_id)
                        t = BookmarkItem(external_url=url, internal_url=path)
                        t.user = request.user
                        t.save()
                        bookmark.items.add(t) 
                   
                    tags = form.cleaned_data['tags']
                    for tag in tags:
                        bookmark.tags.add(tag)   
                   
                    authors = form.cleaned_data['authors']
                    for author in authors:
                        bookmark.authors.add(author)

                    return HttpResponseRedirect(settings.BASE_URL + "dashboard")
        if 'add_tag' in request.POST:
            if tagFormSet.is_valid():
                for form in tagFormSet.forms:
                    if not form['tag_name'].data == '':
                        t = Tag(tag_name=form['tag_name'].data)
                        t.user = request.user
                        t.save()
        if 'add_author' in request.POST:
            if authorFormSet.is_valid():
                for form in authorFormSet.forms:
                    if not form['author_name'].data == '':
                        a = Author(author_name=form['author_name'].data)
                        a.user = request.user
                        a.save()
        if 'add_folder' in request.POST:
            if folderForm.is_valid():
                if not folderForm['folder_name'].data == '':
                    folderList = folderForm['parent_folder'].data
                    for folderId in folderList:
                        parent = Folder.objects.get(id=folderId)
                        f = Folder(folder_name=folderForm['folder_name'].data, parent=parent)
                        f.user = request.user
                        f.save()
                    return HttpResponseRedirect(settings.BASE_URL + "dashboard")
    else:
        bookmarkForm = BookmarkForm(user=request.user.id)
        tagFormSet = TagFormSet()
        authorFormSet = AuthorFormSet()
        folderForm = FolderForm(user=request.user.id)

    return render_to_response('marnie/add.html', {
        "bookmarkForm": bookmarkForm, 
        "tagFormSet": tagFormSet, 
        "authorFormSet": authorFormSet, 
        "folderForm": folderForm,
    }, RequestContext(request))