Exemple #1
0
def content_profile_add(request):
    content_profile_form = ContentProfileAddForm()
    if request.POST:
        content_profile_form = ContentProfileAddForm(request.POST)

        if content_profile_form.is_valid():
            new_profile = content_profile_form.save(commit=False)
            new_profile.created_by = request.user

            # Retrieve page title
            pageStructure = BeautifulSoup(urllib.urlopen(new_profile.url))
            if not pageStructure or not pageStructure.head:
                # TODO return helpful error message to client
                print "Could not retrieve"
                raise Exception("Could not retrieve title from URL [%s]." % new_profile.url)
            title = pageStructure.head.title
            if not title:
                # TODO return helpful error message to client
                print "Could not retrieve title for %s" % new_profile.url
                raise Exception("Could not retrieve title from URL [%s]." % new_profile.url)

            new_profile.name = title.renderContents()

            # Private key generation (currently just sys time)
            pKey = generate_profile_private_key(new_profile)
            new_profile.privateKey = pKey

            new_profile.status = 0

            new_profile.save()

            return HttpResponseRedirect(reverse("content_profiles_list"))
        else:
            print "Invalid form submitted"
            # TODO return helpful error message to client
    request.breadcrumbs([("Profiles", reverse("content_profiles_list")), ("New Profile", "")])

    return render_to_response(
        "content_profiles/content_profile_add.html",
        {"form": content_profile_form},
        context_instance=RequestContext(request),
    )
Exemple #2
0
def content_profile_add(request):
    content_profile_form = ContentProfileAddForm()
    if request.POST:
        content_profile_form = ContentProfileAddForm(request.POST)

        if content_profile_form.is_valid():
            new_profile = content_profile_form.save(commit=False)
            new_profile.created_by = request.user
            new_profile.save()
            return HttpResponseRedirect(reverse('content_profiles_list'))

    request.breadcrumbs([
        ("Profiles", reverse('content_profiles_list')),
        ('New Profile', ''),
    ])


    return render_to_response('content_profiles/content_profile_add.html',
        {'form': content_profile_form},
        context_instance=RequestContext(request)
    )