Пример #1
0
def archive(request,year,month):
    right_entries = Entry.get_last_by_section()

    paginator = Paginator(Entry.get_archive(year,month),settings.BLOG_OTHER_LAST_ENTRIES,request.GET.get("p",1))
    entries = paginator.current()

    return render_to_response("home-short.html", 
        dict(right_entries=right_entries,entries=entries, archive=datetime.date(int(year),int(month),1),section=None,subsection=None,tag=None), 
        context_instance=RequestContext(request))
Пример #2
0
def view_for_section(request,section):
       
    right_entries = Entry.get_last_by_section(section=section)
    
    paginator = Paginator(Entry.get_last(section__id=section.id),settings.BLOG_OTHER_LAST_ENTRIES,request.GET.get("p",1))
    entries = paginator.current()

    return render_to_response("home-short.html", 
        dict(right_entries=right_entries, entries=entries, paginator=paginator,section = section,archive=None,subsection=None,tag=None), 
        context_instance=RequestContext(request))
Пример #3
0
def subsection_tag(request,subsection,tag):

    subsection = get_object_or_404(Subsection,slug=subsection)
    tag = get_object_or_404(Tag,slug=tag)

    paginator = Paginator(Entry.get_last(subsection__id=subsection.id,tags__id__in=[tag.id]),settings.BLOG_OTHER_LAST_ENTRIES,request.GET.get("p",1))
    entries = paginator.current()
    right_entries = Entry.get_last_by_section()

    return render_to_response("home-short.html", 
        dict(right_entries=right_entries, entries=entries,paginator=paginator,archive=None,section=None,subsection=subsection,tag=tag), 
        context_instance=RequestContext(request))
Пример #4
0
def section_subsection(request,section,subsection):
    
    section = get_object_or_404(Section,slug=section)
    subsection = get_object_or_404(Subsection,slug=subsection)
    
    paginator = Paginator(Entry.get_last(subsection__id=subsection.id,section__id=section.id),settings.BLOG_OTHER_LAST_ENTRIES,request.GET.get("p",1))
    entries = paginator.current()
    
    right_entries = Entry.get_last_by_section()

    return render_to_response("home.html", 
        dict(right_entries=right_entries, entries=entries,paginator=paginator,section=section,subsection=subsection), 
        context_instance=RequestContext(request))
Пример #5
0
def home_gallery():
    import random,time
    random.seed(time.time())
    
    gallery = list(Entry.get_home_gallery())
    random.shuffle(gallery)
    total = len(gallery)
    
    return {'gallery':gallery, "total":total }
Пример #6
0
def author(request,user):
    
    author = get_object_or_404(User,username=user)
    
    entries = Entry.get_last_by_author(author)

    return render_to_response("author.html", 
        dict(entries=entries, author=author,), 
        context_instance=RequestContext(request))
Пример #7
0
    def get_context_data(self, **kwargs):
        context = super(EntryView, self).get_context_data(**kwargs)
        slug = self.kwargs['slug']
        entry = Entry.all().filter('slug =', slug).get()
        if not entry:
            raise Http404

        context['entry'] = entry
        return context
Пример #8
0
def search(request):
    
    q = request.GET.get("q")
        
    paginator = Paginator(Entry.search(q),settings.BLOG_OTHER_LAST_ENTRIES,request.GET.get("p",1))
    entries = paginator.current()


    return render_to_response("home-short.html", 
        dict(entries=entries,paginator=paginator,archive=None,section=None,subsection=None,tag=None), 
        context_instance=RequestContext(request))
Пример #9
0
def entry_delete(request, slug=None):
    data = {}
    if slug is None:
        raise Http404

    entry = Entry.all().filter('slug =', slug).get()
    if not entry:
        raise Http404

    entry.delete()
    messages.warning(request, 'Entry deleted')
    data['redirect_url'] = reverse('blog_index')

    return HttpResponse(simplejson.dumps(data), 
                        mimetype="application/json")
Пример #10
0
 def mutate_and_get_payload(cls, input, info):
     try:
         entry = Entry()
         entry.title = input.get('title')
         entry.status = input.get('status')
         entry.date = input.get('date')
         entry.sticky = input.get('sticky', False)
         entry.section_id = get_section_id(input.get('section'))
         entry.category_id = get_category_id(input.get('category'))
         entry.summary = input.get('summary', '')
         entry.body = input.get('body', '')
         entry.owner_id = get_user_id(input.get('owner'),
                                      otherwise=input.get('owner'))
         entry.full_clean()
         entry.save()
         entry.tags = get_tags_ids(input.get('tags'))
         return CreateEntry(entry=entry)
     except ValidationError as e:
         return CreateEntry(entry=None, errors=getErrors(e))
     except Exception as e:
         print '%s (%s)' % (e.message, type(e))
Пример #11
0
def entry_create(request, slug=None):
    if slug is not None:
        entry = Entry.all().filter('slug =', slug).get()
        action_url = reverse('entry_edit', args=[slug])
        initial = {'title': entry.title,
                   'content': entry.content,
                   'tags': "\n".join(tag.name() for tag in entry.tags),
                   'status': entry.status}
    else:
        entry = None
        action_url = reverse('entry_create')
        initial = None

    if request.method == 'POST':
        form = EntryForm(request.POST, initial)
        if form.is_valid():
            if not initial:
                tags = []
                for tagtitle in form.cleaned_data['tags']:
                    tag = Tag.inc_or_insert(tagtitle)
                    tags.append(tag.key())
                form.cleaned_data['tags'] = tags
                
                entry = Entry(**form.cleaned_data)
                entry.put()
                messages.success(request, 'Post created successfully')
            else:
                initial_tags = [tag.name() for tag in entry.tags]
                new_tags = form.cleaned_data['tags']

                new = set(new_tags) - set(initial_tags)
                existing = set(new_tags) & set(initial_tags)
                deleted = set(initial_tags) - set(new_tags)

                tags = []
                for tagtitle in deleted:
                    Tag.try_dec(tagtitle)

                for tagtitle in new_tags:
                    if tagtitle in new:
                        tag = Tag.inc_or_insert(tagtitle)
                        tags.append(tag.key())
                    elif tagtitle in existing:
                        tag = Tag.get_by_key_name(tagtitle)
                        tags.append(tag.key())
                    else:
                        raise Exception("what?")

                entry.tags = tags
                entry.title = form.cleaned_data['title']
                entry.status = form.cleaned_data['status']
                entry.content = form.cleaned_data['content']
                entry.put()
                messages.success(request, 'Post modified successfully')
                
            if entry.status == 'draft':
                msg = ('<strong>Warning</strong> The post was saved as a '
                       'draft and will not be visisble from the homepage. '
                       'Click <a href="%s">here</a> to view all your posts.'
                       % reverse('all_index'))
                messages.warning(request, mark_safe(msg))
            
            return redirect('entry_view', entry.slug)
    else:
        form = EntryForm(initial)

    return render_to_response('blog/create.html', {
        'form': form,
        'action_url': action_url
        },
        context_instance=RequestContext(request))
Пример #12
0
 def get_query(self):
     tag = Tag.get_by_key_name(self.kwargs['tag'])
     return Entry.all().filter('status =', 'published') \
                       .filter('tags =', tag.key()) \
                       .order('-published_at')
Пример #13
0
 def get_query(self):
     return Entry.all().order('-created_at')
Пример #14
0
 def get_query(self):
     return Entry.all().filter('status =', 'published') \
                       .order('-published_at')