How to use the dispatch.apps.core.models.Person.objects function in dispatch

To help you get started, we’ve selected a few dispatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubyssey / dispatch / apps / api / tests.py View on Github external
def test_delete_person(self):
        """
        Ensure we can delete a person.
        """
        id = self.person.id
        url = reverse('people-detail', args=(id,))
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        try:
            Person.objects.get(pk=id)
            self.fail()
        except:
            pass
github ubyssey / dispatch / apps / api / tests.py View on Github external
def setUp(self):
        self.user = User.objects.create(email='peterjsiemens@gmail.com')
        self.person = Person.objects.create(full_name="Jane Doe")
        self.client.force_authenticate(self.user)
github ubyssey / dispatch / dispatch / apps / manager / views.py View on Github external
def user_edit(request, id):

    p = Person.objects.get(pk=id)

    if request.method == 'POST':
        form = PersonForm(request.POST, request.FILES, instance=p)
        if form.is_valid():
            form.save()
            return redirect(users)
    else:
        form = PersonForm(instance=p)

    context = {
        'title': 'Edit User',
        'person': p,
        'form': form,
        'user_form': form.user_form,
    }
github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save_article(self, data):

        slug = data['url'].rsplit('/',2)[1]

        try:
            Article.objects.filter(slug=slug).delete()
        except:
            pass

        try:
            author = Person.objects.get(full_name=data['author'])
        except:
            author = Person.objects.create(full_name=data['author'])

        article = Article()

        title = str(BeautifulSoup(data['title'], 'html.parser'))
        article.headline = title

        article.slug = slug
        article.snippet = data['description']
        article.seo_keyword = data['keyword']
        article.seo_description = data['description']

        date = dateutil.parser.parse(data['date'])

        article.status = Article.DRAFT
github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save_article(self, data):

        slug = data['url'].rsplit('/',2)[1]

        try:
            Article.objects.filter(slug=slug).delete()
        except:
            pass

        try:
            author = Person.objects.get(full_name=data['author'])
        except:
            author = Person.objects.create(full_name=data['author'])

        article = Article()

        title = str(BeautifulSoup(data['title'], 'html.parser'))
        article.headline = title

        article.slug = slug
        article.snippet = data['description']
        article.seo_keyword = data['keyword']
        article.seo_description = data['description']

        date = dateutil.parser.parse(data['date'])

        article.status = Article.DRAFT
        article.is_published = True
        article.published_at = date
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def author(self, request, slug=None):

        try:
            person = Person.objects.get(slug=slug)
        except:
            raise Http404("Author could not be found.")

        articles = Article.objects.filter(authors=person, is_published=True)[:6]

        context = {
            'meta': self.get_author_meta(person),
            'person': person,
            'articles': articles
        }

        return render(request, 'author/base.html', context)
github ubyssey / dispatch / dispatch / apps / frontend / themes / default / forms.py View on Github external
def save(self, commit=True):

        # Save the provided password in hashed format
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])

        user.person = Person.objects.create(full_name=self.cleaned_data.get('full_name'), is_admin=False)

        if commit:
            user.save()
        return user
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def author_articles(self, request, slug=None):

        try:
            person = Person.objects.get(slug=slug)
        except:
            raise Http404("Author could not be found.")

        order = request.GET.get('order', 'newest')

        if order == 'newest':
            order_by = '-published_at'
        else:
            order_by = 'published_at'

        query = request.GET.get('q', False)

        article_list = Article.objects.filter(authors=person, is_published=True).order_by(order_by)

        if query:
            article_list = article_list.filter(headline__icontains=query)
github ubyssey / dispatch / dispatch / apps / manager / views.py View on Github external
def users(request):
    users = Person.objects.filter(is_admin=True).order_by('full_name')
    q = request.GET.get('q', '')
    if q:
        users = users.filter(full_name__icontains=q)

    paginator = Paginator(users, 15) # Show 15 articles per page

    page = request.GET.get('page')

    try:
        persons = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        persons = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        persons = paginator.page(paginator.num_pages)
github ubyssey / dispatch / apps / frontend / themes / default / forms.py View on Github external
def save(self, commit=True):

        # Save the provided password in hashed format
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])

        user.person = Person.objects.create(full_name=self.cleaned_data.get('full_name'), is_admin=False)

        if commit:
            user.save()
        return user