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)
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()
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()
# 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()