Latest 100 public snipts »
patrickbeeson's
snipts
showing 1-11 of 11 snipts
-
∞ ellington mailform HTML
<form action="/mailform/formtest/" method="POST" enctype="multipart/form-data" id="emailform_attachement"> <fieldset> <input type="hidden" name="_required" value="id_name, id_email, id_phone_number, id_message" /> <p><label for="id_name">Your name:</label> <input type="text" id="id_name" name="id_name" /></p> <p><label for="id_email">Your e-mail:</label> <input type="text" id="id_email" name="id_email" /></p> <p><label for="id_phone_number">Your phone number:</label> <input type="text" name="id_phone_number" id="id_phone_number" /></p> <p class="optional"><label for="id_resume">Your resume:</label> <input type="file" name="id_resume" id="id_resume" /></p> <p><label for="id_message">Your message:</label> <textarea id="id_message" name="id_message" rows="10" cols="40"></textarea></p> <p id="form_submit"><input type="submit" value="Submit your message" /></p> </fieldset> </form>
-
∞ feed template for publish2 links staff
<h2>Currently reading</h2> <ul class="bucket_list"> {% for itm in rss.items %} <li><strong><a href="{{itm.link}}">{{itm.title}}</strong></a></li> {% endfor %} </ul>
-
∞ publish2 links on staff profile mod
{% load libSet %} {% set as publish2_links %}http://www.publish2.com/journalists/{{ staffmember.slug }}/links/rss/{% endset %} {% load libRSS %} {% templaterss src=publish2_links template=feeds/publish2_rss_links max_entries=5 %}
-
∞ aggregate publish2 links on staff profile
{% load libSet %} {% set as publish2_links %}http://www.publish2.com/journalists/{{ staffmember.slug }}/links/rss/{% endset %} {% load libRSS %} <h2>Currently reading</h2> <p>These are some of the things {{ staffmember.first_name }} finds interesting from around the Web. <a href="http://www.publish2.com/journalists/{{ staffmember.slug }}/links/">See more links on Publish2</a>.</p> {% templaterss src=publish2_links template=feeds/rss_heads max_entries=5 %}
-
∞ Django blog entry model
class Entry(models.Model): # Status options CLOSED_STATUS = 1 EDITING_STATUS = 2 LIVE_STATUS = 3 STATUS_CHOICES = ( (CLOSED_STATUS, 'Closed'), (EDITING_STATUS, 'Editing'), (LIVE_STATUS, 'Public'), ) # Title and slug fields title = models.CharField(max_length=200, help_text='This field will populate the slug field. Maximum 200 characters.') slug = models.SlugField(unique_for_date='pub_date') # Summary and body fields summary = models.TextField(help_text='Please use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.') body = models.TextField(help_text='Please use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.') # Markdown conversion for summary and body fields summary_html = models.TextField(editable=False, blank=True) body_html = models.TextField(editable=False, blank=True) # Tag field tags = models.ManyToManyField(Tag, blank=True) # Meta fields meta_keywords = models.CharField(blank=True, max_length=300, help_text='Comma-separated list of keyworks for this entry. Maximum 300 characters.') meta_description = models.CharField(blank=True, max_length=400, help_text='A brief description of this entry. Maximum 400 characters.') # Image field centerpiece_image = models.ForeignKey(Photo, blank=True, null=True) # Response link field response_link = models.ForeignKey(Link, blank=True, null=True) # Date fields pub_date = models.DateTimeField(default=datetime.datetime.now) update = models.DateTimeField(blank=True, editable=True, auto_now=False, null=True) # Author field author = models.ForeignKey(User) # Enable comments field enable_comments = models.BooleanField(default=True) # Entry status field status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, default=EDITING_STATUS) # Entry managers objects = models.Manager() live = LiveEntryManager() #objects = ManagerWithPublished() class Meta: ordering = ['-pub_date'] verbose_name_plural = 'entries' def __unicode__(self): return self.title def save(self): self.summary_html = markdown(self.summary) self.body_html = markdown(self.body) super(Entry, self).save() try: ping_google() except Exception: pass def get_absolute_url(self): return '/blog/%s/%s/' % (self.pub_date.strftime('%Y/%b/%d').lower(), self.slug) @property def comments_expired(self): delta = datetime.datetime.now() - self.pub_date return delta.days < 60
-
∞ RSS feed for comments on a Django blog entry.
class CommentsForEntry(Feed): def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist return Entry.objects.get(slug__exact=bits[0]) def title(self, obj): return "Comments posted on the entry %s | %s" % (obj.title, current_site.name) def link(self, obj): if not obj: raise FeedDoesNotExist return obj.get_absolute_url() def description(self, obj): return "Comments posted on the entry %s" % obj.title def items(self, obj): return Comment.objects.for_model(obj).filter(is_public=True).order_by('-submit_date')[:15]
-
∞ Script to remove bad comments from the database.
import os import time import optparse import datetime def delete_spam_comments(verbose=False): from django.contrib.comments.models import Comment spam_comments = Comment.objects.filter(is_public=False) deleted_count = spam_comments.count() for Comment in spam_comments: Comment.delete() if spam_comments: print "Removed %s spam comments from database" % deleted_count if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option('--settings') parser.add_option('-v', '--verbose', action="store_true") options, args = parser.parse_args() if options.settings: os.environ["DJANGO_SETTINGS_MODULE"] = options.settings delete_spam_comments(options.verbose)
-
∞ Code snippet from my blog entry_detail.html showing how to moderate comments.
{% if object.enable_comments %} {% if object.comments_expired %} <div id="comments_open"> <h2>Post a comment</h2> <p id="comment_policy">Please use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> syntax for formatting. No <abbr title="hypertext markup language">HTML</abbr> is allowed. By using this comment form, it's assumed that you agree with the terms of <a href="http://patrickbeeson.com/about/comments/" title="Comment policy for this Web site">my comment policy</a>.</p> {% render_comment_form for object %} </div> {% else %} <div id="comments_closed"> <h2 style="clear: both;">Comments no longer accepted for this entry.</h2> <p id="comment_policy">To prevent spam, comments are no longer allowed after 60 days.</p> </div> {% endif %} {% else %} <div id="comments_closed"> <h2 style="clear: both;">Comments are closed for this entry.</h2> </div> {% endif %}
-
∞ Property on my blog models.py to allow the closing of comments after 60 days.
@property def comments_expired(self): delta = datetime.datetime.now() - self.pub_date return delta.days < 60
-
∞ Code to use Akismet in Django blog that also emails the comment to the admin if it's set to is_public.
from django.contrib.comments.signals import comment_was_posted from django.utils.encoding import smart_str from django.core.mail import mail_managers import akismet from django.conf import settings from django.contrib.sites.models import Site ... def moderate_comment(sender, comment, request, **kwargs): ak = akismet.Akismet( key = settings.AKISMET_API_KEY, blog_url = 'http://%s/' % Site.objects.get_current().domain ) data = { 'user_ip': request.META.get('REMOTE_ADDR', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', ''), 'referrer': request.META.get('HTTP_REFERRER', ''), 'comment_type': 'comment', 'comment_author': smart_str(comment.user_name), } if ak.comment_check(smart_str(comment.comment), data=data, build_data=True): comment.is_public = False comment.save() if comment.is_public: email_body = "%s" mail_managers ("New comment posted", email_body % (comment.get_as_text())) comment_was_posted.connect(moderate_comment)
-
∞ Comments on an Ellington flatpage.
{% load libGlenn %} {% if flatpage.enable_comments %} {% load comments.comments %} {% get_comment_list for flatpages.flatpages flatpage.id as comment_list %} <div class="post_content"> <div id="comments"> <div class="titlebar"><h4>Comments</h4></div> {% if comment_list %} {% for comment in comment_list %} <div class="comment {% cycle comment_odd,comment_even %}" id="c{{ comment.id }}"> {% if comment.is_removed %} {% else %} <p class="comment-info">Posted by <a href="/users/{{ comment.get_user.username|strip_host }}"><strong>{{ comment.get_user.username|strip_host }}</strong></a> on {{ comment.submit_date|date:"F j, Y" }} at {{ comment.submit_date|date:"P" }}{% if not comment.is_removed %} ({% if user_can_moderate_comments %}<a href="{{ comment.get_deletion_url }}">Remove</a>{% else %}<a href="{{ comment.get_flag_url }}">Suggest removal</a>{% endif %}){% endif %}</p> {{ comment.comment|escape|urlizetrunc:"40"|linebreaks }} {% endif %}</div> {% endfor %} {% endif %} <div class="comment-form"> <span class="larger">Post your comment</span><br /> {% if not user.username %} (Requires free <a href="/accounts/register/">registration</a>.) {% endif %} <hr /> <p><strong>Comments are the sole responsibility of the person posting them. You agree not to post comments that are off topic, defamatory, obscene, abusive, threatening or an invasion of privacy. Violators may be banned. <a href="/privacy/">Click here for our full user agreement</a>.</strong></p> {% comment_form for flatpages.flatpages flatpage.id %} </div> <!-- END commentform --> </div> <!-- END comments --> </div> <!-- END post_content --> {% endif %}


