示例#1
0
def create_article_evento_signal(sender, instance, raw, using, *args,
                                 **kwargs):
    if not instance.privado and not instance.artigo:
        # Cria o artigo
        try:
            section = Section.objects.get(slug='eventos')
        except Section.DoesNotExist:
            section = Section.objects.create(title='Eventos', slug='eventos')
        author = User.objects.get_or_create(username="******")[0]
        artigo = Article(
            title=u'%s - %s' % (
                instance.circulo.titulo,
                instance.nome,
            ),
            header=instance.local.replace('\n', '<br>'),
            content=instance.local.replace('\n', '<br>'),
            author=author,
            created_at=instance.dt_evento,
            is_active=True,
        )
        artigo.save()
        SectionItem(section=section, article=artigo).save()
        # Vincula o artigo ao CirculoEvento
        instance.artigo = artigo
    if instance.artigo:
        # Desabilita/Havilita a visualização do artigo
        instance.artigo.header = instance.local.replace('\n', '<br>')
        instance.artigo.content = instance.local.replace('\n', '<br>')
        instance.artigo.is_active = not instance.privado
        instance.artigo.save()
示例#2
0
def new(request, site):
    if request.method != 'POST':
        return redirect('admin:sites.articles.list', site)

    active_site = Site.get_cached_by_id(site)
    category = request.POST['category']
    if category not in [c[0] for c in Article.CATEGORY_CHOICES]:
        raise PermissionDenied

    article = Article(
        category=category,
        thumbnail=None,
        hide_thumbnail=False,
        published=False,
        pub_date=None,
        unpub_date=None,
        created_by=request.user,
        site=active_site,
    )
    article.save()
    version = Version(page=None, article=article, version=1, owner=request.user, active=True)
    version.save()
    version.publishers.add(request.user)
    create_template(request.POST['template'], version, request.POST['title'])
    return redirect('admin:sites.articles.edit', active_site.id, version.id)
示例#3
0
def save(request, site, version):
    """Save changes to page or article version"""

    try:
        version = Version.objects.get(id=version)
    except Version.DoesNotExist:
        return HttpResponse(json.dumps({'version_does_not_exist': True}))

    response = {}

    # Wrap the entire save operation in an atomic transaction
    with transaction.atomic():
        # Process submitted rows and content
        posted_rows = json.loads(request.POST['rows'])
        _save__process_rows_and_content(request, version, posted_rows)

        # Tags - common for pages and articles
        _save__process_tags(request, version)

        # Page data
        if version.page is not None:
            _save__process_page(request, version, posted_rows)
        # Article data
        elif version.article is not None:
            _save__process_article(request, version, response, posted_rows)
            Article.clear_widget_cache()

    return HttpResponse(json.dumps(response))
示例#4
0
def create_article_evento_signal(sender, instance, raw, using, *args, **kwargs):
    if not instance.privado and not instance.artigo:
        # Cria o artigo
        try:
            section = Section.objects.get(slug='eventos')
        except Section.DoesNotExist:
            section = Section.objects.create(title='Eventos', slug='eventos')
        author = User.objects.get_or_create(username="******")[0]
        artigo = Article(
            title=u'%s - %s' % (instance.circulo.titulo, instance.nome,),
            header=instance.local.replace('\n', '<br>'),
            content=instance.local.replace('\n', '<br>'),
            author=author,
            created_at=instance.dt_evento,
            is_active=True,
        )
        artigo.save()
        SectionItem(section=section, article=artigo).save()
        # Vincula o artigo ao CirculoEvento
        instance.artigo = artigo
    if instance.artigo:
        # Desabilita/Havilita a visualização do artigo
        instance.artigo.header = instance.local.replace('\n', '<br>')
        instance.artigo.content = instance.local.replace('\n', '<br>')
        instance.artigo.is_active = not instance.privado
        instance.artigo.save()
示例#5
0
def delete(request, site, article):
    try:
        active_site = Site.get_cached_by_id(site)
        Article.objects.get(id=article).delete()
        Article.clear_widget_cache()
    except Article.DoesNotExist:
        # Probably not a code error but a double-click or something, ignore
        pass
    return redirect('admin:sites.articles.list', active_site.id)
# Run the following commands in the Django shell `python3 manage.py shell`

# Trying to create a new article. This will result in an error.
from cms.models import Article

article1 = Article()
article1.title = "New Article"
article1.content = "Test content"
article1.slug = "new-article"
article1.save()

# Creating a new user.
from django.contrib.auth.models import User

author1 = User()
author1.first_name = 'Aruna'
author1.last_name = 'Tank'
author1.email = '*****@*****.**'
author1.set_password('apassword')
author1.save()


# The above article can be saved now tha tis has an author attached.
article1.author = author1
article1.save()
# Run the following commands in the Django shell `python3 manage.py shell`

# Trying to create a new article. This will result in an error.
from cms.models import Article

article1 = Article()
article1.title = "New Article"
article1.content = "Test content"
article1.slug = "new-article"
article1.save()

# Creating a new user.
from django.contrib.auth.models import User

author1 = User()
author1.first_name = 'Aruna'
author1.last_name = 'Tank'
author1.email = '*****@*****.**'
author1.set_password('apassword')
author1.save()

# The above article can be saved now tha tis has an author attached.
article1.author = author1
article1.save()