예제 #1
0
    def render(self, context):

        if self.include_draft:
            qs = Post.all().order('-post_date')
        else:
            qs = Post.published().order('-post_date')

        context[self.varname] = qs

        return ''
예제 #2
0
파일: views.py 프로젝트: stucox/Cheese-Blog
def checkPostSlug(slug, disallowed=[]):
    """
    Checks is a post slug is valid, unique and available.
    
    Parameters:
    - `slug`: the slug string to check
    - `disallowed`: a list of string which should not be allowed as slugs
    """
    # TODO: thorough checking of slug format
    return Post.all().filter("slug =", slug).count() \
            and not slug in disallowed
예제 #3
0
def index(request):
    posts = Post.all().order('-create_time')
    
    #return test_list(request, queryset=posts, paginate_by=LIST_PER_PAGE, template_name='index.html', 
    #    extra_context={}, template_object_name='post') 
    return object_list(request,
                       template_object_name = 'post',
                       queryset = posts,
                       allow_empty = True,
                       extra_context = {},
                       template_name = 'index.html',
                       paginate_by = LIST_PER_PAGE,
                       )
예제 #4
0
def admin_list_post(request):
    if users.is_current_user_admin():
        
        return object_list(request,
                       template_object_name='obj',
                       queryset=Post.all().order('-create_time'),
                       allow_empty=True,
                       extra_context={'type': 'post'},
                       template_name='admin/list.html',
                       paginate_by=setting.ADMIN_LIST_PER_PAGE,
                       )
    else:
        return HttpResponseRedirect('/')
예제 #5
0
파일: main.py 프로젝트: yablochkin/homepage
def feed():
    feed = AtomFeed(u"Bers blog", feed_url=request.url, url=request.url_root)
    posts = Post.all().filter("hidden =", False).order("-created").fetch(limit=20)
    for post in posts:
        feed.add(
            post.title,
            unicode(post.content),
            content_type="html",
            author=u"Bers",
            url=urljoin(request.url_root, post.get_url()),
            updated=post.created,
            published=post.created,
        )
    return feed.get_response()
예제 #6
0
파일: views.py 프로젝트: stucox/Cheese-Blog
def listPosts(request, max=None, order=PostOrder.NEWEST_FIRST):
    """
    A list of the posts in the blog, with summaries and links to each.
    
    Parameters:
    - `request`: a `WSGIRequest` representing the HTTP request for this view
    - `max`: the maximum number of posts to display, or None to display all
      posts
    - `order`: a member of the PostOrder enum class defining the sorting order
      of posts in the list; defaults to newest first.
    """
    posts = Post.all().order(order).fetch(max)
    return render_to_response(LIST_POSTS_TEMPLATE, {'posts': posts},
            context_instance=RequestContext(request))
예제 #7
0
def admin_list_post(request):
    if users.is_current_user_admin():

        return object_list(
            request,
            template_object_name='obj',
            queryset=Post.all().order('-create_time'),
            allow_empty=True,
            extra_context={'type': 'post'},
            template_name='admin/list.html',
            paginate_by=setting.ADMIN_LIST_PER_PAGE,
        )
    else:
        return HttpResponseRedirect('/')
예제 #8
0
파일: views.py 프로젝트: stucox/Cheese-Blog
def viewPost(request, slug):
    """
    Display a blog post.
    
    Parameters:
    - `request`: a `WSGIRequest` representing the HTTP request for this view
    - `slug`: the URL slug of the post to edit, or None to create a new post
    """
    if slug is None:
        raise Http404
    post = Post.all().filter("slug =", slug).get()
    if not post:
        raise Http404
    return render_to_response(VIEW_POST_TEMPLATE, {'post': post},\
            context_instance=RequestContext(request))
