Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New database fields #62

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 9 additions & 3 deletions cookie_consent/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
Cookie,
CookieGroup,
LogItem,
CookieType,
)


class CookieAdmin(admin.ModelAdmin):
list_display = ('varname', 'name', 'cookiegroup', 'path', 'domain',
list_display = ('varname', 'name', 'cookiegroup', 'cookietype', 'path', 'domain',
'get_version')
search_fields = ('name', 'domain', 'cookiegroup__varname',
search_fields = ('name', 'domain', 'cookietype__name', 'cookiegroup__varname',
'cookiegroup__name')
readonly_fields = ('varname',)
list_filter = ('cookiegroup',)


class CookieGroupAdmin(admin.ModelAdmin):
list_display = ('varname', 'name', 'is_required', 'is_deletable',
'get_version')
'get_version', 'updated')
search_fields = ('varname', 'name',)
list_filter = ('is_required', 'is_deletable',)

Expand All @@ -31,7 +32,12 @@ class LogItemAdmin(admin.ModelAdmin):
date_hierarchy = 'created'


class CookieTypeAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)

admin.site.register(Cookie, CookieAdmin)
admin.site.register(CookieGroup, CookieGroupAdmin)
admin.site.register(CookieType, CookieTypeAdmin)
if settings.COOKIE_CONSENT_LOG_ENABLED:
admin.site.register(LogItem, LogItemAdmin)
39 changes: 39 additions & 0 deletions cookie_consent/migrations/0003_add_cookietype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('cookie_consent', '0002_auto__add_logitem'),
]

operations = [
migrations.CreateModel(
name='CookieType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=20, null=True)),
],
options={
'verbose_name': 'Cookie Type',
'verbose_name_plural': 'Cookie Types',
'ordering': ('name',),
},
),
migrations.AddField(
model_name='cookie',
name='duration',
field=models.CharField(blank=True, max_length=256, verbose_name='Duration'),
),
migrations.AddField(
model_name='cookiegroup',
name='updated',
field=models.DateTimeField(blank=True, null=True, verbose_name='Updated'),
),
migrations.AddField(
model_name='cookie',
name='cookietype',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookie_consent.CookieType', verbose_name='Cookie Type'),
),
]
20 changes: 20 additions & 0 deletions cookie_consent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CookieGroup(models.Model):
default=True)
ordering = models.IntegerField(_('Ordering'), default=0)
created = models.DateTimeField(_('Created'), auto_now_add=True, blank=True)
updated = models.DateTimeField(_('Updated'), blank=True, null=True)

class Meta:
verbose_name = _('Cookie Group')
Expand All @@ -57,15 +58,34 @@ def save(self, *args, **kwargs):
delete_cache()


class CookieType(models.Model):
name = models.CharField(max_length=20, blank=True, null=True)

def __str__(self):
return self.name

class Meta:
verbose_name = 'Cookie Type'
verbose_name_plural = 'Cookie Types'
ordering = ('name',)


class Cookie(models.Model):
cookiegroup = models.ForeignKey(
CookieGroup,
verbose_name=CookieGroup._meta.verbose_name,
on_delete=models.CASCADE)
cookietype = models.ForeignKey(
CookieType,
verbose_name=CookieType._meta.verbose_name,
blank=True,
null=True,
on_delete=models.CASCADE)
name = models.CharField(_('Name'), max_length=250)
description = models.TextField(_('Description'), blank=True)
path = models.TextField(_('Path'), blank=True, default="/")
domain = models.CharField(_('Domain'), max_length=250, blank=True)
duration = models.CharField('Duration', max_length=250, blank=True)
created = models.DateTimeField(_('Created'), auto_now_add=True, blank=True)

class Meta:
Expand Down
17 changes: 16 additions & 1 deletion cookie_consent/templates/cookie_consent/_cookie_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<div class="cookie-group">
<div class="cookie-group-title">
<h3>{{ cookie_group.name }}</h3>
{% if cookie_group.updated %}
<p> Last updated: {{ cookie_group.updated|date:"m/d/Y" }} </p>
{% endif %}

{% if not cookie_group.is_required %}
<div class="cookie-group-form">
Expand Down Expand Up @@ -34,7 +37,8 @@ <h3>{{ cookie_group.name }}</h3>
{{ cookie_group.description }}
</p>


<details open>
<summary>View cookies</summary>
<table>
{% for cookie in cookie_group.cookie_set.all %}
<tr>
Expand All @@ -44,6 +48,16 @@ <h3>{{ cookie_group.name }}</h3>
({{ cookie.domain }})
{% endif %}
</th>
<td>
{% if cookie.cookietype %}
{{ cookie.cookietype }}
{% endif %}
</td>
<td>
{% if cookie.duration %}
{{ cookie.duration }}
{% endif %}
</td>
<td>
{% if cookie.description %}
{{ cookie.description }}
Expand All @@ -52,5 +66,6 @@ <h3>{{ cookie_group.name }}</h3>
</tr>
{% endfor %}
</table>
</details>

</div>