From f69064a89e04604203636bd4bbef6f11265a35be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monge=20Moreno?= Date: Tue, 31 May 2016 14:11:09 +0200 Subject: [PATCH] Django 1.9+ --- painlessseo/admin.py | 23 ++-- painlessseo/locale/ru/LC_MESSAGES/django.po | 44 ------- painlessseo/migrations/0001_initial.py | 122 ++++++++---------- painlessseo/migrations/0002_add_view_name.py | 52 -------- ...03_auto__add_field_seometadata_priority.py | 53 -------- painlessseo/models.py | 5 +- 6 files changed, 64 insertions(+), 235 deletions(-) delete mode 100644 painlessseo/locale/ru/LC_MESSAGES/django.po delete mode 100644 painlessseo/migrations/0002_add_view_name.py delete mode 100644 painlessseo/migrations/0003_auto__add_field_seometadata_priority.py diff --git a/painlessseo/admin.py b/painlessseo/admin.py index 9bd6e50..9d925c7 100644 --- a/painlessseo/admin.py +++ b/painlessseo/admin.py @@ -1,20 +1,21 @@ # Copyright (C) 2014 Glamping Hub (https://glampinghub.com) # License: BSD 3-Clause +from django import forms from django.contrib import admin from django.core import exceptions -from django.contrib.contenttypes import generic -from django.contrib.contenttypes.models import ContentType -from painlessseo.models import SeoMetadata, SeoRegisteredModel -from painlessseo.utils import register_seo_signals from django.utils.translation import activate, get_language from django.contrib.contenttypes.models import ContentType -from django import forms +from django.contrib.contenttypes.forms import BaseGenericInlineFormSet +from django.contrib.contenttypes.admin import GenericTabularInline from django.forms import TextInput, Textarea from django.db import models from django.utils.text import slugify from django.db.models import Count +from painlessseo.models import SeoMetadata, SeoRegisteredModel +from painlessseo.utils import register_seo_signals + class ViewNameFilter(admin.SimpleListFilter): title = 'View' @@ -86,9 +87,9 @@ def lookups(self, request, model_admin): res = [] models = SeoRegisteredModel.objects.values( - 'content_type__id', 'content_type__name').distinct() + 'content_type__id', 'content_type__model').distinct() for seomodel in list(models): - res.append((seomodel['content_type__id'], seomodel['content_type__name'])) + res.append((seomodel['content_type__id'], seomodel['content_type__model'])) return res def queryset(self, request, queryset): @@ -98,7 +99,7 @@ def queryset(self, request, queryset): return queryset.all() -class SeoMetadataInlineFormSet(generic.BaseGenericInlineFormSet): +class SeoMetadataInlineFormSet(BaseGenericInlineFormSet): def clean(self): for form in self.forms: if form.cleaned_data: @@ -133,7 +134,7 @@ class BaseModelAdmin(admin.ModelAdmin): } -class SeoMetadataInline(generic.GenericTabularInline): +class SeoMetadataInline(GenericTabularInline): extra = 1 model = SeoMetadata formset = SeoMetadataInlineFormSet @@ -173,8 +174,4 @@ def get_form(self, request, obj=None, **kwargs): defaults.update(kwargs) return super(SeoMetadataAdmin, self).get_form(request, obj, **defaults) - -admin.site.register(SeoRegisteredModel, SeoRegisteredModelAdmin) -admin.site.register(SeoMetadata, SeoMetadataAdmin) - register_seo_signals() diff --git a/painlessseo/locale/ru/LC_MESSAGES/django.po b/painlessseo/locale/ru/LC_MESSAGES/django.po deleted file mode 100644 index af1728f..0000000 --- a/painlessseo/locale/ru/LC_MESSAGES/django.po +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2014 Glamping Hub (https://glampinghub.com) -# License: BSD 3-Clause -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-07-30 00:54+0400\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" - -#: models.py:15 -msgid "Path" -msgstr "Путь" - -#: models.py:16 -msgid "" -"This should be an absolute path, excluding the domain name. Example: '/foo/" -"bar/'." -msgstr "Абсолютный путь без доменного имени. Пример: '/раздел/страница/'." - -#: models.py:17 -msgid "Language" -msgstr "Язык" - -#: models.py:20 -msgid "Title" -msgstr "Заголовок" - -#: models.py:21 -msgid "Description" -msgstr "Описание" - -#: models.py:24 models.py:25 -msgid "SEO metadata" -msgstr "Метаданные SEO" diff --git a/painlessseo/migrations/0001_initial.py b/painlessseo/migrations/0001_initial.py index b0585ee..0843e7b 100644 --- a/painlessseo/migrations/0001_initial.py +++ b/painlessseo/migrations/0001_initial.py @@ -1,72 +1,52 @@ # -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding model 'SeoRegisteredModel' - db.create_table(u'painlessseo_seoregisteredmodel', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'], null=True, blank=True)), - ('lang_code', self.gf('django.db.models.fields.CharField')(default='en', max_length=2)), - ('title', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), - ('description', self.gf('django.db.models.fields.CharField')(max_length=200, null=True, blank=True)), - )) - db.send_create_signal(u'painlessseo', ['SeoRegisteredModel']) - - # Adding model 'SeoMetadata' - db.create_table(u'painlessseo_seometadata', ( - (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'], null=True, blank=True)), - ('object_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True)), - ('lang_code', self.gf('django.db.models.fields.CharField')(default='en', max_length=2)), - ('has_parameters', self.gf('django.db.models.fields.BooleanField')(default=False)), - ('path', self.gf('django.db.models.fields.CharField')(max_length=200, null=True, db_index=True)), - ('title', self.gf('django.db.models.fields.CharField')(max_length=100, null=True)), - ('description', self.gf('django.db.models.fields.CharField')(max_length=200, null=True)), - )) - db.send_create_signal(u'painlessseo', ['SeoMetadata']) - - - def backwards(self, orm): - # Deleting model 'SeoRegisteredModel' - db.delete_table(u'painlessseo_seoregisteredmodel') - - # Deleting model 'SeoMetadata' - db.delete_table(u'painlessseo_seometadata') - - - models = { - u'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - u'painlessseo.seometadata': { - 'Meta': {'ordering': "('path', 'lang_code')", 'object_name': 'SeoMetadata'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True'}), - 'has_parameters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), - 'path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'db_index': 'True'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'}) - }, - u'painlessseo.seoregisteredmodel': { - 'Meta': {'object_name': 'SeoRegisteredModel'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) - } - } - - complete_apps = ['painlessseo'] \ No newline at end of file +# Generated by Django 1.9.6 on 2016-05-31 13:46 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='SeoMetadata', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('view_name', models.CharField(blank=True, max_length=30, null=True, verbose_name='View Name')), + ('object_id', models.PositiveIntegerField(blank=True, null=True, verbose_name='Id')), + ('lang_code', models.CharField(choices=[(b'en', b'English')], default=b'en', max_length=2, verbose_name='Language')), + ('has_parameters', models.BooleanField(default=False, help_text='This indicates if the SEOMetadata path contains parameters.')), + ('path', models.CharField(db_index=True, help_text="This should be an absolute path, excluding the domain name. Example: '/foo/bar/'. You can also capture parameters using '{X}' notation, where X is a positive number.", max_length=200, null=True, verbose_name='Path')), + ('title', models.CharField(help_text="Here you can make use of the parameters captured in the URL using the same '{X}' notation.", max_length=100, null=True, verbose_name='Title')), + ('description', models.CharField(help_text="Here you can make use of the parameters captured in the URL using the same '{X}' notation.", max_length=200, null=True, verbose_name='Description')), + ('priority', models.IntegerField(default=0, help_text='Priority when duplicated. Higher the most priority. Default 0', verbose_name='Priority')), + ('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType', verbose_name='Model')), + ], + options={ + 'ordering': ('path', 'lang_code'), + 'verbose_name': 'SEO Path Metadata', + 'verbose_name_plural': 'SEO Path Metadata', + }, + ), + migrations.CreateModel( + name='SeoRegisteredModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('lang_code', models.CharField(choices=[(b'en', b'English')], default=b'en', max_length=2, verbose_name='Language')), + ('title', models.CharField(blank=True, max_length=100, null=True, verbose_name='Title')), + ('description', models.CharField(blank=True, max_length=200, null=True, verbose_name='Description')), + ('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), + ], + options={ + 'verbose_name': 'SEO Model', + 'verbose_name_plural': 'SEO Models', + }, + ), + ] diff --git a/painlessseo/migrations/0002_add_view_name.py b/painlessseo/migrations/0002_add_view_name.py deleted file mode 100644 index 5492689..0000000 --- a/painlessseo/migrations/0002_add_view_name.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding field 'SeoMetadata.view_name' - db.add_column(u'painlessseo_seometadata', 'view_name', - self.gf('django.db.models.fields.CharField')(max_length=30, null=True, blank=True), - keep_default=False) - - - def backwards(self, orm): - # Deleting field 'SeoMetadata.view_name' - db.delete_column(u'painlessseo_seometadata', 'view_name') - - - models = { - u'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - u'painlessseo.seometadata': { - 'Meta': {'ordering': "('path', 'lang_code')", 'object_name': 'SeoMetadata'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True'}), - 'has_parameters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), - 'path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'db_index': 'True'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'}), - 'view_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}) - }, - u'painlessseo.seoregisteredmodel': { - 'Meta': {'object_name': 'SeoRegisteredModel'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) - } - } - - complete_apps = ['painlessseo'] \ No newline at end of file diff --git a/painlessseo/migrations/0003_auto__add_field_seometadata_priority.py b/painlessseo/migrations/0003_auto__add_field_seometadata_priority.py deleted file mode 100644 index 0ba8f8c..0000000 --- a/painlessseo/migrations/0003_auto__add_field_seometadata_priority.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding field 'SeoMetadata.priority' - db.add_column(u'painlessseo_seometadata', 'priority', - self.gf('django.db.models.fields.IntegerField')(default=0), - keep_default=False) - - - def backwards(self, orm): - # Deleting field 'SeoMetadata.priority' - db.delete_column(u'painlessseo_seometadata', 'priority') - - - models = { - u'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - u'painlessseo.seometadata': { - 'Meta': {'ordering': "('path', 'lang_code')", 'object_name': 'SeoMetadata'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True'}), - 'has_parameters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), - 'path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'db_index': 'True'}), - 'priority': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'}), - 'view_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}) - }, - u'painlessseo.seoregisteredmodel': { - 'Meta': {'object_name': 'SeoRegisteredModel'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lang_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}) - } - } - - complete_apps = ['painlessseo'] \ No newline at end of file diff --git a/painlessseo/models.py b/painlessseo/models.py index 6eb65ee..09f85f0 100644 --- a/painlessseo/models.py +++ b/painlessseo/models.py @@ -1,8 +1,9 @@ # Copyright (C) 2014 Glamping Hub (https://glampinghub.com) # License: BSD 3-Clause -from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.fields import GenericForeignKey +from django.contrib.contenttypes.fields import GenericRelation from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -34,7 +35,7 @@ class SeoMetadata(models.Model): content_type = models.ForeignKey(ContentType, null=True, blank=True, verbose_name=_('Model')) object_id = models.PositiveIntegerField(null=True, blank=True, verbose_name=_('Id')) - content_object = generic.GenericForeignKey('content_type', 'object_id') + content_object = GenericForeignKey('content_type', 'object_id') lang_code = models.CharField(verbose_name=_('Language'), max_length=2, choices=settings.SEO_LANGUAGES,