Skip to content

Commit

Permalink
new tag cloud automatically redirects to its real url
Browse files Browse the repository at this point in the history
  • Loading branch information
jessykate committed Nov 14, 2010
1 parent e6e1473 commit 7e0ad3c
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 147 deletions.
32 changes: 11 additions & 21 deletions frontend/views.py
Expand Up @@ -80,27 +80,7 @@ def new_document(request):
return HttpResponse('<b>API Error</b><br><br>'+content)
return

# replace the full body text with placeholder text, and then pass
# the API call url to the template so the user can see what was
# done.
control_params = args
if 'body' in args:
control_params['body'] = "your text here"
generator_url = url + '?' + urllib.urlencode(control_params)

# tell the browser where it can insert a line break
generator_url_display = generator_url.replace('&', '<wbr>&')

print type(content)
# note that in the template, body and style need to be given the 'safe'
# filter so that the markup will be interpreted. otherwise it will be
# escaped and displayed as strings.
return HttpResponseRedirect("/cloud/%s" % cloud_id)
return render_to_formtemplate(request, 'frontend/tagcloud_display.html', {'body' : body,
'style' : style, 'generator_url' : generator_url,
'generator_url_display': generator_url_display,
'tagcloud_json': content, 'tagcloud_form': form,
'max_words_max': 200}) #stubbed out values
else:
print request.POST
print 'Form did not validate'
Expand All @@ -114,7 +94,17 @@ def cloud(request, cloud_id):
con = pymongo.Connection()
collection = con.wordapi.tagclouds
record = collection.find_one({'_id':ObjectId(cloud_id)})
return render_to_template(request, 'frontend/cloud.html', {'cloud':record})
# XXX TODO this needs to be its own form, not the tag cloud form.
form = TagCloudForm()

#generator_url = url + '?' + urllib.urlencode(control_params)
# tell the browser where it can insert a line break
#generator_url_display = generator_url.replace('&', '<wbr>&')

# note that in the template, body and style need to be given the 'safe'
# filter so that the markup will be interpreted. otherwise it will be
# escaped and displayed as strings.
return render_to_template(request, 'frontend/cloud.html', {'cloud':record, 'update_form':form})

def new_topic(request):
#topic_form = NewTopicForm(request.POST)
Expand Down
115 changes: 97 additions & 18 deletions templates/frontend/cloud.html
@@ -1,26 +1,105 @@
<html>
<head>
{% extends "frontend/base.html" %}

{% block custom_style %}
{{ cloud.style|safe }}
<link rel="stylesheet" type="text/css" href="/media/cloud.css">
<title>{{ cloud_name }}</title>
</head>

<body>
<div id="cloudwrapper">
{% if cloud.cloud_name %}
<div id="cloudtitle">
<h1>{{ cloud.cloud_name }}</h1>
</div>
{% endif %}
{% endblock %}

{% block custom_include %}
<link rel="stylesheet" media="screen" type="text/css" href="/media/colorpicker.css" />
<script type="text/javascript" src="/media/js/colorpicker.js"></script>
{% endblock %}
{% block page_title %} - TagCloud{% endblock %}

{% block custom_js %}
<script type="text/javascript">
$(document).ready(function() {

$("#save-box").dialog({
autoOpen: false,
width: 350,
model: true,
buttons : {
'Create!' : function() {
// check validity of arguments
// submit the form
$('#save-form').submit();
},
'Cancel' : function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val('');
}
});
$("#save-cloud").button().click(function() {
$("#save-box").dialog("open");
});
});

$('#id_start_color, #id_end_color').ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
$(el).val(hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
}
})
.bind('keyup', function(){
$(this).ColorPickerSetColor(this.value);
});


</script>
{% endblock %}

{% block content %}
<div id="save-box">
<form id="save-form" action="save" method="POST">
{% csrf_token %}
<label for="name">Name your cloud (optional)</label>
<input type="text" name="name"><br>
<fieldset id="update-type">
<input type="radio" name="update" value="static" checked="yes">Static
<input type="radio" name="update" value="dynamic">Dynamic<br>
<p>A static cloud stays the same as you see it right now. A dynamic cloud will
update every time you visit it.</p>
</fieldset>
<input type="hidden" name="cloud_id" value="{{ cloud_id }}">
</form>
</div>

<div id="tagcloud_controls">
<h4>Themes</h4>
<h4>Color</h4>
{{ update_form.start_color.label }}: <input type="text" maxlength="6" size="6" id="id_start_color" value="00ff00" />
{{ update_form.end_color.label }}: <input type="text" maxlength="6" size="6" id="id_end_color" value="0000ff" />
{{ update_form.color_steps.label }}: {{ update_form.color_steps }}

<h4>{{ update_form.max_words.label }}: <input type="range" min="0" max="{{ cloud.metadata.total_tags }}" /></h3>
<h4 class="size-selector">Size:</h4>
<label><input class="radio" type="radio" name="size" value="240x180"> Small</label>
<label><input class="radio" type="radio" name="size" value="500x375"> Medium</label>
<label><input class="radio" type="radio" name="size" value="1024x768"> Large</label>

<h4>Custom Stop Words</h4>
</div>

<div id="tagcloud_wrapper">
{{ cloud.body|safe }}
</div>
<div id="cloudinfo">
{{ home_page }}
Created {{ cloud.created|date:"D M d, Y" }}.

<div class="clear">
</div>

<div id="infobox">
Generated by <a href="{{home_page}}">WordAPI</a>
<a href="{{ cloud.short_url }}">Short Url</a>
Created {{ cloud.created_utc|date:"D M d, Y" }}.
<a href="{{ cloud.metadata.short_url }}">Short Url</a>
<a href="">Embed</a>
<a href="{{home_page}}/document/new">Create your own</a>

</div>

</body>
{% endblock %}
108 changes: 0 additions & 108 deletions templates/frontend/tagcloud_display.html

This file was deleted.

0 comments on commit 7e0ad3c

Please sign in to comment.