django-github-user

django github user models (Gist, Repo, StarredGist, StarredRepo) and management commands


Keywords
django github, django, github, python
Install
pip install django-github-user==2019.5.2

Documentation

Travis

Installation

$ [sudo] pip install django-github-user

settings.py

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    "taggit",
    "django_github_user",
]

Models

model __doc__
django_github_user.models.Repo repo model. fields: id, node_id, name, full_name, private, fork, description, homepage, language, forks_count, stargazers_count, watchers_count, open_issues_count, subscribers_count, network_count, size, has_issues, has_projects, has_wiki, has_pages, has_downloads, archived, disabled, pushed_at, created_at, updated_at, topics
django_github_user.models.StarredRepo starred repo model. new fields: starred_at
django_github_user.models.Gist gist model. fields: id, node_id, public, created_at, updated_at, description, comments
django_github_user.models.StarredGist starred gists. same fields as Gist model

Commands

command help
python manage.py import-starred-repos import starred repos
python manage.py import-gists import my gists
python manage.py import-repos import my repos
python manage.py import-starred-gists import starred gists

Examples

$ python -u manage.py import-repos
$ python -u manage.py import-starred-repos
$ python -u manage.py import-gists
$ python -u manage.py import-starred-gists

views.py

from django_github_user.models import Gist, Repo, StarredGist, StarredRepo


class View:
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["repos"] = Repo.objects.filter(full_name__contains=settings.GITHUB_USERNAME).filter(fork=False).filter(private=False).all()
        context["starred_repos"] = StarredRepo.objects.filter(private=False).all()
        context["gists"] = Gist.objects.filter(public=True).all()
        context["starred_gists"] = StarredGist.objects.filter(public=True).all()
        return context

index.html

{% for repo in repos %}
    <h3><a href="{{ repo.html_url }}">{{repo.name}}</a></h3>
    <div class="tags">
    {% for topic in repo.topics.all %}
        <a class="topic-tag topic-tag-link f6" href="#">{{ topic.name }}</a>
    {% endfor % }
    </div>
{% endfor %}

Links

django-readme-generator