Пример #1
0
def calendars_browse(request, template_name="calendars/calendars_browse.html"):

    from taggit.models import TaggedItem
    tags = TaggedItem.tags_for(Calendar)
    
    return render_to_response(template_name, {
        "tags": tags,
    }, context_instance=RequestContext(request))
Пример #2
0
def add_tags():    
    pub = Tag.objects.create(name='published')
    unpub = Tag.objects.create(name='unpublished')
    even = Tag.objects.create(name='even')
    odd = Tag.objects.create(name='odd')

    posts = BasicPost.objects.select_subclasses()
    
    for p in posts:
        if p.is_published():
            ti = TaggedItem(object=p, tag=pub)
        else:
            ti = TaggedItem(object=p, tag=unpub)
        ti.save()
        if p.pk % 2 == 0:
            ti = TaggedItem(object=p, tag=even)
        else: 
            ti = TaggedItem(object=p, tag=odd)
        ti.save()
Пример #3
0
def add_tags():
    pub = Tag.objects.create(name='published')
    unpub = Tag.objects.create(name='unpublished')
    even = Tag.objects.create(name='even')
    odd = Tag.objects.create(name='odd')

    posts = BasicPost.objects.select_subclasses()

    for p in posts:
        if p.is_published():
            ti = TaggedItem(object=p, tag=pub)
        else:
            ti = TaggedItem(object=p, tag=unpub)
        ti.save()
        if p.pk % 2 == 0:
            ti = TaggedItem(object=p, tag=even)
        else:
            ti = TaggedItem(object=p, tag=odd)
        ti.save()
Пример #4
0
def submit_article(request):
    '''
        View for Article Submission
    '''
    ImageFormset = formset_factory(ImageForm, extra=settings.MAX_NUM_IMAGES)
    if request.method == 'POST':
        form = ArticleSubmissionForm(request.POST, request.FILES)
        image_forms = ImageFormset(request.POST, request.FILES)
        if form.is_valid() and image_forms.is_valid():
            title = request.POST['title']
            subtitle = request.POST['subtitle']
            body = request.POST['body']
            editor = request.POST['editor']
            authors = request.POST.get('authors', [])
            tags = request.POST.get('tags', [])
            files = request.FILES
            post_body = EnhancedText(
                body,
                editor)  #Combines body and editor field to for creating post
            post = None
            if len(files) == 0:  #Will save post as basic post
                post = BasicPost(title=title,
                                 slug=slugify(title),
                                 subtitle=subtitle,
                                 body=post_body)
                post.slug = post._get_unique_slug()
                post.save()
            elif len(files) == 1:  #Will save post as post with simple image
                image = None
                image = files.itervalues().next()
                post = PostWithSimpleImage(title=title,
                                           slug=slugify(title),
                                           subtitle=subtitle,
                                           body=post_body,
                                           image=image)
                post.save()
            else:  #Will save post as post with slideshow
                gallery = Gallery(title=title)
                gallery.save()
                path = os.path.join(settings.MEDIA_ROOT, 'uploads')
                path = os.path.join(path, 'images')
                for index, image in enumerate(files):
                    filename_unique = False
                    filename = os.path.join(path, files[image].name)
                    counter = 1
                    while not filename_unique:
                        if os.path.exists(filename):
                            filename_split = filename.split('.')
                            filename = filename_split[0]
                            extension = filename_split[1]
                            filename = filename + unicode(
                                counter) + '.' + extension
                        else:
                            filename_unique = True
                    image_file = open(filename, 'wb+')
                    for chunk in files[image].chunks():
                        image_file.write(chunk)
                    image_file.close()
                    filename_split = filename.split(os.sep)
                    base_filename = filename_split[-1]
                    filename = os.path.join('uploads', 'images')
                    filename = os.path.join(filename, base_filename)
                    image = Image(title=title,
                                  slug=slugify(title),
                                  file=filename)
                    image.slug = image._get_unique_slug()
                    image.save()
                    ordered_image = OrderedImage(gallery=gallery,
                                                 image=image,
                                                 position=index)
                    ordered_image.save()
                post = PostWithSlideshow(title=title,
                                         slug=slugify(title),
                                         subtitle=subtitle,
                                         body=post_body,
                                         gallery=gallery)
                post.save()
            if post:
                # Saves the authors and tags of the post
                for index, author in enumerate(authors):
                    credit = OrderedCredit(
                        credit=Credit.objects.get(id=author),
                        content_object=post,
                        position=index)
                    credit.save()
                for index, tag in enumerate(tags):
                    tag = TaggedItem(tag=Tag.objects.get(id=tag), object=post)
                    tag.save()
                article = SubmittedArticle(submitted_by=request.user,
                                           object=post)
                article.save()
            return HttpResponseRedirect(reverse('submit_article_success'))
    else:
        form = ArticleSubmissionForm()
        image_forms = ImageFormset()
    return render_to_response('submit_article/add.html', {
        'form': form,
        'image_forms': image_forms,
        'max_forms': settings.MAX_NUM_IMAGES
    },
                              context_instance=RequestContext(request))
