Adam Knight avatar Adam Knight committed 1d95096

Database routing and import changes to support Drupal.

Comments (0)

Files changed (19)

comments/models.py

-# from django.db import models
+from django.db import models
 from django.contrib.comments.models import Comment
 from mptt.models import MPTTModel, TreeForeignKey
 
     """ Threaded comments - Add support for the parent comment store and MPTT traversal"""
     # a link to comment that is being replied, if one exists
     parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
+    title = models.CharField(max_length=200, null=True, blank=True)
 
     class MPTTMeta:
         # comments on one level will be ordered by date of creation

comments/templates/400-debug.html

+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+  <title>Comment post not allowed (400)</title>
+  <meta name="robots" content="NONE,NOARCHIVE" />
+  <style type="text/css">
+  <![CDATA[
+    html * { padding:0; margin:0; }
+    body * { padding:10px 20px; }
+    body * * { padding:0; }
+    body { font:small sans-serif; background:#eee; }
+    body>div { border-bottom:1px solid #ddd; }
+    h1 { font-weight:normal; margin-bottom:.4em; }
+    h1 span { font-size:60%; color:#666; font-weight:normal; }
+    table { border:none; border-collapse: collapse; width:100%; }
+    td, th { vertical-align:top; padding:2px 3px; }
+    th { width:12em; text-align:right; color:#666; padding-right:.5em; }
+    #info { background:#f6f6f6; }
+    #info ol { margin: 0.5em 4em; }
+    #info ol li { font-family: monospace; }
+    #summary { background: #ffc; }
+    #explanation { background:#eee; border-bottom: 0px none; }
+  ]]>
+  </style>
+</head>
+<body>
+  <div id="summary">
+    <h1>Comment post not allowed <span>(400)</span></h1>
+    <table class="meta">
+      <tr>
+        <th>Why:</th>
+        <td>{{ why }}</td>
+      </tr>
+    </table>
+  </div>
+  <div id="info">
+    <p>
+    The comment you tried to post to this view wasn't saved because something
+    tampered with the security information in the comment form. The message
+    above should explain the problem, or you can check the <a
+    href="http://docs.djangoproject.com/en/dev/ref/contrib/comments/">comment
+    documentation</a> for more help.
+    </p>
+  </div>
+
+  <div id="explanation">
+    <p>
+      You're seeing this error because you have <code>DEBUG = True</code> in
+      your Django settings file. Change that to <code>False</code>, and Django
+      will display a standard 400 error page.
+    </p>
+  </div>
+</body>
+</html>

comments/templates/approve.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Approve a comment" %}{% endblock %}
+
+{% block content %}
+  <h1>{% trans "Really make this comment public?" %}</h1>
+  <blockquote>{{ comment|linebreaks }}</blockquote>
+  <form action="." method="post">{% csrf_token %}
+    {% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
+    <p class="submit">
+      <input type="submit" name="submit" value="{% trans "Approve" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
+    </p>
+  </form>
+{% endblock %}

comments/templates/approved.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Thanks for approving" %}.{% endblock %}
+
+{% block content %}
+  <h1>{% trans "Thanks for taking the time to improve the quality of discussion on our site" %}.</h1>
+{% endblock %}

comments/templates/base.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>{% block title %}{% endblock %}</title>
+</head>
+<body>
+  {% block content %}{% endblock %}
+</body>
+</html>

comments/templates/comments.html

 {% endrecursetree %}
 {% endif %}
 
-{% render_comment_form for object %}
+{% if object.allow_comments == 2 %}
+{% render_comment_form for object %}
+{% endif %}

comments/templates/delete.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Remove a comment" %}{% endblock %}
+
+{% block content %}
+<h1>{% trans "Really remove this comment?" %}</h1>
+  <blockquote>{{ comment|linebreaks }}</blockquote>
+  <form action="." method="post">{% csrf_token %}
+    {% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
+    <p class="submit">
+    <input type="submit" name="submit" value="{% trans "Remove" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
+    </p>
+  </form>
+{% endblock %}

comments/templates/deleted.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Thanks for removing" %}.{% endblock %}
+
+{% block content %}
+  <h1>{% trans "Thanks for taking the time to improve the quality of discussion on our site" %}.</h1>
+{% endblock %}

comments/templates/flag.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Flag this comment" %}{% endblock %}
+
+{% block content %}
+<h1>{% trans "Really flag this comment?" %}</h1>
+  <blockquote>{{ comment|linebreaks }}</blockquote>
+  <form action="." method="post">{% csrf_token %}
+    {% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
+    <p class="submit">
+    <input type="submit" name="submit" value="{% trans "Flag" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
+    </p>
+  </form>
+{% endblock %}

comments/templates/flagged.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Thanks for flagging" %}.{% endblock %}
+
+{% block content %}
+  <h1>{% trans "Thanks for taking the time to improve the quality of discussion on our site" %}.</h1>
+{% endblock %}

comments/templates/list.html

+<dl id="comments">
+  {% for comment in comment_list %}
+    <dt id="c{{ comment.id }}">
+        {{ comment.submit_date }} - {{ comment.name }}
+    </dt>
+    <dd>
+        <p>{{ comment.comment }}</p>
+    </dd>
+  {% endfor %}
+</dl>

comments/templates/posted.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Thanks for commenting" %}.{% endblock %}
+
+{% block content %}
+  <h1>{% trans "Thank you for your comment" %}.</h1>
+{% endblock %}

comments/templates/preview.html

+{% extends "comments/base.html" %}
+{% load i18n %}
+
+{% block title %}{% trans "Preview your comment" %}{% endblock %}
+
+{% block content %}
+  {% load comments %}
+  <form action="{% comment_form_target %}" method="post">{% csrf_token %}
+    {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
+    {% if form.errors %}
+    <h1>{% blocktrans count counter=form.errors|length %}Please correct the error below{% plural %}Please correct the errors below{% endblocktrans %}</h1>
+    {% else %}
+    <h1>{% trans "Preview your comment" %}</h1>
+      <blockquote>{{ comment|linebreaks }}</blockquote>
+      <p>
+      {% trans "and" %} <input type="submit" name="submit" class="submit-post" value="{% trans "Post your comment" %}" id="submit" /> {% trans "or make changes" %}:
+      </p>
+    {% endif %}
+    {% for field in form %}
+      {% if field.is_hidden %}
+        <div>{{ field }}</div>
+      {% else %}
+        {% if field.errors %}{{ field.errors }}{% endif %}
+        <p
+          {% if field.errors %} class="error"{% endif %}
+          {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
+          {{ field.label_tag }} {{ field }}
+        </p>
+      {% endif %}
+    {% endfor %}
+    <p class="submit">
+    <input type="submit" name="submit" class="submit-post" value="{% trans "Post" %}" />
+    <input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
+    </p>
+  </form>
+{% endblock %}

drupal_support/management/commands/convertdrupal.py

                 raise CommandError("No Drupal nodes found in the current database.")
             
             # Create some sections
-            (blog_section, c) = Section.objects.get_or_create(name="blog")
+            (blog_section, c) = Section.objects.get_or_create(name="blog", slug="blog")
             if c:
                 if debug: print "* Created blog section."
                 blog_section.save()
             
-            (story_section, c) = Section.objects.get_or_create(name="story")
+            (story_section, c) = Section.objects.get_or_create(name="story", slug="story")
             if c:
                 if debug: print "* Created story section."
                 story_section.save()
                 
                 # Bring over the comments
                 comments = self.get_comments_for_node(node)
-                if debug: print "  Comments:", comments.all()
+                # if debug: print "  Comments:", comments.count()
                 for comment in comments:
                     if debug: print "  Importing comment: ", comment.thread, comment.subject
                     
         But, that's okay.  Drupal required MySQL anyway, so do the conversion on a copy of the DB there, then
         migrate to whatever else you want to use.
         '''
-        from django.db import connection
-        cursor = connection.cursor()
-        
-        cursor.execute("SELECT cid FROM comments as c WHERE nid = %s ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))", [node.nid])
-        rows = cursor.fetchall()
-        ids = [c[0] for c in rows]
-        comments = DrupalComment.objects.filter(pk__in=ids)
+        # from django.db import connection
+        # cursor = connection.cursor()
         
+        # cursor.execute("SELECT cid FROM comments as c WHERE nid = %s ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))", [node.nid])
+        # rows = cursor.fetchall()
+        # ids = [c[0] for c in rows]
+        # comments = DrupalComment.objects.filter(pk__in=ids)
+        raw_comments = DrupalComment.objects.raw("SELECT * FROM comments WHERE nid = %s ORDER BY SUBSTRING(comments.thread, 1, (LENGTH(comments.thread) - 1))", [node.nid])
+        comments = []
+        for comment in raw_comments:
+            comments.append(comment)
         return comments

drupal_support/routers.py

         return None
     
     def allow_syncdb(self, db, model):
-        if db == 'drupal'or model._meta.app_label == 'drupal_support':
+        if db == 'drupal' or model._meta.app_label == 'sitepoet.drupal_support':
+            print "DENY"
             return False
+        print "NO OPINION"
         return None

middleware/__init__.py

-from django.conf import settings
-from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect, HttpResponseGone, Http404
-from django.template import Template, RequestContext, loader
-
-from sitepoet.models import Redirect, Page, Story
-from sitepoet.views import view_page
-
-class RedirectionMiddleware(object):
-    def process_response(self, request, response):
-        # If the response found something, return it.
-        if response.status_code != 404:
-            return response
-        try:
-            # Look for an exact redirect
-            path = request.path
-            paths = [path]
-            
-            # Also try without the trailing slash if someone tacked it on for us
-            if settings.APPEND_SLASH:
-                paths.append(path[:path.rfind('/')] + path[path.rfind('/')+1:])
-            
-            r = Redirect.objects.get(site__id__exact=settings.SITE_ID, original__in=paths)
-            
-            # If the destination is not visible, let the 404 shine.
-            if hasattr(r.target_object, 'visible') and r.target_object.visible == False:
-                return response
-            
-            # If there's a redirect, process it
-            destination = r.destination()
-            
-            # If we're about to tell someone to go where we already are, stop and think...
-            if destination == request.path_info:
-                return response
-            
-            if destination == None:
-                # No destination means it's been removed, so make it a dead end.
-                context = RequestContext(request, {
-                    'title':'410 Gone',
-                    'content':'the resource you seek / has been taken by time / seek answers within'
-                })
-                template = loader.get_template("error.html")
-                return HttpResponseGone(template.render(context))
-            
-            if r.permanent == True:
-                # 301 Moved
-                return HttpResponsePermanentRedirect(destination)
-            else:
-                # 302 Found
-                return HttpResponseRedirect(destination)
-        
-        except Redirect.DoesNotExist, e:
-            # Otherwise, return the original response
-            return response
-        except:
-            if settings.DEBUG:
-                raise
-        # If we're here, we didn't catch something -- just pass along the 404.
-        return response
-
-
-class PageMiddleware(object):
-    def process_response(self, request, response):
-        # If the response found something, return it.
-        if response.status_code != 404:
-            return response
-        # Otherwise, see if we can get a response from the view
-        try:
-            return view_page(request, request.path_info)
-        # If the view couldn't find a page, then return the original response (don't pollute)
-        except Http404:
-            return response
-        # If anything else goes wrong here, just ignore it and return the original response (again, don't pollute)
-        except:
-            if settings.DEBUG:
-                raise
-            return response
+from page import *
+from redirection import *

middleware/page.py

+from django.conf import settings
+from django.http import Http404
+
+from sitepoet.models import Page
+from sitepoet.views import view_page
+
+
+class PageMiddleware(object):
+    def process_response(self, request, response):
+        # If the response found something, return it.
+        if response.status_code != 404:
+            return response
+        # Otherwise, see if we can get a response from the view
+        try:
+            return view_page(request, request.path_info)
+        # If the view couldn't find a page, then return the original response (don't pollute)
+        except Http404:
+            return response
+        # If anything else goes wrong here, just ignore it and return the original response (again, don't pollute)
+        except:
+            if settings.DEBUG:
+                raise
+            return response

middleware/redirection.py

+from django.conf import settings
+from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect, HttpResponseGone
+from django.template import RequestContext, loader
+from sitepoet.models import Redirect
+
+class RedirectionMiddleware(object):
+    def process_response(self, request, response):
+        # If the response found something, return it.
+        if response.status_code != 404:
+            return response
+        try:
+            # Look for an exact redirect
+            path = request.path
+            paths = [path]
+            
+            # Also try without the trailing slash if someone tacked it on for us
+            if settings.APPEND_SLASH:
+                paths.append(path[:path.rfind('/')] + path[path.rfind('/')+1:])
+            
+            r = Redirect.objects.get(site__id__exact=settings.SITE_ID, original__in=paths)
+            
+            # If the destination is not visible, let the 404 shine.
+            if hasattr(r.target_object, 'visible') and r.target_object.visible == False:
+                return response
+            
+            # If there's a redirect, process it
+            destination = r.destination()
+            
+            # If we're about to tell someone to go where we already are, stop and think...
+            if destination == request.path_info:
+                return response
+            
+            if destination == None:
+                # No destination means it's been removed, so make it a dead end.
+                context = RequestContext(request, {
+                    'title':'410 Gone',
+                    'content':'the resource you seek / has lost its battle with time / seek answers within'
+                })
+                template = loader.get_template("error.html")
+                return HttpResponseGone(template.render(context))
+            
+            if r.permanent == True:
+                # 301 Moved
+                return HttpResponsePermanentRedirect(destination)
+            else:
+                # 302 Found
+                return HttpResponseRedirect(destination)
+        
+        except Redirect.DoesNotExist, e:
+            # Otherwise, return the original response
+            return response
+        except:
+            if settings.DEBUG:
+                raise
+        # If we're here, we didn't catch something -- just pass along the 404.
+        return response
     def allow_commenting(self):
         return self.allow_comments == COMMENTS_ENABLED
     
+    def get_all_urls(self):
+        urls = [];
+        
+        if self.section:
+            section = self.section.slug
+        else:
+            section = None
+        
+        kwargs = {
+            'section': section,
+            'year':    self.date_published.year,
+            'month':   "%02d"%self.date_published.month,
+            'day':     "%02d"%self.date_published.day,
+            'slug':    self.slug,
+        }
+        
+        urls.append(reverse('story-detail', kwargs = kwargs))
+        
+        del kwargs['slug']
+        urls.append(reverse('story-archive', kwargs = kwargs))
+
+        del kwargs['day']
+        urls.append(reverse('story-archive', kwargs = kwargs))
+        
+        del kwargs['month']
+        urls.append(reverse('story-archive', kwargs = kwargs))
+        
+        del kwargs['year']
+        urls.append(reverse('story-archive', kwargs = kwargs))
+        
+        urls.append('/')
+        
+        return urls
+        
     def get_absolute_url(self):
         if self.section:
             section = self.section.slug
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.