mirror of
https://github.com/Findus23/acronomy.git
synced 2024-09-19 15:33:45 +02:00
add integrations page and popular pages
This commit is contained in:
parent
c4d66f71c1
commit
39d199718d
11 changed files with 154 additions and 6 deletions
|
@ -35,7 +35,7 @@ class AcronymAdmin(SimpleHistoryAdmin):
|
|||
]
|
||||
filter_horizontal = ["tags"]
|
||||
readonly_fields = ["slug"]
|
||||
list_display = ["name", "full_name"]
|
||||
list_display = ["name", "full_name", "pageviews"]
|
||||
list_filter = ["tags", "modified_date", "created_date"]
|
||||
search_fields = ["name", "full_name", "description_md"]
|
||||
save_on_top = True
|
||||
|
|
32
acros/management/commands/matomo-import.py
Normal file
32
acros/management/commands/matomo-import.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
|
||||
from acronomy.settings import DEBUG
|
||||
from acros.models import Acronym
|
||||
from acros.utils.matomo import fetch_matomo_pages
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Fetches Acronym Popularity from Matomo'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
with transaction.atomic():
|
||||
for pagestat in fetch_matomo_pages():
|
||||
url: str = pagestat["label"]
|
||||
if not url.startswith("/acronym/"):
|
||||
continue
|
||||
fragments = url.split("/")
|
||||
if len(fragments) != 3:
|
||||
continue
|
||||
slug = fragments[2]
|
||||
try:
|
||||
acronym = Acronym.objects.get(slug=slug)
|
||||
except Acronym.DoesNotExist:
|
||||
if DEBUG:
|
||||
continue
|
||||
else:
|
||||
raise
|
||||
print(acronym)
|
||||
views = pagestat["nb_visits"]
|
||||
acronym.pageviews = views
|
||||
acronym.save()
|
23
acros/migrations/0047_auto_20200720_1534.py
Normal file
23
acros/migrations/0047_auto_20200720_1534.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.8 on 2020-07-20 15:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('acros', '0046_auto_20200719_1944'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='acronym',
|
||||
name='pageviews',
|
||||
field=models.IntegerField(default=0, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalacronym',
|
||||
name='pageviews',
|
||||
field=models.IntegerField(default=0, editable=False),
|
||||
),
|
||||
]
|
|
@ -29,6 +29,7 @@ class Acronym(models.Model):
|
|||
stub = models.BooleanField(default=True, help_text="check if this is a minimal entry that should be extended")
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
modified_date = models.DateTimeField(auto_now=True)
|
||||
pageviews = models.IntegerField(default=0, editable=False)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.description_html = md_to_html(self.description_md)
|
||||
|
|
|
@ -34,12 +34,51 @@
|
|||
Popular Acronyms
|
||||
</div>
|
||||
<div class="card-body">
|
||||
Coming soon…
|
||||
<ul class="nav popular">
|
||||
{% for acr in popular_acronyms %}
|
||||
<li class="nav-item">
|
||||
<a href="{% url "detail" acr.slug %}" class="nav-link" title="{{ acr.full_name }}">
|
||||
{{ acr.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row cardrow">
|
||||
<div class="col-sm">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Integrations
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<em>Search for the meaning of acronyms from your favourite program!</em>
|
||||
</div>
|
||||
<a class="card-footer" href="{% url "integrations" %}">
|
||||
View all integrations
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Acronomy API
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<em>Build your own application using acronomy data!</em>
|
||||
</div>
|
||||
<a class="card-footer" href="/api/">
|
||||
Browse the API
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block searchInput %}autofocus{% endblock %}
|
||||
|
|
21
acros/templates/integrations.html
Normal file
21
acros/templates/integrations.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
{% block heading %}
|
||||
<h1 class="acronym">Integrations</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>KDE KRunner</h2>
|
||||
|
||||
<img src="{% static "images/integrations/krunner.png" %}" alt="Screenshot of KRunner">
|
||||
<p>
|
||||
Search for acronyms directly from the KDE KRunner launcher.
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://github.com/Findus23/acronomy-krunner/">Code and Setup</a>
|
||||
</p>
|
||||
|
||||
<h3>More to come…</h3>
|
||||
<p>If you are interested in building your own, take a look at the <a href="/api/">API Documentation</a>.</p>
|
||||
{% endblock %}
|
|
@ -20,7 +20,7 @@ sitemaps = {
|
|||
urlpatterns = [
|
||||
path('account/', include('django.contrib.auth.urls')),
|
||||
path("sitemap.xml", cache_page(60 * 15)(sitemap), {"sitemaps": sitemaps}, name="sitemap"),
|
||||
path('api/', include(router.urls)),
|
||||
path('api/', include(router.urls), name="api"),
|
||||
path('', views.IndexView.as_view(), name='index'),
|
||||
path('acronym', RedirectView.as_view(pattern_name="overview")),
|
||||
path('acronym/add', views.AddView.as_view(), name="add"),
|
||||
|
@ -34,7 +34,7 @@ urlpatterns = [
|
|||
path('tags', views.TagListView.as_view(), name='tags'),
|
||||
path('tag', RedirectView.as_view(pattern_name="tags")),
|
||||
path('tag/<str:slug>', views.TagAcroView.as_view(), name='tag'),
|
||||
|
||||
path('integrations', views.IntegrationsView.as_view(), name="integrations")
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
21
acros/utils/matomo.py
Normal file
21
acros/utils/matomo.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from datetime import date
|
||||
|
||||
import requests
|
||||
|
||||
from acronomy.settings import MATOMO_API_KEY
|
||||
|
||||
|
||||
def fetch_matomo_pages():
|
||||
url = "https://matomo.lw1.at/index.php" \
|
||||
"?period=range" \
|
||||
"&date=2010-01-01," + str(date.today()) + \
|
||||
"&filter_limit=-1" \
|
||||
"&flat=1" \
|
||||
"&format=JSON" \
|
||||
"&idSite=29" \
|
||||
"&method=Actions.getPageUrls" \
|
||||
"&module=API" \
|
||||
f"&token_auth={MATOMO_API_KEY}"
|
||||
print(url)
|
||||
r = requests.get(url)
|
||||
return r.json()
|
|
@ -22,10 +22,16 @@ class IndexView(generic.TemplateView):
|
|||
data = super().get_context_data(**kwargs)
|
||||
aotd = AcroOfTheDay.objects.filter(date=date.today()).select_related('acronym')
|
||||
data['acronyms_of_the_day'] = aotd
|
||||
popular = Acronym.objects.filter(pageviews__gt=0).order_by('-pageviews')[:5]
|
||||
data['popular_acronyms'] = popular
|
||||
data['num_acronyms'] = Acronym.objects.all().count()
|
||||
return data
|
||||
|
||||
|
||||
class IntegrationsView(generic.TemplateView):
|
||||
template_name = "integrations.html"
|
||||
|
||||
|
||||
class PageNotFoundView(generic.TemplateView):
|
||||
template_name = "404.html"
|
||||
|
||||
|
|
BIN
static/images/integrations/krunner.png
Normal file
BIN
static/images/integrations/krunner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
|
@ -210,7 +210,7 @@ footer {
|
|||
}
|
||||
|
||||
|
||||
.aotd {
|
||||
.aotd, .popular {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,12 @@ footer {
|
|||
height: inherit;
|
||||
}
|
||||
|
||||
.wikilink {
|
||||
p a {
|
||||
text-decoration-line: underline;
|
||||
text-decoration-style: dashed;
|
||||
}
|
||||
|
||||
|
||||
.cardrow, #autocomplete {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue