예제 #1
0
파일: views.py 프로젝트: makaimc/pfisdi
def research_link(req, slug=''):
    p = _create_params(req)
    p['link'] = get_object_or_404(ResearchLink, owner=req.user, slug=slug)
    p['breadcrumbs'].append({'ideas/link/%s/' % slug: p['link'].name })
    p['slug'] = p['link'].slug
    if req.method == 'GET':
        p['form'] = ResearchLinkForm(instance=p['link'])
        return render_to_response(TEMPLATE_PATH + 'research_link.html', p,
            context_instance=RequestContext(req))
    elif req.method == 'POST':
        form = ResearchLinkForm(req.POST)
        if form.is_valid():
            link = p['link']
            link.owner = req.user
            _save_research_link(form, link)
            messages.add_message(req, messages.INFO,
                'Research link  "%s" successfully updated.' % link.name)
            return HttpResponseRedirect(reverse('ideas'))
        else:
            p['form'] = form
            return render_to_response(TEMPLATE_PATH + 'research_link.html', p,
                context_instance=RequestContext(req))
예제 #2
0
파일: views.py 프로젝트: makaimc/pfisdi
def new_research_link(req):
    p = _create_params(req)
    p['breadcrumbs'].append({reverse('new_research_link'): \
        'New Research Link'})
    if req.method == 'GET':
        p['form'] = ResearchLinkForm()
        return render_to_response(TEMPLATE_PATH + 'research_link.html', p,
            context_instance=RequestContext(req))
    elif req.method == 'POST':
        form = ResearchLinkForm(req.POST)
        if form.is_valid():
            link = ResearchLink()
            link.owner = req.user
            _save_research_link(form, link)
            tags = req.POST.get('tags', '').strip()
            if tags != '':
                _add_tags(link, tags, req.user, 'research link')
            messages.add_message(req, messages.INFO,
                'New research link "%s" created successfully.' % link.name)
            return HttpResponseRedirect(reverse('ideas'))
        else:
            p['form'] = form
            return render_to_response(TEMPLATE_PATH + 'research_link.html', p,
                context_instance=RequestContext(req))