예제 #9
0
파일: views.py 프로젝트: stucox/Cheese-Blog
def ctrlPanel(request, order=PostOrder.NEWEST_FIRST):
    """
    Control panel for blog administration.
    
    Parameters:
    - `request`: a `WSGIRequest` representing the HTTP request for this view
    - `order`: a member of the PostOrder enum class defining the sorting order
      of posts in the list; defaults to newest first.
    """
    posts = [post for post in Post.all().order(order)]
    # If the request contains POST data, perform any necessary post deletions
    if request.method == "POST":
        for slug in request.POST.getlist('delete'):
            filter(lambda post: post.slug == slug)[0].delete()
    return render_to_response(CTRL_PANEL_TEMPLATE, {'posts': posts},\
            context_instance=RequestContext(request))
예제 #10
0
파일: urls.py 프로젝트: lvbeck/niubi
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.conf.urls.defaults import *
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
from blog.models import Post, Category, Tag
from feeds.models import LatestEntries, HottestEntries

feeds = {"latest": LatestEntries, "hottest": HottestEntries}

posts = {"queryset": Post.all().filter("is_published", True), "date_field": "create_time"}

tags = {"queryset": Tag.all().order("-post_count")}

categories = {"queryset": Category.all().order("-post_count")}

sitemaps = {
    "flatpages": FlatPageSitemap,
    "blog": GenericSitemap(posts, priority=0.6, changefreq="monthly"),
    #'tag': GenericSitemap(tags, priority=0.5, changefreq='monthly'),
    #'category': GenericSitemap(categories, priority=0.4, changefreq='yearly'),
}

