Browse Source

Merge pull request #70 from rafalp/develop

Merging in tweaks and fixes from develop
Rafał Pitoń 12 years ago
parent
commit
cf7f9f1c1a

+ 3 - 0
misago/apps/privatethreads/mixins.py

@@ -6,6 +6,9 @@ from misago.acl.exceptions import ACLError404
 class TypeMixin(object):
     type_prefix = 'private_thread'
 
+    def type_available(self):
+        return self.request.settings['enable_private_threads']
+
     def check_permissions(self):
         try:
             if self.thread.pk:

+ 7 - 0
misago/apps/threadtype/base.py

@@ -9,6 +9,13 @@ class ViewBase(object):
         obj = super(ViewBase, cls).__new__(cls)
         return obj(request, **kwargs)
         
+    def _type_available(self):
+        try:
+            if not self.type_available():
+                raise Http404()
+        except AttributeError:
+            pass
+
     def set_forum_context(self):
         pass
 

+ 1 - 0
misago/apps/threadtype/changelog.py

@@ -36,6 +36,7 @@ class ChangelogBaseView(ViewBase):
         self.post = None
         self.parents = []
         try:
+            self._type_available()
             self.fetch_target()
             self._check_permissions()
             if not request.user.is_authenticated():

+ 1 - 0
misago/apps/threadtype/delete.py

@@ -30,6 +30,7 @@ class DeleteHideBaseView(ViewBase):
         self.kwargs = kwargs
         self.parents = []
         try:
+            self._type_available()
             self._set_context()
             self._check_permissions()
             self.delete()

+ 1 - 0
misago/apps/threadtype/details.py

@@ -26,6 +26,7 @@ class ExtraBaseView(ViewBase):
         self.post = None
         self.parents = []
         try:
+            self._type_available()
             self.fetch_target()
             self.check_acl()
             self._check_permissions()

+ 1 - 0
misago/apps/threadtype/jumps.py

@@ -30,6 +30,7 @@ class JumpView(ViewBase):
         self.request = request
         self.parents = []
         try:
+            self._type_available()
             self.fetch_thread(thread)
             if self.forum.level:
                 self.parents = Forum.objects.forum_parents(self.forum.pk, True)

+ 1 - 0
misago/apps/threadtype/list/views.py

@@ -94,6 +94,7 @@ class ThreadsListBaseView(ViewBase):
         self.threads = []
         self.message = request.messages.get_message('threads')
         try:
+            self._type_available()
             self._fetch_forum()
             self._check_permissions()
             self.fetch_threads()

+ 1 - 0
misago/apps/threadtype/posting/base.py

@@ -80,6 +80,7 @@ class PostingBaseView(ViewBase):
         form = None
 
         try:
+            self._type_available()
             self._set_context()
             self.check_forum_type()
             self._check_permissions()

+ 1 - 0
misago/apps/threadtype/thread/views.py

@@ -169,6 +169,7 @@ class ThreadBaseView(ViewBase):
         self.watcher = False
         self.message = request.messages.get_message('threads')
         try:
+            self._type_available()
             self.fetch_thread()
             self.check_forum_type()
             self._check_permissions()

+ 4 - 1
misago/apps/watchedthreads/views.py

@@ -13,7 +13,10 @@ from misago.utils.pagination import make_pagination
 @block_guest
 def watched_threads(request, page=0, new=False):
     # Find mode and fetch threads
-    queryset = WatchedThread.objects.filter(user=request.user).filter(forum_id__in=Forum.objects.readable_forums(request.acl, True)).select_related('thread').filter(thread__moderated=False).filter(thread__deleted=False)
+    readable_forums = Forum.objects.readable_forums(request.acl, True)
+    if not request.settings['enable_private_threads']:
+        readable_forums.remove(Forum.objects.special_pk('private_threads'))
+    queryset = WatchedThread.objects.filter(user=request.user).filter(forum_id__in=readable_forums).select_related('thread').filter(thread__moderated=False).filter(thread__deleted=False)
     if new:
         queryset = queryset.filter(last_read__lt=F('thread__last'))
     count = queryset.count()

+ 22 - 17
static/cranefly/js/cranefly.js

