Esempio n. 1
0
def install(request, template=INSTALL_TEMPLATE):
    
    if is_installed():
        return installed(request)
    
    db_error = ""
    
    if request.method == 'POST':
        installation_form = InstallationForm(request.POST)
        if installation_form.is_valid():
            try:
                # Initialise the database
                syncdb_command = syncdb.Command()
                syncdb_command.handle_noargs()
            except Exception, e:    
                db_error = e
            else:    
                # Initialise the admin account
                username = installation_form.cleaned_data['username']
                password = installation_form.cleaned_data['password']
                email = installation_form.cleaned_data['email']
                all_users = User.objects.all()
                all_users.delete()
                admin_user = User.objects.create_superuser(username, email, password)
                # Initialise the basic set of site settings
                site_title = installation_form.cleaned_data['site_title']
                site_title_setting = Setting.objects.add_templatable('site_title', site_title)
                site_email_setting = Setting.objects.add('site_email', email)
                # Reset the publish dates of the intitial article
                initial_article = articles_utils.article_get("1")
                initial_article.created = datetime.datetime.now()
                initial_article.updated = initial_article.created
                initial_article.save()
                # Redirect the user to the admin interface
                return installed(request)
Esempio n. 2
0
def article_scrap_edit(request, article_id, scrap_id, is_page=False, template=ARTICLE_SCRAP_EDIT_TEMPLATE):
    article = utils.article_get(article_id)
    scrap = scraps_utils.scrap_get(scrap_id)
    msg = None
    if request.method == 'POST':
        # only update upon save after post    
        scrap_edit_form = scraps_utils.scrap_get_edit_form(scrap, False)
        scrap_edit_form = scrap_edit_form(request.POST)
        if scrap_edit_form.is_valid():
            scraps_utils.scrap_update(scrap, request.POST)
            utils.article_update_rendered_pile(article_id)
            msg = 'Your changes to this ' + scrap.blueprint_display_name() \
                + ' scrap were saved'
            if is_page:
                return redirect('articles_admin_page_edit', article_id=article_id)
            else:
                return redirect('articles_admin_article_edit', article_id=article_id)
    else:
        scrap_edit_form = scraps_utils.scrap_edit_form_instance(scrap, False)
    h1 = "Editing \"" + article.title + "\""
    
    return direct_to_template(
        request,
        template,
        {
            'menu_current': menu_current(is_page),
            'h1': h1,
            'article': article,
            'editable_scrap': scrap,
            'scrap_edit_form': scrap_edit_form,
            'msg': msg,
            'is_page': is_page
        }
    )
Esempio n. 3
0
def article_detail(request, article_id=None, year=None, month=None, slug=None, template=ARTICLE_DETAIL_TEMPLATE):
    if article_id:
        article = utils.article_get(article_id)
        return redirect(
            'articles_public_article_detail',
            year=article.created.year,
            month=article.created.month,
            slug=article.slug
        )
    article = get_object_or_404(
        Article,
        created__year=year,
        created__month=month,
        slug=slug
    )
    if article.is_published:
        return direct_to_theme(
            request,
            template,
            {
                'article': article
            }
        )
    elif request.user == article.author:
        article.title = article.title + " *DRAFT*"
        return direct_to_theme(
            request,
            template,
            {
                'doc_title': article.title,
                'article': article
            }
        )
    else:
        raise Http404
Esempio n. 4
0
def article_scrap_create(request, article_id, is_page=False):
    if request.method == 'POST':
        article = utils.article_get(article_id)
        create_scrap_form = CreateScrapForm(request.POST)
        if create_scrap_form.is_valid():
            blueprint_name = create_scrap_form.cleaned_data['blueprint_name']
            scrap = scraps_utils.scrap_create(blueprint_name)
            scraps_utils.scrap_repile(scrap.id, article.pile.id)
    if is_page:
        return redirect('articles_admin_page_edit', article_id=article_id)
    else:
        return redirect('articles_admin_article_edit', article_id=article_id)
Esempio n. 5
0
def articles_manage(request, article_id=None, is_page=False, template=ARTICLES_MANAGE_TEMPLATE):
    if is_page:
        articles = Article.objects.pages().order_by('title')
        create_article_form = CreatePageForm()
    else:
        articles = Article.objects.articles().order_by('-created')
        create_article_form = CreateArticleForm()
    quick_edit_article = None
    quick_edit_article_form = None
    if article_id:
        quick_edit_article = utils.article_get(article_id)
        data = {
            'title': quick_edit_article.title,
            'is_published': quick_edit_article.is_published,
            'show_comments': quick_edit_article.show_comments,
            'enable_comments': quick_edit_article.enable_comments
        }
        quick_edit_article_form = QuickEditArticleForm(data)
        if request.method == 'POST':
            quick_edit_article_form = QuickEditArticleForm(request.POST)
            if quick_edit_article_form.is_valid():
                quick_edit_article.title = quick_edit_article_form.cleaned_data['title']
                quick_edit_article.is_published = quick_edit_article_form.cleaned_data['is_published']
                quick_edit_article.show_comments = quick_edit_article_form.cleaned_data['show_comments']
                quick_edit_article.enable_comments = quick_edit_article_form.cleaned_data['enable_comments']
                quick_edit_article.save()
                if is_page:
                    return redirect('articles_admin_pages_manage')
                else:
                    return redirect('articles_admin_articles_manage')
                
    return direct_to_template(
        request,
        template,
        {
            'menu_current': menu_current(is_page),
            'h1': 'Manage ' + title_current(is_page) + 's',
            'articles': articles,
            'create_article_form': create_article_form,
            'quick_edit_article': quick_edit_article,
            'quick_edit_article_form': quick_edit_article_form,
            'is_page': is_page
        }
    )
Esempio n. 6
0
def article_edit(request, article_id, is_page=False, template=ARTICLE_EDIT_TEMPLATE):
    article = utils.article_get(article_id)
    create_scrap_form = CreateScrapForm()
    msg = None
    if request.method == 'POST':
        pass
    h1 = "Editing " + title_current(is_page) + " \"" + article.title + "\""
    return direct_to_template(
        request,
        template,
        {
            'menu_current': menu_current(is_page),
            'h1': h1,
            'article': article,
            'create_scrap_form': create_scrap_form,
            'msg': msg,
            'is_page': is_page
        }
    )