Skip to content

Commit

Permalink
Merge pull request #30 from matagus/misc-fixes-6
Browse files Browse the repository at this point in the history
Added test coverage report + code coverage tracking + README badge
  • Loading branch information
matagus authored Feb 8, 2024
2 parents 809ee44 + d9c858a commit 43240a5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[report]
show_missing = True
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade hatch
- name: Run tests for Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} on ${{ matrix.os }}
- name: Run tests for Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} on ${{ matrix.os }} with coverage report
run: |
hatch run test.py${{ matrix.python-version }}-${{ matrix.django-version }}:test
hatch run test.py${{ matrix.python-version }}-${{ matrix.django-version }}:cov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ django_generic_links.egg-info/
generic_links.egg-info/
.tox
.coverage
coverage.*
project/
htmlcov/
db.sqlite3
78 changes: 64 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
django-generic-links
====================

![Python Compatibility](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg) [![PyPi Version](https://img.shields.io/pypi/v/django-generic-links.svg)](https://pypi.python.org/pypi/django-generic-links) ![CI badge](https://github.com/matagus/django-generic-links/actions/workflows/ci.yml/badge.svg) [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
![Python Compatibility](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg) [![PyPi Version](https://img.shields.io/pypi/v/django-generic-links.svg)](https://pypi.python.org/pypi/django-generic-links) ![CI badge](https://github.com/matagus/django-generic-links/actions/workflows/ci.yml/badge.svg) [![codecov](https://codecov.io/gh/matagus/django-generic-links/graph/badge.svg?token=a64SxEDQk0)](https://codecov.io/gh/matagus/django-generic-links) [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

Simple app to attach links to any Django model. Compatible with Django 4.x to 5.0 and Python 3.9 to 3.12.

Expand All @@ -19,28 +19,34 @@ Features
Installation
============

Installing `django-generic-links` is fairly easy. You can...
Via `pip` command:

pip install django-generic-links
```bash
pip install django-generic-links
```

...or, you can clone the repo and install it the old fashioned way.
...or you can clone the repo and install it using `pip` too:

git clone git://github.com/matagus/django-generic-links.git
cd django-generic-links
pip install -e .
```bash
git clone git://github.com/matagus/django-generic-links.git
cd django-generic-links
pip install -e .
```

then add `generic_links` to your `settings.py`:

``` python
```python
INSTALLED_APPS = (
# ...
"generic_links",
)
```

and then run the migrations!
and then run the migrations:

# python manage.py migrate
```bash
python manage.py migrate
```


Usage
Expand All @@ -53,16 +59,47 @@ Imagine you have a music app in your project where you save and manage artist's
And you'd like to store and display links for each artist, say her facebook page, her youtube artist page and her
last.fm profile page:

![](docs/images/usage.png)

```python
>>> from generic_links.models import GenericLink
>>> from music.models import Artist
>>> # Get an artist from our database...
>>> lou_reed = Artist.objects.get(pk=1)
>>> lou_reed
<Artist: Lou Reed>
>>> # Create the first link
>>> link1 = GenericLink()
>>> link1.title = "Wikipedia Page"
>>> link1.url = "http://en.wikipedia.org/wiki/Lou_Reed"
>>> link1.is_external = True
>>> linkl.content_object = lour_reed
>>> link1.save()
>>> # and then a second one
>>> link2 = GenericLink()
>>> link2.title = "Youtube artist page"
>>> link2.url = "http://www.youtube.com/artist/lou_reed" >>> link2.is_external = True
>>> link2.content_object
>>> link2.save()
```

Generic Links Inline Admin
--------------------------

Since a `GenericLink` instance will be associated to another object you usually
wish to show an inline model admin form in that model form.

![](docs/images/inline.png)
```python
from django.contrib import admin

from generic_links.admin import GenericLinkStackedInline

from music_app.models import Artist


@admin.register(Artist)
class ArtistAdmin(admin.ModelAdmin):
# ...
inlines = [GenericLinkStackedInline]
```


Using django-generic-links templatetags
Expand All @@ -71,7 +108,20 @@ Using django-generic-links templatetags
Now imagine you have an artist page. You're passing `artist` object using template
context and you want to get all the links for it:

![](docs/images/templatetags.png)
```html
{% load generic_links_tags %}

<hl>{{ artist.name }}</hl>
<p>{{ artist.description }}</p>
<h2>Links for {{ artist.name }}</h2>
{% get_links_for artist as artist_links %}
<ul>
{% for link in artist_links %}
‹li><a href="{{ link.url }}" title="{{ link.title }}"> {{ link. title }}</a></li>
{% endfor %}
</ul>
```


Development / Contributions
===========================
Expand Down
Binary file removed docs/images/admin.png
Binary file not shown.
Binary file removed docs/images/inline.png
Binary file not shown.
Binary file removed docs/images/templatetags.png
Binary file not shown.
Binary file removed docs/images/usage.png
Binary file not shown.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ dependencies = ["coverage[toml]", "django~={matrix:django}.0"]
[tool.hatch.envs.test.scripts]
test = "python -m django test --settings tests.settings"
test-cov = "coverage run -m django test --settings tests.settings"
cov-report = ["coverage combine", "coverage report"]
cov-report = ["coverage json", "coverage report"]
cov = ["test-cov", "cov-report"]
test-cov-report = ["test-cov", "cov-report"]

[tool.ruff]
line-length = 120
Expand Down

0 comments on commit 43240a5

Please sign in to comment.