Skip to content

Commit

Permalink
Použitie get_meta namiesto _meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
mireq committed Aug 17, 2014
1 parent 25f13a9 commit e5ddef7
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 40 deletions.
3 changes: 2 additions & 1 deletion admin_dashboard/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.translation import ugettext_lazy as _

from appgroups import get_application_groups
from common_utils import get_meta


RE_CHANGE_URL = re.compile("(.+)_([^_]+)_change")
Expand All @@ -20,7 +21,7 @@ def init_with_context(self, context):
listitems = self._visible_models(context['request'])
for model, perms in listitems:
if perms['change']:
self.children.append(items.MenuItem(title = capfirst(model._meta.verbose_name_plural), url = self._get_admin_change_url(model, context)))
self.children.append(items.MenuItem(title = capfirst(get_meta(model).verbose_name_plural), url = self._get_admin_change_url(model, context)))


class ReturnToSiteItem(items.MenuItem):
Expand Down
8 changes: 4 additions & 4 deletions attachment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models.fields.files import FileField
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _

from .utils import get_available_size
from common_utils import clean_dir
from common_utils import clean_dir, get_meta


def upload_to(instance, filename):
content_class = instance.content_type.model_class()
return 'attachment/{0}_{1}/{2:02x}/{3}/{4}'.format(
content_class._meta.app_label,
content_class._meta.object_name.lower(),
get_meta(content_class).app_label,
get_meta(content_class).object_name.lower(),
instance.object_id % 256,
instance.object_id,
filename
Expand Down
3 changes: 2 additions & 1 deletion attachment/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
from .forms import AttachmentFormMixin
from .models import UploadSession, Attachment, TemporaryAttachment
from .utils import get_available_size
from common_utils import get_meta
from common_utils.tests_common import ProcessFormTestMixin


class AttachmentModelTest(TestCase):
def setUp(self):
self.testContentType = ContentType.objects.all()[0]
self.ct = self.testContentType.model_class()._meta.db_table
self.ct = get_meta(self.testContentType.model_class()).db_table

def test_upload_session(self):
session1 = UploadSession()
Expand Down
9 changes: 5 additions & 4 deletions blog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
from django.utils.timezone import now

from .models import Blog, Post
from common_utils import get_meta
from rich_editor.forms import RichOriginalField


class BlogForm(forms.ModelForm):
original_description = RichOriginalField(Blog._meta.get_field('original_description').parsers, label=u'Popis', max_length=1000) #pylint: disable=W0212
original_sidebar = RichOriginalField(Blog._meta.get_field('original_sidebar').parsers, label=u'Bočný panel', max_length=1000) #pylint: disable=W0212
original_description = RichOriginalField(get_meta(Blog).get_field('original_description').parsers, label=u'Popis', max_length=1000) #pylint: disable=W0212
original_sidebar = RichOriginalField(get_meta(Blog).get_field('original_sidebar').parsers, label=u'Bočný panel', max_length=1000) #pylint: disable=W0212
class Meta:
model = Blog
exclude = ('author', 'slug')


class PostForm(forms.ModelForm):
original_perex = RichOriginalField(Post._meta.get_field('original_perex').parsers, label=u'Perex', max_length=1000) #pylint: disable=W0212
original_content = RichOriginalField(Post._meta.get_field('original_content').parsers, label=u'Obsah', max_length=100000) #pylint: disable=W0212
original_perex = RichOriginalField(get_meta(Post).get_field('original_perex').parsers, label=u'Perex', max_length=1000) #pylint: disable=W0212
original_content = RichOriginalField(get_meta(Post).get_field('original_content').parsers, label=u'Obsah', max_length=100000) #pylint: disable=W0212
pub_now = forms.BooleanField(label=u'Publikovať teraz', required=False)

def __init__(self, *args, **kwargs):
Expand Down
13 changes: 8 additions & 5 deletions common_utils/tests_common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import os
import unittest
from datetime import datetime

import unittest
from django.contrib.auth import get_user_model
from django.core.management.color import no_style
from django.core.urlresolvers import reverse
Expand All @@ -12,6 +12,8 @@
from django.shortcuts import resolve_url
from django.test import LiveServerTestCase

from common_utils import get_meta


User = get_user_model()

Expand Down Expand Up @@ -176,7 +178,7 @@ class Meta:

@classmethod
def create_table(cls):
raw_sql, refs = connection.creation.sql_create_model(cls, no_style(), [])
raw_sql = connection.creation.sql_create_model(cls, no_style(), [])[0]
create_sql = u'\n'.join(raw_sql).encode('utf-8')
cls.delete_table()
cursor = connection.cursor()
Expand All @@ -189,12 +191,13 @@ def create_table(cls):
def delete_table(cls):
cursor = connection.cursor()
try:
cursor.execute('DROP TABLE IF EXISTS %s' % cls._meta.db_table)
except:
pass
cursor.execute('DROP TABLE IF EXISTS %s' % get_meta(cls).db_table)
finally:
cursor.close()

def __unicode__(self):
return "Test %d" % self.pk


class CreateModelsMixin(object):
temporary_models = ()
Expand Down
3 changes: 2 additions & 1 deletion forum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from antispam.forms import AntispamFormMixin
from attachment.fields import AttachmentField
from attachment.forms import AttachmentFormMixin
from common_utils import get_meta
from models import Topic, Section
from rich_editor.forms import RichOriginalField

Expand Down Expand Up @@ -46,7 +47,7 @@ def __getitem__(self, idx):

class TopicForm(AntispamFormMixin, AttachmentFormMixin, forms.ModelForm):
section = SectionModelChoiceField(Section.objects.all(), empty_label=None, widget = RadioSelect(renderer = SectionRenderer), label = capfirst(_('section')))
original_text = RichOriginalField(parsers = Topic._meta.get_field('original_text').parsers, label = _("Text"), max_length = COMMENT_MAX_LENGTH)
original_text = RichOriginalField(parsers = get_meta(Topic).get_field('original_text').parsers, label = _("Text"), max_length = COMMENT_MAX_LENGTH)
attachment = AttachmentField(label = _("Attachment"), required = False)
upload_session = forms.CharField(label = "Upload session", widget = HiddenInput, required = False)

Expand Down
6 changes: 4 additions & 2 deletions linuxos/templatetags/linuxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django import template
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.template.defaulttags import now, date
from django.template.defaulttags import date
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.encoding import smart_unicode
Expand All @@ -15,6 +15,8 @@
from django_jinja import library
from jinja2 import contextfunction

from common_utils import get_meta


register = template.Library()

Expand Down Expand Up @@ -82,7 +84,7 @@ def filter_contains_tags(messages, tags):
@register.filter
def labelize_content_type(content_type):
app_label, model = content_type.split('.')
return ContentType.objects.get_by_natural_key(app_label = app_label, model = model).model_class()._meta.verbose_name #pylint: disable=W0212
return get_meta(ContentType.objects.get_by_natural_key(app_label = app_label, model = model).model_class()).verbose_name #pylint: disable=W0212


@library.global_function
Expand Down
5 changes: 3 additions & 2 deletions news/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings

from antispam.forms import AntispamFormMixin
from common_utils import get_meta
from models import News
from rich_editor.forms import RichOriginalField

Expand All @@ -11,8 +12,8 @@


class NewsForm(AntispamFormMixin, forms.ModelForm):
original_short_text = RichOriginalField(News._meta.get_field('original_short_text').parsers, label = u'Krátky text', max_length = COMMENT_MAX_LENGTH)
original_long_text = RichOriginalField(News._meta.get_field('original_long_text').parsers, label = u'Dlhý text', max_length = COMMENT_MAX_LENGTH)
original_short_text = RichOriginalField(get_meta(News).get_field('original_short_text').parsers, label = u'Krátky text', max_length = COMMENT_MAX_LENGTH)
original_long_text = RichOriginalField(get_meta(News).get_field('original_long_text').parsers, label = u'Dlhý text', max_length = COMMENT_MAX_LENGTH)

def __init__(self, *args, **kwargs):
logged = kwargs.pop('logged', False)
Expand Down
11 changes: 6 additions & 5 deletions threaded_comments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from antispam.forms import AntispamFormMixin
from attachment.fields import AttachmentField
from attachment.forms import AttachmentFormMixin
from common_utils import get_meta
from rich_editor.forms import RichOriginalField
from threaded_comments.models import Comment

Expand All @@ -31,7 +32,7 @@ class CommentForm(AttachmentFormMixin, AntispamFormMixin, forms.Form):

name = forms.CharField(label = _("Name"), max_length = 50)
subject = forms.CharField(label = _("Subject"), max_length = 100)
original_comment = RichOriginalField(parsers = Comment._meta.get_field('original_comment').parsers, label = _("Comment"), max_length = COMMENT_MAX_LENGTH)
original_comment = RichOriginalField(parsers = get_meta(Comment).get_field('original_comment').parsers, label = _("Comment"), max_length = COMMENT_MAX_LENGTH)
attachment = AttachmentField(label = _("Attachment"), required = False)

def __init__(self, target_object, data = None, initial = None, *args, **kwargs):
Expand Down Expand Up @@ -117,8 +118,8 @@ def get_comment(self):
def generate_security_data(self):
timestamp = int(time())
security_dict = {
'content_type': str(self.target_object._meta),
'object_id': str(self.target_object._get_pk_val()),
'content_type': str(get_meta(self.target_object)._meta),
'object_id': str(self.target_object.pk),
'parent_pk': str(self.parent_comment.pk),
'timestamp': str(timestamp),
'security_hash': self.initial_security_hash(timestamp),
Expand All @@ -128,7 +129,7 @@ def generate_security_data(self):
def initial_security_hash(self, timestamp):
initial_security_dict = {
'content_type': str(self.target_object._meta),
'object_id': str(self.target_object._get_pk_val()),
'object_id': str(self.target_object.pk),
'timestamp': str(timestamp),
}
return self.generate_security_hash(**initial_security_dict)
Expand All @@ -142,7 +143,7 @@ def generate_security_hash(self, content_type, object_id, timestamp):
def get_comment_create_data(self):
return {
'content_type': ContentType.objects.get_for_model(self.target_object),
'object_id': self.target_object._get_pk_val(),
'object_id': self.target_object.pk,
'user_name': self.cleaned_data.get("name", ""),
'original_comment': self.cleaned_data["original_comment"],
'submit_date': timezone.now(),
Expand Down
9 changes: 4 additions & 5 deletions threaded_comments/templatetags/threaded_comments_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from django import template
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models import Count
from django.template.loader import render_to_string
from django.utils import timezone
Expand All @@ -10,7 +9,7 @@
from jinja2 import contextfunction
from mptt.templatetags import mptt_tags

from common_utils import iterify
from common_utils import iterify, get_meta
from threaded_comments.models import Comment, RootHeader, UserDiscussionAttribute


Expand Down Expand Up @@ -113,9 +112,9 @@ def render_threaded_comments_toplevel(context, target):
context = dict(context)
model_class = target.__class__
templates = [
"comments/{0}_{1}_comments_toplevel.html".format(*str(model_class._meta).split('.')),
"comments/{0}_comments_toplevel.html".format(model_class._meta.app_label),
"comments/comments_toplevel.html".format(model_class._meta.app_label),
"comments/{0}_{1}_comments_toplevel.html".format(*str(get_meta(model_class)).split('.')),
"comments/{0}_comments_toplevel.html".format(get_meta(model_class).app_label),
"comments/comments_toplevel.html".format(get_meta(model_class).app_label),
]
context.update({"target": target})
return mark_safe(render_to_string(templates, context))
Expand Down
17 changes: 8 additions & 9 deletions threaded_comments/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# -*- coding: utf-8 -*-

from django import http
from django.contrib.auth.decorators import login_required, permission_required
from django.db import models
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template.defaultfilters import capfirst
from django.template.response import TemplateResponse
from django.views.decorators.http import require_POST
from django.utils.encoding import force_unicode
from django.views.decorators.http import require_POST

from common_utils import get_default_manager, get_meta
from threaded_comments import get_form, signals
from threaded_comments.models import Comment, CommentFlag, RootHeader, UserDiscussionAttribute, update_comments_header
from threaded_comments import get_form
from threaded_comments import signals
from common_utils import get_default_manager


def get_module_name(content_object):
if hasattr(content_object, 'breadcrumb_label'):
return capfirst(content_object.breadcrumb_label)
else:
return capfirst(content_object.__class__._meta.verbose_name_plural)
return capfirst(get_meta(content_object).verbose_name_plural)


def get_module_url(content_object):
Expand All @@ -40,7 +39,7 @@ def reply_comment(request, parent):
else:
new_subject = force_unicode('RE: ') + force_unicode(content_object)

model_meta = content_object.__class__._meta
model_meta = get_meta(content_object)
template_list = [
"comments/{0}_{1}_preview.html".format(*tuple(str(model_meta).split('.'))),
"comments/{0}_preview.html".format(model_meta.app_label),
Expand Down Expand Up @@ -93,8 +92,8 @@ def post_comment(request):

if form.errors or not 'create' in data or parent.is_locked:
template_list = [
"comments/{0}_{1}_preview.html".format(model._meta.app_label, model._meta.module_name),
"comments/{0}_preview.html".format(model._meta.app_label),
"comments/{0}_{1}_preview.html".format(get_meta(model).app_label, get_meta(model).module_name),
"comments/{0}_preview.html".format(get_meta(model).app_label),
"comments/preview.html",
]
valid = not form.errors
Expand Down
3 changes: 2 additions & 1 deletion wiki/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from django.forms.models import ModelForm

from common_utils import get_meta
from rich_editor.forms import RichOriginalField
from wiki.models import Page


class WikiEditForm(ModelForm):
original_text = RichOriginalField(parsers = Page._meta.get_field('original_text').parsers, label = u'Text')
original_text = RichOriginalField(parsers = get_meta(Page).get_field('original_text').parsers, label = u'Text')

class Meta:
model = Page
Expand Down

0 comments on commit e5ddef7

Please sign in to comment.