Ejemplo n.º 1
0
def fetch_from_url(request, url):
    """Analyze URL, returning the article and the articles in its path
    If something goes wrong, return an error HTTP response"""

    err = None
    article = None
    path = None
    
    url_path = get_url_path(url)

    try:
        root = Article.get_root()
    except:
        err = not_found(request, '')
        return (article, path, err)

    if url_path and root.slug == url_path[0]:
        url_path = url_path[1:]

    path = Article.get_url_reverse(url_path, root)
    if not path:
        err = not_found(request, '/' + '/'.join(url_path))
    else:
        article = path[-1]
    return (article, path, err)
Ejemplo n.º 2
0
def create(request, template_name=None, next=None, action=None):
    """this method is used to create a page about something"""
    request_user = request.user
    if request.method == 'POST':
        f = ArticleForm(request.POST)
        if f.is_valid():
            title = f.cleaned_data['title']
            slug = slugify(title)
            category = f.cleaned_data['category']
            protection = f.cleaned_data['protection']
            visibility = f.cleaned_data['visibility']
            can_write = f.cleaned_data['can_write']
            can_read = f.cleaned_data['can_read']
            if Article.objects.filter(slug=slug).count() > 0:
                slug = slug + str(Article.objects.filter(slug__contains=slug).count())
            article = Article(author=request.user, slug=slug, title=title,category=category)

            #Check every thing related to permissions cal_protection and cal_visibility
            if article.permissions is None:
                    permissions = Permission(permission_name='%s_perms' % slug,
                                             visibility=visibility,
                                             protection=protection)
                    permissions.save()
                    article.permissions = permissions
                    article.permissions.can_write.add(request.user)
                    article.permissions.can_read.add(request.user)
            #@todo change "2" to CUSTOM
            if protection == "2":
                for user in can_write:
                        article.permissions.can_write.add(user)
            if visibility == "2":
                for user in can_read:
                        article.permissions.can_read.add(user)


            article.parent = Article.get_root()
            article.save()
            
            if TaggableManager:
                #tagging the article
                tags = f.cleaned_data['tags']
                if tags:
                    article.tags.set(*tags)
            #adding the article description only if the user has checked the add_description
            if not f.cleaned_data['contents'] == '':
                status = f.cleaned_data['status']
                contents = f.cleaned_data['contents']
                new_revision = Version(user=request.user, article=article, status=status,
                                      contents=contents)
                new_revision.save()
            #set the notification object
            #ToNotify(user=request_user, Article=article).save()
            if not request.is_ajax():
                if next == 'wall_home':
                    return HttpResponseRedirect(reverse(next))
                return HttpResponseRedirect(reverse(next, args=(article.get_url(),)))
            response = {'success':True}
        else:
            response = errors_as_json(f)
        if request.is_ajax():
            json = simplejson.dumps(response, ensure_ascii=False)
            return HttpResponse(json, mimetype="application/json")
    else:
        f = ArticleForm()

    c = RequestContext(request, {'wiki_form': f,
                                 'action':reverse(action),
                                 'wiki_edit_protection':False,
                                 'wiki_write': False,
                                 'wiki_read': False,
                                 })

    return render_to_response(template_name, c)