Commit 816392ab14abcbb9e8b7eb3c846f691b0b26d34f
- Diff rendering mode:
- inline
- side by side
pm/forum/models.py
(9 / 0)
|   | |||
| 111 | 111 | ||
| 112 | 112 | forum.last_post = p | |
| 113 | 113 | forum.save() | |
| 114 | |||
| 115 | def can_read_forum(forum, user): | ||
| 116 | return user.is_staff or not topic.forum.staff_only | ||
| 117 | |||
| 118 | def can_read_topic(topic, user): | ||
| 119 | return can_read_forum(topic.forum, user) | ||
| 120 | |||
| 121 | def can_write_topic(topic, user): | ||
| 122 | return can_read_topic(topic, user) and not topic.is_closed |
pm/forum/views.py
(42 / 49)
|   | |||
| 39 | 39 | {'topics' : topics, 'forum': forum, | |
| 40 | 40 | 'pages': pages}) | |
| 41 | 41 | ||
| 42 | |||
| 43 | def render_topic(request, topic, page, args={}): | ||
| 44 | if not can_read_topic(topic, request.user): | ||
| 45 | raise Http404 | ||
| 46 | |||
| 47 | if request.user.is_authenticated(): | ||
| 48 | if never_read(topic): | ||
| 49 | mark_read(topic) | ||
| 50 | |||
| 51 | postq = topic.post_set.order_by('creation') | ||
| 52 | tail = postq[1:] | ||
| 53 | head = postq[0] | ||
| 54 | utiles = postq.filter(is_helpful=True) | ||
| 42 | 55 | ||
| 56 | pages, post_set, nb = paginate(tail, page = page) | ||
| 57 | |||
| 58 | id_page = page | ||
| 59 | if page == None: | ||
| 60 | id_page = 1 | ||
| 61 | if page == None and 'page' in request.GET: | ||
| 62 | try: | ||
| 63 | id_page = int(request.GET['page']) | ||
| 64 | except: | ||
| 65 | pass | ||
| 66 | |||
| 67 | forums = Forum.objects.order_by('position') | ||
| 68 | |||
| 69 | targs = {'topic' : topic, 'head' : head, 'tail' : post_set, | ||
| 70 | 'forums': forums, 'pages': pages, 'utiles' : utiles, | ||
| 71 | 'id_page': id_page, 'nb': nb | ||
| 72 | } | ||
| 73 | targs.update(args) | ||
| 74 | |||
| 75 | |||
| 76 | return render_template('forum/topic.html', targs) | ||
| 77 | |||
| 78 | |||
| 79 | |||
| 43 | 80 | def topic(request, topic_id, slug, page = None): | |
| 44 | 81 | try: | |
| 45 | 82 | topic = get_topic(topic_id) | |
| … | … | ||
| 86 | 86 | if not slug == slugify(topic): | |
| 87 | 87 | return redirect(topic.get_absolute_url()) | |
| 88 | 88 | ||
| 89 | if not request.user.is_staff and topic.forum.staff_only == True: | ||
| 90 | raise Http404 | ||
| 91 | else: | ||
| 92 | if request.user.is_authenticated(): | ||
| 93 | if never_read(topic): | ||
| 94 | mark_read(topic) | ||
| 95 | postq = topic.post_set.order_by('creation') | ||
| 96 | tail = postq[1:] | ||
| 97 | head = postq[0] | ||
| 98 | utiles = postq.filter(is_helpful=True) | ||
| 99 | |||
| 100 | pages, post_set, nb = paginate(tail, page = page) | ||
| 101 | |||
| 102 | id_page = page | ||
| 103 | if page == None: | ||
| 104 | id_page = 1 | ||
| 105 | if page == None and 'page' in request.GET: | ||
| 106 | try: | ||
| 107 | id_page = int(request.GET['page']) | ||
| 108 | except: | ||
| 109 | pass | ||
| 110 | |||
| 111 | forums = Forum.objects.order_by('position') | ||
| 112 | |||
| 113 | return render_template('forum/topic.html', | ||
| 114 | {'topic' : topic, | ||
| 115 | 'head' : head, | ||
| 116 | 'tail' : post_set, | ||
| 117 | 'forums': forums, | ||
| 118 | 'pages': pages, | ||
| 119 | 'utiles' : utiles, | ||
| 120 | 'id_page': id_page, | ||
| 121 | 'nb': nb}) | ||
| 89 | return render_topic(request, topic, page, {}) | ||
| 122 | 90 | ||
| 123 | 91 | ||
| 124 | 92 | def export(request, topic_id,slug): | |
| … | … | ||
| 98 | 98 | return render_template('forum/export.html',{'posts':postq}) | |
| 99 | 99 | ||
| 100 | 100 | @login_required | |
| 101 | def reply(request, topic_id): | ||
| 101 | def reply(request, topic_id, page = None): | ||
| 102 | 102 | try: | |
| 103 | 103 | t = get_topic(topic_id) | |
| 104 | 104 | except Topic.DoesNotExist: | |
| … | … | ||
| 106 | 106 | ||
| 107 | 107 | texte = "" | |
| 108 | 108 | preview = False | |
| 109 | if not request.user.is_staff and t.forum.staff_only == True: | ||
| 109 | if not can_write_topic(t, request.user): | ||
| 110 | 110 | raise Http404 | |
| 111 | 111 | ||
| 112 | post_set = t.post_set.all() | ||
| 113 | head = post_set[0] | ||
| 114 | try: | ||
| 115 | tail = post_set[1:] | ||
| 116 | except IndexError: | ||
| 117 | tail = [] | ||
| 118 | |||
| 119 | nb = post_set.all().count() | ||
| 120 | |||
| 121 | 112 | if request.method == 'POST' and request.POST['texte']: | |
| 122 | 113 | texte = request.POST['texte'] | |
| 123 | 114 | if "preview" in request.POST: | |
| … | … | ||
| 133 | 133 | t.save() | |
| 134 | 134 | return redirect(p.get_absolute_url()) | |
| 135 | 135 | else: | |
| 136 | return render_template('forum/topic.html', {'topic' : t, | ||
| 137 | 'head': head, 'tail': tail,'nb':nb, 'error':u"Votre réponse est vide !"}) | ||
| 136 | return render_topic(request, t, page, {'error':u"Votre réponse est vide !"}) | ||
| 138 | 137 | ||
| 139 | return render_template('forum/topic.html', {'topic' : t, | ||
| 140 | 'texte': texte, 'preview': preview, | ||
| 141 | 'head': head, 'tail': tail,'nb':nb}) | ||
| 138 | return render_topic(request, t, page, {'texte': texte, 'preview': preview}) | ||
| 142 | 139 | ||
| 143 | 140 | @login_required | |
| 144 | 141 | def new(request, forum_id): |
pm/settings.py
(1 / 1)
|   | |||
| 2 | 2 | import os | |
| 3 | 3 | import locale | |
| 4 | 4 | ||
| 5 | locale.setlocale(locale.LC_TIME, 'fr_FR.utf-8') | ||
| 5 | locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') | ||
| 6 | 6 | ||
| 7 | 7 | DEBUG = True | |
| 8 | 8 | TEMPLATE_DEBUG = DEBUG |
public/assets/css/style.css
(1 / 1)
|   | |||
| 286 | 286 | .deplacer { display : inline ;} | |
| 287 | 287 | .deplacer select { background-color : white; border : 1px solid grey; border-radius : 3px; -moz-border-radius : 3px;} | |
| 288 | 288 | input { border : 1px solid grey; /* border-radius : 3px; -moz-border-radius : 3px; */} | |
| 289 | input[type="submit"] { background-color : #EEE; border-radius : 3px; } | ||
| 289 | input[type="submit"] { background-color : #EEE; border-radius : 3px; cursor: pointer;} | ||
| 290 | 290 | ||
| 291 | 291 | .haut-topic { padding-bottom : 10px; } |
templates/forum/topic.html
(1 / 1)
|   | |||
| 115 | 115 | </ul> | |
| 116 | 116 | {% endif %} | |
| 117 | 117 | {% if user.is_authenticated %} | |
| 118 | <form action="{% url forum.views.reply topic_id=topic.id%}#view-post" method="POST"> | ||
| 118 | <form action="{% url forum.views.reply topic_id=topic.id %}?page={{ id_page }}#view-post" method="POST"> | ||
| 119 | 119 | <p><textarea name="texte" rows="10" cols="50">{{ texte }}</textarea></p> | |
| 120 | 120 | <p><input type="submit" value="Envoyer" /> <input type="submit" name="preview" value="Aperçu" /></p> | |
| 121 | 121 | </form> |

