~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/views.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
from pybb.util import render_to, paged, build_form, quote_text, paginate, set_language, ajax, urlize
16
16
from pybb.models import Category, Forum, Topic, Post, PrivateMessage, Attachment,\
17
 
                        MARKUP_CHOICES
 
17
    MARKUP_CHOICES
18
18
from pybb.forms import AddPostForm, EditPostForm, UserSearchForm
19
19
from pybb import settings as pybb_settings
20
20
from pybb.orm import load_related
26
26
except ImportError:
27
27
    notification = None
28
28
 
 
29
 
29
30
def index_ctx(request):
30
31
    quick = {'posts': Post.objects.count(),
31
32
             'topics': Topic.objects.count(),
47
48
    quick = {'posts': category.posts.count(),
48
49
             'topics': category.topics.count(),
49
50
             'last_topics': category.topics.select_related()[:pybb_settings.QUICK_TOPICS_NUMBER],
50
 
             'last_posts': category.posts.order_by('-created').select_related()\
51
 
                [:pybb_settings.QUICK_POSTS_NUMBER],
 
51
             'last_posts': category.posts.order_by('-created').select_related()
 
52
             [:pybb_settings.QUICK_POSTS_NUMBER],
52
53
             }
53
54
    return {'category': category,
54
55
            'quick': quick,
62
63
    quick = {'posts': forum.post_count,
63
64
             'topics': forum.topics.count(),
64
65
             'last_topics': forum.topics.all().select_related()[:pybb_settings.QUICK_TOPICS_NUMBER],
65
 
             'last_posts': forum.posts.order_by('-created').select_related()\
66
 
                [:pybb_settings.QUICK_POSTS_NUMBER],
 
66
             'last_posts': forum.posts.order_by('-created').select_related()
 
67
             [:pybb_settings.QUICK_POSTS_NUMBER],
67
68
             }
68
69
 
69
 
    topics = forum.topics.order_by('-sticky', '-updated').exclude(posts__hidden=True).select_related()
 
70
    topics = forum.topics.order_by(
 
71
        '-sticky', '-updated').exclude(posts__hidden=True).select_related()
70
72
    page, paginator = paginate(topics, request, pybb_settings.FORUM_PAGE_SIZE)
71
 
    
 
73
 
72
74
    return {'forum': forum,
73
75
            'topics': page.object_list,
74
76
            'quick': quick,
86
88
    topic.views += 1
87
89
    topic.save()
88
90
 
89
 
 
90
91
    if request.user.is_authenticated():
91
92
        topic.update_read(request.user)
92
93
 
98
99
 
99
100
    initial = {}
100
101
    if request.user.is_authenticated():
101
 
        initial = {'markup': "markdown" }
 
102
        initial = {'markup': 'markdown'}
102
103
    form = AddPostForm(topic=topic, initial=initial)
103
104
 
104
105
    moderator = (request.user.is_superuser or
153
154
        quote = ''
154
155
    else:
155
156
        post = get_object_or_404(Post, pk=quote_id)
156
 
        quote = quote_text(post.body, post.user, "markdown")
 
157
        quote = quote_text(post.body, post.user, 'markdown')
157
158
 
158
159
    form = build_form(AddPostForm, request, topic=topic, forum=forum,
159
160
                      user=request.user, ip=get_real_ip(request),
160
 
                      initial={'markup': "markdown", 'body': quote})
 
161
                      initial={'markup': 'markdown', 'body': quote})
161
162
 
162
163
    if form.is_valid():
163
164
        post = form.save()
196
197
    post = get_object_or_404(Post, pk=post_id)
197
198
    count = post.topic.posts.filter(created__lt=post.created).count() + 1
198
199
    page = math.ceil(count / float(pybb_settings.TOPIC_PAGE_SIZE))
199
 
    url = '%s?page=%d#post-%d' % (reverse('pybb_topic', args=[post.topic.id]), page, post.id)
 
200
    url = '%s?page=%d#post-%d' % (reverse('pybb_topic',
 
201
                                          args=[post.topic.id]), page, post.id)
200
202
    return HttpResponseRedirect(url)
201
203
 
202
204
 
251
253
 
252
254
    allowed = False
253
255
    if request.user.is_superuser or\
254
 
        request.user in post.topic.forum.moderators.all() or \
255
 
        (post.user == request.user and post == last_post):
 
256
            request.user in post.topic.forum.moderators.all() or \
 
257
            (post.user == request.user and post == last_post):
256
258
        allowed = True
257
259
 
258
260
    if not allowed:
332
334
    return HttpResponseRedirect(reverse('pybb_topic', args=[topic.id]))
333
335
 
334
336
 
335
 
 
336
337
@login_required
337
338
def show_attachment(request, hash):
338
339
    attachment = get_object_or_404(Attachment, hash=hash)
360
361
    html = urlize(html)
361
362
    return {'content': html}
362
363
 
 
364
 
363
365
def pybb_moderate_info(request):
364
366
    return render(request, 'pybb/pybb_moderate_info.html')