Пример #5
0
def submit_article(request):
    '''
        View for Article Submission
    '''
    ImageFormset = formset_factory(ImageForm, extra=settings.MAX_NUM_IMAGES)
    if request.method == 'POST':
        form = ArticleSubmissionForm(request.POST, request.FILES)
        image_forms = ImageFormset(request.POST, request.FILES)
        if form.is_valid() and image_forms.is_valid():
            title = request.POST['title']
            subtitle = request.POST['subtitle']
            body = request.POST['body']
            editor = request.POST['editor']
            authors = request.POST.get('authors', [])
            tags = request.POST.get('tags', [])
            files = request.FILES
            post_body = EnhancedText(body, editor)                                  #Combines body and editor field to for creating post
            post = None
            if len(files) == 0:                                                     #Will save post as basic post
                post = BasicPost(title=title, slug=slugify(title), 
                                    subtitle=subtitle, body=post_body)
                post.slug = post._get_unique_slug()
                post.save()
            elif len(files) == 1:                                                   #Will save post as post with simple image
                image = None
                image = files.itervalues().next()
                post = PostWithSimpleImage(title=title, slug=slugify(title),
                                            subtitle=subtitle, body=post_body,
                                            image=image)
                post.save()
            else:                                                                   #Will save post as post with slideshow
                gallery = Gallery(title=title)
                gallery.save()
                path = os.path.join(settings.MEDIA_ROOT, 'uploads')
                path = os.path.join(path, 'images')
                for index, image in enumerate(files):
                    filename_unique = False
                    filename = os.path.join(path, files[image].name)
                    counter = 1
                    while not filename_unique:
                        if os.path.exists(filename):
                            filename_split = filename.split('.')
                            filename = filename_split[0]
                            extension = filename_split[1]
                            filename = filename + unicode(counter) + '.' + extension
                        else:
                            filename_unique = True
                    image_file = open(filename, 'wb+')
                    for chunk in files[image].chunks():
                        image_file.write(chunk)
                    image_file.close()
                    filename_split = filename.split(os.sep) 
                    base_filename = filename_split[-1]
                    filename = os.path.join('uploads', 'images')
                    filename = os.path.join(filename, base_filename)
                    image = Image(title=title, slug=slugify(title), file=filename)
                    image.slug = image._get_unique_slug()
                    image.save()
                    ordered_image = OrderedImage(gallery=gallery, image=image, position=index)
                    ordered_image.save()
                post = PostWithSlideshow(title=title, slug=slugify(title),
                                            subtitle=subtitle, body=post_body,
                                            gallery=gallery)
                post.save()
            if post:
                # Saves the authors and tags of the post
                for index, author in enumerate(authors):
                    credit = OrderedCredit(credit=Credit.objects.get(id=author), 
                                            content_object=post, position=index)
                    credit.save()
                for index, tag in enumerate(tags):
                    tag = TaggedItem(tag=Tag.objects.get(id=tag), object=post)
                    tag.save()
                article = SubmittedArticle(submitted_by=request.user, object=post)
                article.save()
            return HttpResponseRedirect(reverse('submit_article_success'))
    else:
        form = ArticleSubmissionForm()
        image_forms = ImageFormset()
    return render_to_response('submit_article/add.html',
                            {'form': form,
                            'image_forms': image_forms,
                            'max_forms': settings.MAX_NUM_IMAGES},
                            context_instance=RequestContext(request))