--- /dev/null
+from django.contrib import admin
+from django.contrib.sites.models import Site
+from . import models
+
+
+class RedirectAdmin(admin.ModelAdmin):
+ list_display = ['slug', 'url', 'counter', 'created_at', 'full_url']
+ readonly_fields = ['counter', 'created_at', 'full_url']
+ fields = ['slug', 'url', 'counter', 'created_at', 'full_url']
+
+ def full_url(self, obj):
+ site = Site.objects.get_current()
+ url = obj.get_absolute_url()
+ return f'https://{site.domain}{url}'
+
+
+admin.site.register(models.Redirect, RedirectAdmin)
--- /dev/null
+from django.apps import AppConfig
+
+
+class RedirectsConfig(AppConfig):
+ name = 'redirects'
--- /dev/null
+# Generated by Django 2.2.10 on 2020-04-30 08:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Redirect',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('slug', models.SlugField(unique=True)),
+ ('url', models.CharField(max_length=255)),
+ ('counter', models.IntegerField(default=0)),
+ ('created_at', models.DateTimeField(auto_now_add=True)),
+ ],
+ ),
+ ]
--- /dev/null
+from django.db import models
+from django.urls import reverse
+
+
+class Redirect(models.Model):
+ slug = models.SlugField(unique=True)
+ url = models.CharField(max_length=255)
+ counter = models.IntegerField(default=0)
+ created_at = models.DateTimeField(auto_now_add=True)
+
+ def get_absolute_url(self):
+ return reverse('redirect', args=[self.slug])
+
+ def update_counter(self):
+ type(self).objects.filter(pk=self.pk).update(counter=models.F('counter') + 1)
+
--- /dev/null
+from django.test import TestCase
+
+# Create your tests here.
--- /dev/null
+from django.urls import path
+from . import views
+from stats.utils import piwik_track_view
+
+urlpatterns = [
+ path('<slug:slug>/', piwik_track_view(views.WLRedirectView.as_view()), name='redirect'),
+]
--- /dev/null
+from django.shortcuts import get_object_or_404
+from django.views.generic.base import RedirectView
+from . import models
+
+
+class WLRedirectView(RedirectView):
+ permanent = False
+
+ def get_redirect_url(self, slug):
+ redirect = get_object_or_404(models.Redirect, slug=slug)
+ redirect.update_counter()
+ return redirect.url
'paypal',
'push',
'club.apps.ClubConfig',
+ 'redirects.apps.RedirectsConfig',
]
INSTALLED_APPS_CONTRIB = [
path('formularz/', include('forms_builder.forms.urls')),
path('isbn/', include('isbn.urls')),
path('messaging/', include('messaging.urls')),
+ path('re/', include('redirects.urls')),
path('paypal/app-form/', RedirectView.as_view(
url='/towarzystwo/?app=1', permanent=False)),