view templates/snippet/snippet_new.djhtml @ 139:b8e0bdc37e32

Hide snippets created by anonymous users Created a custom manager for Snippet, with a public() method for easily retrieving all the snippets that were created by registered users. This change makes the code a bit neater, as it's no longer to necessary to have to do the {% if snippet.author %} check every time.
author dellsystem <ilostwaldo@gmail.com>
date Sat, 29 Sep 2012 21:31:17 -0400
parents 8aa8c6dd2b02
children
line wrap: on
line source

{% extends "snippet/base.djhtml" %}
{% load i18n %}

{% block title %}{% trans "New snippet" %}{% endblock %}

{% block content %}
    <div id="non-sidebar">
        <h1>{% trans "Paste a new snippet" %}</h1>
        <p class="hint">{% trans "Snippets provide a way to quickly share pieces of code, complete with line-numbering and syntax-highlighting." %} {% if not user.is_authenticated %}{% trans "Although registration is not required, only registered users can delete their own snippets after ending a session or have them linked to their profile. Additionally, snippets made by guests will not be publicly listed." %}{% endif %}</p>
        {% include "snippet/snippet_form.djhtml" %}
    </div><div id="sidebar">
        <h2>Recent snippets</h2>
        {% for snippet in recent_snippets %}
        <hr />
        <p>
            <a href="{{ snippet.get_absolute_url }}">
                {{ snippet.get_title }}
            </a>
            <br />
            by
            <a href="{{ snippet.author.get_absolute_url }}">
                {{ snippet.author }}
            </a>
        </p>
        {% endfor %}
        <p class="right-float"><a href="{% url snippet_explore %}">
            {% trans "View more" %} &raquo;
        </a></p>
    </div>
{% endblock %}

{% block script_footer %}
<script type="text/javascript">
jQuery(document).ready(function(){
    {% if request.session.userprefs.display_all_lexer %}
    $('#guess_lexer_btn').click(function(){
        $.getJSON('{% url snippet_guess_lexer %}',
            {'codestring': $('#id_content').val()},
            function(data){
                if(data.lexer == "unknown"){
                    $('#guess_lexer_btn').css('color', 'red');
                }else{
                    $('#id_lexer').val(data.lexer);
                    $('#guess_lexer_btn').css('color', 'inherit');
                }
            });
    });
    {% endif %}
});
</script>
{% endblock %}