2011-01-08 17 views
2

Django_notification (https://github.com/pinax/django-notification/blob/master/notification/views.py)의보기 인 경우 확인란을 어떻게 표시합니까? 여기에 형태 객체가있는 것처럼 보이지 않습니다. 일반적으로, 나는이 일을하는 데 사용 해요 : {{myform.thefield}}이Django 템플릿에서 체크 박스와 알림 유형을 어떻게 표시합니까?

@login_required 
def notice_settings(request): 
    """ 
    The notice settings view. 

    Template: :template:`notification/notice_settings.html` 

    Context: 

     notice_types 
      A list of all :model:`notification.NoticeType` objects. 

     notice_settings 
      A dictionary containing ``column_headers`` for each ``NOTICE_MEDIA`` 
      and ``rows`` containing a list of dictionaries: ``notice_type``, a 
      :model:`notification.NoticeType` object and ``cells``, a list of 
      tuples whose first value is suitable for use in forms and the second 
      value is ``True`` or ``False`` depending on a ``request.POST`` 
      variable called ``form_label``, whose valid value is ``on``. 
    """ 
    notice_types = NoticeType.objects.all() 
    settings_table = [] 
    for notice_type in notice_types: 
     settings_row = [] 
     for medium_id, medium_display in NOTICE_MEDIA: 
      form_label = "%s_%s" % (notice_type.label, medium_id) 
      setting = get_notification_setting(request.user, notice_type, medium_id) 
      if request.method == "POST": 
       if request.POST.get(form_label) == "on": 
        if not setting.send: 
         setting.send = True 
         setting.save() 
       else: 
        if setting.send: 
         setting.send = False 
         setting.save() 
      settings_row.append((form_label, setting.send)) 
     settings_table.append({"notice_type": notice_type, "cells": settings_row}) 

    if request.method == "POST": 
     next_page = request.POST.get("next_page", ".") 
     return HttpResponseRedirect(next_page) 

    notice_settings = { 
     "column_headers": [medium_display for medium_id, medium_display in NOTICE_MEDIA], 
     "rows": settings_table, 
    } 

    return render_to_response("notification/notice_settings.html", { 
     "notice_types": notice_types, 
     "notice_settings": notice_settings, 
    }, context_instance=RequestContext(request)) 

답변

3

이보기에 대한 기본 템플릿이 GitHub의에 체크인 : https://github.com/pinax/pinax/blob/master/pinax/templates/default/notification/notice_settings.html

UPDATE를 : Pinax 자신의 테마를 제거 템플릿을 마지막으로 체크인은 여전히 ​​here를 찾을 수 있습니다.

는 설정 개체 알림에 대해 정의 된 형태가 없기 때문에 체크 박스 요소 (양식 자체가) 원시 HTML 사용하여 생성됩니다

<form method="POST" action=""> {# doubt this easy to do in uni-form #} 
     {% csrf_token %} 
     <table class="notice_settings"> 
      <tr> 
       <th>{% trans "Notification Type" %}</th> 
       {% for header in notice_settings.column_headers %} 
        <th>{{ header }}</th> 
       {% endfor %} 
      </tr> 
      {% for row in notice_settings.rows %} 
       <tr> 
        <td>{% trans row.notice_type.display %}<br/> 
         <span class="notice_type_description">{% trans row.notice_type.description %}</span> 
        </td> 
        {% for cell in row.cells %} 
         <td> 
          <input type="checkbox" name="{{ cell.0 }}" {% if cell.1 %}checked="yes"{% endif %}/> 
         </td> 
        {% endfor %} 
       </tr> 
      {% endfor %} 
      <tr> 
       <td><input type="submit" value="{% trans "Change" %}" /></td> 
      </tr> 
     </table> 
    </form> 
+0

네, 그게 더 비슷해. 그 형식의 을 추가해야합니다. –

0

당신이 보여 뷰에만 게시 된 통지의 처리를 관리하지만 페이지에서 양식의 표시하지. form_label이라는 필드가 포함 된 양식을 직접 만들고이보기에 게시하는 모든 페이지에 숨겨진 입력을 포함 할 수 있습니다.

+0

송신 방법 알림을 보내는입니다. 이것은 설정을위한 것입니다. – TIMEX

+0

네가 맞아, 나는 그 부분을 제거했다. –