urlpatterns = patterns(
    "",
    (r"^$", "blog.views.list_post"),
예제 #11
0
def feeds(request):
    return render_to_response('feeds/feeds.html',
                              dictionary = {"posts": Post.all().order('-create_time')[:10] },
                              )
예제 #12
0
파일: main.py 프로젝트: yablochkin/homepage
def view(slug):
    post = Post.all().filter("slug =", slug).get()
    if not post:
        abort(404)
    return render_template("view.html", section="home", post=post)
예제 #13
0
파일: __init__.py 프로젝트: lvbeck/niubi
 def process_request(self, request):
     if not hasattr(request, 'categories'):
         request.categories = Category.all().order('-post_count')      
     if not hasattr(request, 'most_read_posts'):
         request.most_read_posts = Post.all().order('-read_count')[:10]   
     return None
예제 #14
0
def wwb_list_post():   
    html = ''
    for post in Post.all().order('-create_time')[:10]:
        html += '<li><a href=\"%s">%s</a></li>'%(post.get_absolute_url(), post.title.encode('utf-8'))
    return html
예제 #15
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.conf.urls.defaults import *
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
from blog.models import Post, Category, Tag
from feeds.models import LatestEntries, HottestEntries

feeds = {
    'latest': LatestEntries,
    'hottest': HottestEntries,
}

posts = {
    'queryset': Post.all().filter('is_published', True),
    'date_field': 'create_time',
}

tags = {
    'queryset': Tag.all().order('-post_count'),
}

categories = {
    'queryset': Category.all().order('-post_count'),
}

sitemaps = {
    'flatpages': FlatPageSitemap,
    'blog': GenericSitemap(posts, priority=0.6, changefreq='monthly'),
    #'tag': GenericSitemap(tags, priority=0.5, changefreq='monthly'),
예제 #16
0
파일: main.py 프로젝트: yablochkin/homepage
def posts():
    posts = Post.all()
    if not users.is_current_user_admin():
        posts = posts.filter("hidden =", False)
    posts = posts.order("-created")
    return render_template("posts.html", posts=posts, section="home")
예제 #17
0
파일: models.py 프로젝트: lvbeck/net-fish
 def items(self):
     return Post.all().filter(
         "is_published",
         True).order('-create_time').order('-read_count')[:10]
예제 #18
0
파일: urls.py 프로젝트: ytrstu/niubi
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.conf.urls.defaults import *
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
from blog.models import Post, Category, Tag
from feeds.models import LatestEntries, HottestEntries

feeds = {
    'latest': LatestEntries,
    'hottest': HottestEntries,
}

posts = {
    'queryset': Post.all().filter('is_published', True),
    'date_field': 'create_time',
}

tags = {
    'queryset': Tag.all().order('-post_count'),
}

categories = {
    'queryset': Category.all().order('-post_count'),
}

sitemaps = {
    'flatpages': FlatPageSitemap,
    'blog': GenericSitemap(posts, priority=0.6, changefreq='monthly'),
    #'tag': GenericSitemap(tags, priority=0.5, changefreq='monthly'),
예제 #19
0
def wwb_list_post():
    html = ''
    for post in Post.all().order('-create_time')[:10]:
        html += '<li><a href=\"%s">%s</a></li>' % (post.get_absolute_url(),
                                                   post.title.encode('utf-8'))
    return html
예제 #20
0
파일: models.py 프로젝트: lvbeck/niubi
 def items(self):
     return Post.all().filter("is_published", True).order('-create_time')[: 10]
예제 #21
0
파일: views.py 프로젝트: stucox/Cheese-Blog
def editPost(request, slug=None):
    """
    Admin interface for creating and editing blog posts.
    
    Parameters:
    - `request`: a `WSGIRequest` representing the HTTP request for this view
    - `slug`: the URL slug of the post to edit, or None to create a new post
    """
    ## This view function handles post creation, editing, deletion and display
    ## of edit interfaces
    # Create a list of success messages to be updated
    successes = []
    # If no URL slug is provided, it's a new blog post
    isNewPost = slug is None
    # If it's a new post, create an empty instance to play with; this will only
    # be written to the database if data has been submitted
    if isNewPost:
        post = None
    # If not a new post, try to get the blog post with the provided slug
    if not isNewPost:
        post = Post.all().filter("slug =", slug).get()
        if not post:
            raise Http404
    # If there's POST data, changes have been submitted so create/update the
    # post
    if request.method == "POST":
        # Parse the POST data with the form then store validated fields
        form = PostEditForm(request.POST)
        if form.is_valid():
            # Create a post instance using the validated form data
            # Only set the publish date and slug if this is a new post; these
            # can't be changed afterwards
            if isNewPost:
                post = Post(
                    content=form.cleaned_data["content"],
                    title=form.cleaned_data["title"],
                    summary=form.cleaned_data["summary"],
                    slug=getUniquePostSlug(form.cleaned_data['title']),
                    pubDate=datetime.datetime.now(),
                    lastMod=datetime.datetime.now(),
                )
            else:
                post.content = form.cleaned_data["content"]
                post.title = form.cleaned_data["title"]
                post.summary = form.cleaned_data["summary"]
            # Changes have only been made to instances in memory, so save to
            # database
            post.put()
            # Add a message to the success list
            successes.append(SUCCESS_POST_CREATED if isNewPost else \
                    SUCCESS_POST_UPDATED)
            #return redirect("blog:edit-post", slug=post.slug)
    else:
        # If not a new post, create a form bound to the instance grabbed earlier
        if not isNewPost:
            form = PostEditForm({
                    "content": post.content,
                    "title": post.title,
                    "summary": post.summary,
                    })
        # Otherwise create an unbound form to build the page with
        else:
            form = PostEditForm()
    # Render and return the edit form as a response
    return render_to_response(EDIT_POST_TEMPLATE, {'post': post, 'form': form,
            'successes': successes}, context_instance=RequestContext(request))
예제 #22
0
파일: __init__.py 프로젝트: lvbeck/net-fish
 def process_request(self, request):
     if not hasattr(request, 'categories'):
         request.categories = Category.all().order('-post_count')
     if not hasattr(request, 'most_read_posts'):
         request.most_read_posts = Post.all().order('-read_count')[:10]
     return None