Changeset 7891
- Timestamp:
- 08/29/08 02:53:08 (3 months ago)
- Files:
-
- project/gallery.openlayers.org/openlayers/faq/models.py (modified) (2 diffs)
- project/gallery.openlayers.org/openlayers/faq/render.py (added)
- project/gallery.openlayers.org/openlayers/faq/templates/cat.html (modified) (2 diffs)
- project/gallery.openlayers.org/openlayers/faq/templates/cat_list.html (modified) (2 diffs)
- project/gallery.openlayers.org/openlayers/faq/templates/question.html (modified) (1 diff)
- project/gallery.openlayers.org/openlayers/faq/urls.py (modified) (1 diff)
- project/gallery.openlayers.org/openlayers/faq/views.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
project/gallery.openlayers.org/openlayers/faq/models.py
r7890 r7891 1 1 from django.db import models 2 2 from django.template.defaultfilters import slugify 3 from openlayers.faq.render import render_text 3 4 4 5 # Create your models here. … … 44 45 return ('openlayers.faq.views.question', 45 46 [self.cat.slug, self.slug]) 46 47 48 def rendered_answer(self): 49 return render_text(self.answer).replace("<script", "<script") 50 47 51 q = models.CharField(max_length=255) 48 52 slug = models.CharField(max_length=255, editable=False) project/gallery.openlayers.org/openlayers/faq/templates/cat.html
r7890 r7891 1 1 {% extends "base.html" %} 2 {% block title %}{{cat}}{% endblock %} 2 3 {% block content %} 3 4 {% include "breadcrumb.html" %} … … 5 6 <ul> 6 7 {% for q in cat.question_set.all %} 7 <li><a href="{{q.get_absolute_url}}">{{ q }}</a></li> 8 <li><a href="{{q.get_absolute_url}}">{{ q }}</a> 9 {% if expanded %} 10 <br /> 11 {{ q.rendered_answer|safe }} 12 {% endif %} 13 </li> 8 14 {% endfor %} 9 15 </ul> 10 <a href="/add/question/">Add a question/answer</a> 16 <a href="/add/question/">Add a question/answer</a><br /> 17 <a href="all/">Expand All</a> 11 18 {% endblock %} 12 19 project/gallery.openlayers.org/openlayers/faq/templates/cat_list.html
r7890 r7891 7 7 <ul> 8 8 {% for q in cat.question_set.all %} 9 <li><a href="{{q.get_absolute_url}}">{{ q }}</a></li> 9 <li><a href="{{q.get_absolute_url}}">{{ q }}</a> 10 {% if expanded %} 11 <br /> 12 {{ q.rendered_answer|safe }} 13 {% endif %} 14 </li> 10 15 {% endfor %} 11 16 </ul> … … 13 18 {% endfor %} 14 19 </ul> 15 <a href="/add/category/">Add Category</a> 20 <a href="/add/category/">Add Category</a><br /> 21 <a href="/all/">Expand All</a> 16 22 {% endblock %} project/gallery.openlayers.org/openlayers/faq/templates/question.html
r7890 r7891 1 1 {% extends "base.html" %} 2 {% block title %}{{question}}{% endblock %} 2 3 {% block content %} 3 4 {% include "breadcrumb.html" %} 4 5 <h1>{{ question }}</h1> 5 6 <small>(<a href="/add/question/{{question.id}}">Edit</a>)</small> 6 <p>{{ question.answer }}</p> 7 {{ question.rendered_answer|safe }} 7 8 8 9 <hr /> project/gallery.openlayers.org/openlayers/faq/urls.py
r7890 r7891 4 4 # Example: 5 5 (r'^$', 'list'), 6 (r'^(?P<all>all)/$', 'list'), 6 7 (r'^add/qlink/', 'qlink_upload'), 7 8 (r'^add/(?P<type>category|question)/$', 'add_item'), 8 9 (r'^add/(?P<type>category|question)/(?P<id>[0-9]+)/$', 'add_item'), 9 10 (r'^(?P<cat>[a-z0-9-_]+)/$', 'cat'), 11 (r'^(?P<cat>[a-z0-9-_]+)/(?P<all>all)/$', 'cat'), 10 12 (r'^(?P<cat>[a-z0-9-_]+)/(?P<q>[a-z0-9-_]+)/$', 'question'), 11 13 ) project/gallery.openlayers.org/openlayers/faq/views.py
r7890 r7891 5 5 from django.http import HttpResponseRedirect 6 6 from django.shortcuts import render_to_response, get_object_or_404 7 8 import openlayers.faq.render 7 9 8 10 class Page(object): … … 31 33 model = QLink 32 34 33 def list(request ):35 def list(request, all=None): 34 36 crumb = [Page("/", "FAQ Home")] 35 37 cats = Category.objects.all() 36 return render_to_response("cat_list.html", {'cats': cats, 'breadcrumb': crumb}) 38 template = "cat_list.html" 39 return render_to_response(template, {'cats': cats, 'breadcrumb': crumb, 'expanded': bool(all)}) 37 40 38 def cat(request, cat ):41 def cat(request, cat, all=None): 39 42 crumb = [Page("/", "FAQ Home")] 40 43 cat = get_object_or_404(Category, slug=cat) 41 44 crumb.append(cat) 42 return render_to_response("cat.html", {'cat': cat, 'breadcrumb': crumb })45 return render_to_response("cat.html", {'cat': cat, 'breadcrumb': crumb, 'expanded': bool(all)}) 43 46 44 47 def qlink_upload(request): … … 67 70 return render_to_response("form.html", {'form': form}) 68 71 69 def add_cat(request, id=None):70 if id:71 cat = get_object_or_404(Question, pk=id)72 form = QuestionForm(request.POST, instance=cat, auto_id=False)73 else:74 if request.method == "POST":75 form = QuestionForm(request.POST)76 else:77 form = QuestionForm()78 if request.method == "POST" and form.is_valid():79 obj = form.save()80 return HttpResponseRedirect(obj.get_absolute_url())81 else:82 return render_to_response("form.html", {'form': form})83 84 72 85 73 def question(request, cat, q): … … 89 77 question = forms.IntegerField(initial=q.id, widget=forms.HiddenInput) 90 78 f = QQLinkForm() 91 return render_to_response("question.html", {'question': q, 'breadcrumb':crumb, 'form': f})79 return render_to_response("question.html", {'question': q, 'breadcrumb':crumb, 'form': f}) 92 80
