1
|
|
|
from django.conf import settings |
2
|
|
|
from django.core.urlresolvers import reverse |
3
|
|
|
|
4
|
|
|
from simple_forums import models |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
def get_setting(setting_name, default=None): |
8
|
|
|
""" Get the specified setting. |
9
|
|
|
|
10
|
|
|
If the setting exists, it will be returned. Otherwise, the default |
11
|
|
|
value will be returned. |
12
|
|
|
""" |
13
|
|
|
settings_dict = getattr(settings, 'SIMPLE_FORUMS') |
14
|
|
|
|
15
|
|
|
if settings_dict: |
16
|
|
|
return settings_dict.get(setting_name, default) |
17
|
|
|
|
18
|
|
|
return default |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def thread_detail_url(pk=None, thread=None): |
22
|
|
|
""" Get the url of a thread's detail view. |
23
|
|
|
|
24
|
|
|
Uses either the thread's pk or the thread instance itself to |
25
|
|
|
determine the url of the thread's detail view. |
26
|
|
|
""" |
27
|
|
|
if pk is None and thread is None: |
28
|
|
|
raise ValueError("Either 'pk' or 'thread' must not be None") |
29
|
|
|
|
30
|
|
|
if pk: |
31
|
|
|
thread = models.Thread.objects.get(pk=pk) |
32
|
|
|
|
33
|
|
|
kwargs = { |
34
|
|
|
'topic_pk': thread.topic.pk, |
35
|
|
|
'topic_slug': thread.topic.slug, |
36
|
|
|
'thread_pk': thread.pk, |
37
|
|
|
'thread_slug': thread.slug, |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return reverse('thread-detail', kwargs=kwargs) |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def thread_list_url(topic_pk=None, topic=None): |
44
|
|
|
""" Get the url of the thread list view for a topic. |
45
|
|
|
|
46
|
|
|
Uses either the topic's pk or the topic instance itself to |
47
|
|
|
determine the url of the thread list view. |
48
|
|
|
""" |
49
|
|
|
if topic_pk is None and topic is None: |
50
|
|
|
raise ValueError("Either 'topic_pk' or 'topic' must not be None") |
51
|
|
|
|
52
|
|
|
if topic_pk: |
53
|
|
|
topic = models.Topic.objects.get(pk=topic_pk) |
54
|
|
|
|
55
|
|
|
kwargs = { |
56
|
|
|
'topic_pk': topic.pk, |
57
|
|
|
'topic_slug': topic.slug, |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return reverse('thread-list', kwargs=kwargs) |
61
|
|
|
|