@@ -92,14 +92,12 @@ function EnhancePostsMD() {
 		// Automagically turn links into players
 		var players = new Array();
 		$('.markdown.js-extra a').each(function() {
-			if (this.href == $.trim($(this).text())) {
-				match = link2player(this);
-				if (match && $.inArray(match, players) == -1) {
-					players.push(match);
-					$(this).replaceWith(match);
-					if (players.length == 10) {
-						return false;
-					}
+			match = link2player($.trim($(this).text()));
+			if (match && $.inArray(match, players) == -1) {
+				players.push(match);
+				$(this).replaceWith(match);
+				if (players.length == 10) {
+					return false;
 				}
 			}
 		});
@@ -107,18 +105,25 @@ function EnhancePostsMD() {
 }
 
 // Turn link to player
-function link2player(link) {
+function link2player(link_href) {
 	// Youtube link
 	var re = /watch\?v=((\w|-)+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
+		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
+	}
+
+	// Youtube feature=embed
+	var re = /watch\?feature=player_embedded&v=((\w|-)+)/;
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 	}
 
 	// Youtube embed with start time
 	var re = /youtu.be\/((\w|-)+)\?t=([A-Za-z0-9]+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		media_minutes = media_url[2].match(/([0-9]+)m/);
 		media_seconds = media_url[2].match(/([0-9]+)s/);
 		media_url[2] = 0;
@@ -129,15 +134,15 @@ function link2player(link) {
 	
 	// Youtube embed
 	var re = /youtu.be\/((\w|-)+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 	}
 
 	// Vimeo link
 	var re = /vimeo.com\/([0-9]+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe src="http://player.vimeo.com/video/' + media_url[1] + '?color=CF402E" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
 	}
 

+ 1 - 1
templates/cranefly/category.html

@@ -44,7 +44,7 @@
               <div class="thread-name">
                 <a href="{% url 'thread_new' thread=forum.last_thread_id, slug=forum.last_thread_slug %}"{% if forum.last_thread_name|length > 36 %} class="tooltip-top" title="{{ forum.last_thread_name }}"{% endif %}>{{ forum.last_thread_name|short_string(36) }}</a>
               </div>
-              <div class="muted">{% if forum.last_poster_id %}<a href="{% url 'user' user=forum.last_poster_id, username=forum.last_poster_slug %}" class="last-poster">{{ forum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ forum.last_poster_name }}</span>{% endif %} - {{ forum.last_thread_date|reldate }}</div>
+              <div class="muted">{% if forum.last_poster_id %}<a href="{% url 'user' user=forum.last_poster_id, username=forum.last_poster_slug %}" class="last-poster">{{ forum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ forum.last_poster_name }}</span>{% endif %} - {{ forum.last_thread_date|reltimesince }}</div>
               {%- else -%}
               <em>{% trans %}This forum is empty{% endtrans %}</em>
               {%- endif %}

+ 1 - 1
templates/cranefly/index.html

@@ -30,7 +30,7 @@
                   <div class="thread-name">
                     <a href="{% url 'thread_new' thread=forum.last_thread_id, slug=forum.last_thread_slug %}"{% if forum.last_thread_name|length > 36 %} class="tooltip-top" title="{{ forum.last_thread_name }}"{% endif %}>{{ forum.last_thread_name|short_string(36) }}</a>
                   </div>
-                  <div class="muted">{% if forum.last_poster_id %}<a href="{% url 'user' user=forum.last_poster_id, username=forum.last_poster_slug %}" class="last-poster">{{ forum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ forum.last_poster_name }}</span>{% endif %} - {{ forum.last_thread_date|reldate }}</div>
+                  <div class="muted">{% if forum.last_poster_id %}<a href="{% url 'user' user=forum.last_poster_id, username=forum.last_poster_slug %}" class="last-poster">{{ forum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ forum.last_poster_name }}</span>{% endif %} - {{ forum.last_thread_date|reltimesince }}</div>
                   {%- else -%}
                   <em>{% trans %}This forum is empty{% endtrans %}</em>
                   {%- endif %}

+ 1 - 1
templates/cranefly/layout.html

@@ -51,7 +51,7 @@
         <ul class="nav navbar-blocks pull-right">
           <li class="user-profile"><a href="{% url 'user' user=user.id, username=user.username_slug %}" title="{% trans %}Go to your profile{% endtrans %}" class="tooltip-bottom"><div><img src="{{ user.get_avatar(28) }}" alt=""> {{ user.username }}</div></a></li>
           <li><a href="{% url 'alerts' %}" title="{% if user.alerts %}{% trans %}You have new notifications!{% endtrans %}{% else %}{% trans %}Your Notifications{% endtrans %}{% endif %}" class="tooltip-bottom"><i class="icon-asterisk"></i>{% if user.alerts %}<span class="label label-important">{{ user.alerts }}</span>{% endif %}</a></li>
-          {% if settings.enable_private_threads and acl.forums.can_browse(private_threads) and acl.threads.can_read_threads(private_threads) %}
+          {% if settings.enable_private_threads and acl.private_threads.can_participate() %}
           <li><a href="{% url 'private_threads' %}" title="{% if user.unread_pds %}{% trans %}There are unread Private Threads!{% endtrans %}{% else %}{% trans %}Your Private Threads{% endtrans %}{% endif %}" class="tooltip-bottom"><i class="icon-inbox"></i>{% if user.unread_pds %}<span class="label label-important">{{ user.unread_pds }}</span>{% endif %}</a></li>
           {% endif %}
           <li><a href="{% url 'newsfeed' %}" title="{% trans %}Your News Feed{% endtrans %}" class="tooltip-bottom"><i class="icon-signal"></i></a></li>

+ 1 - 1
templates/cranefly/private_threads/list.html

@@ -57,7 +57,7 @@
             {%- endif %}"><i class="icon-comment"></i></a>
             <a href="{% url 'private_thread' thread=thread.pk, slug=thread.slug %}" class="thread-name">{{ thread.name }}</a>
             <span class="thread-details">
-              {% trans user=thread_starter(thread), start=thread.start|reldate|low %}by {{ user }} {{ start }}{% endtrans %}
+              {% trans user=thread_starter(thread), start=thread.start|reltimesince|low %}by {{ user }} {{ start }}{% endtrans %}
             </span>
             <ul class="unstyled thread-flags">
               {% if thread.replies_reported %}

+ 6 - 2
templates/cranefly/private_threads/posting.html

@@ -138,7 +138,7 @@
 {% macro get_info() -%}
 {% if action == 'edit_reply' -%}
     {% if post.moderated %}<li><i class="icon-eye-close"></i> {% trans %}Not Reviewed{% endtrans %}</li>{% endif %}
-    <li><i class="icon-time"></i> {{ post.date|reltimesince }}</li>
+    <li><i class="icon-time"></i> <a href="{% url 'private_thread_find' thread=thread.pk, slug=thread.slug, post=post.pk %}">{{ post.date|reltimesince }}</a></li>
     <li><i class="icon-user"></i> {% if post.user %}<a href="{% url 'user' user=post.user.pk, username=post.user.username_slug %}">{{ post.user.username }}</a>{% else %}{{ post.user_name }}{% endif %}</li>
     <li><i class="icon-pencil"></i> {% if post.edits > 0 -%}
       {% trans count=post.edits %}One edit{% pluralize %}{{ count }} edits{% endtrans %}
@@ -147,7 +147,11 @@
     {%- endif %}</li>
 {%- else -%}
     {% if thread.moderated %}<li><i class="icon-eye-close"></i> {% trans %}Not Reviewed{% endtrans %}</li>{% endif %}
-    <li><i class="icon-time"></i> {{ thread.last|reltimesince }}</li>
+    {% if action == 'edit_thread' %}
+    <li><i class="icon-time"></i> <a href="{% url 'private_thread_find' thread=thread.pk, slug=thread.slug, post=thread.start_post_id %}">{{ thread.start|reltimesince }}</a></li>
+    {% else %}
+    <li><i class="icon-time"></i> <a href="{% url 'private_thread_new' thread=thread.pk, slug=thread.slug %}">{{ thread.last|reltimesince }}</a></li>
+    {% endif %}
     <li><i class="icon-user"></i> {% if thread.start_poster_id %}<a href="{% url 'user' user=thread.start_poster_id, username=thread.start_poster_slug %}">{{ thread.start_poster_name }}</a>{% else %}{{ thread.start_poster_name }}{% endif %}</li>
     <li><i class="icon-comment"></i> {% if thread.replies > 0 -%}
       {% trans count=thread.replies, replies=thread.replies|intcomma %}One reply{% pluralize %}{{ replies }} replies{% endtrans %}

+ 2 - 2
templates/cranefly/threads/list.html

@@ -48,7 +48,7 @@
               <div class="thread-name">
                 <a href="{% url 'thread_new' thread=subforum.last_thread_id, slug=subforum.last_thread_slug %}"{% if subforum.last_thread_name|length > 36 %} class="tooltip-top" title="{{ subforum.last_thread_name }}"{% endif %}>{{ subforum.last_thread_name|short_string(36) }}</a>
               </div>
-              <div class="muted">{% if subforum.last_poster_id %}<a href="{% url 'user' user=subforum.last_poster_id, username=subforum.last_poster_slug %}" class="last-poster">{{ subforum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ subforum.last_poster_name }}</span>{% endif %} - {{ subforum.last_thread_date|reldate }}</div>
+              <div class="muted">{% if subforum.last_poster_id %}<a href="{% url 'user' user=subforum.last_poster_id, username=subforum.last_poster_slug %}" class="last-poster">{{ subforum.last_poster_name }}</a>{% else %}<span class="last-poster">{{ subforum.last_poster_name }}</span>{% endif %} - {{ subforum.last_thread_date|reltimesince }}</div>
               {%- else -%}
               <em>{% trans %}This forum is empty{% endtrans %}</em>
               {%- endif %}
@@ -129,7 +129,7 @@
             {%- endif %}"><i class="icon-comment"></i></a>
             <a href="{% url 'thread' thread=thread.pk, slug=thread.slug %}" class="thread-name">{{ thread.name }}</a>
             <span class="thread-details">
-              {% trans user=thread_starter(thread), start=thread.start|reldate|low %}by {{ user }} {{ start }}{% endtrans %}
+              {% trans user=thread_starter(thread), start=thread.start|reltimesince|low %}by {{ user }} {{ start }}{% endtrans %}
             </span>
             <ul class="unstyled thread-flags">
               {% if thread.replies_reported %}

+ 6 - 2
templates/cranefly/threads/posting.html

@@ -147,7 +147,7 @@
 {% macro get_info() -%}
 {% if action == 'edit_reply' -%}
     {% if post.moderated %}<li><i class="icon-eye-close"></i> {% trans %}Not Reviewed{% endtrans %}</li>{% endif %}
-    <li><i class="icon-time"></i> {{ post.date|reltimesince }}</li>
+    <li><i class="icon-time"></i> <a href="{% url 'thread_find' thread=thread.pk, slug=thread.slug, post=post.pk %}">{{ post.date|reltimesince }}</a></li>
     <li><i class="icon-user"></i> {% if post.user %}<a href="{% url 'user' user=post.user.pk, username=post.user.username_slug %}">{{ post.user.username }}</a>{% else %}{{ post.user_name }}{% endif %}</li>
     <li><i class="icon-pencil"></i> {% if post.edits > 0 -%}
       {% trans count=post.edits %}One edit{% pluralize %}{{ count }} edits{% endtrans %}
@@ -156,7 +156,11 @@
     {%- endif %}</li>
 {%- else -%}
     {% if thread.moderated %}<li><i class="icon-eye-close"></i> {% trans %}Not Reviewed{% endtrans %}</li>{% endif %}
-    <li><i class="icon-time"></i> {{ thread.last|reltimesince }}</li>
+    {% if action == 'edit_thread' %}
+    <li><i class="icon-time"></i> <a href="{% url 'thread_find' thread=thread.pk, slug=thread.slug, post=thread.start_post_id %}">{{ thread.start|reltimesince }}</a></li>
+    {% else %}
+    <li><i class="icon-time"></i> <a href="{% url 'thread_new' thread=thread.pk, slug=thread.slug %}">{{ thread.last|reltimesince }}</a></li>
+    {% endif %}
     <li><i class="icon-user"></i> {% if thread.start_poster_id %}<a href="{% url 'user' user=thread.start_poster_id, username=thread.start_poster_slug %}">{{ thread.start_poster_name }}</a>{% else %}{{ thread.start_poster_name }}{% endif %}</li>
     <li><i class="icon-comment"></i> {% if thread.replies > 0 -%}
       {% trans count=thread.replies, replies=thread.replies|intcomma %}One reply{% pluralize %}{{ replies }} replies{% endtrans %}