Skip to content

Commit

Permalink
Django 1.9+
Browse files Browse the repository at this point in the history
  • Loading branch information
AMongeMoreno committed May 31, 2016
1 parent c371224 commit f69064a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 235 deletions.
23 changes: 10 additions & 13 deletions painlessseo/admin.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -133,7 +134,7 @@ class BaseModelAdmin(admin.ModelAdmin):
}


class SeoMetadataInline(generic.GenericTabularInline):
class SeoMetadataInline(GenericTabularInline):
extra = 1
model = SeoMetadata
formset = SeoMetadataInlineFormSet
Expand Down Expand Up @@ -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()
44 changes: 0 additions & 44 deletions painlessseo/locale/ru/LC_MESSAGES/django.po

This file was deleted.

122 changes: 51 additions & 71 deletions painlessseo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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']
# 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',
},
),
]
52 changes: 0 additions & 52 deletions painlessseo/migrations/0002_add_view_name.py

This file was deleted.

This file was deleted.

5 changes: 3 additions & 2 deletions painlessseo/models.py
Original file line number Diff line number Diff line change
@@ -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 _
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f69064a

Please sign in to comment.