I am not able to pass a variable to a widget with its "mark_safe" attribute intact.

2015-06-16 Thread Dennis Marwood
Hello,

I want to display images in my manyTomany so that a user can choose what 
images would be included inside of a "BlogWidgetCarousel". The issue I am 
running into is that the render function for the widget returns html via 
the "format_html" and the variable has lost its "safe" setting at that 
point.

In my model I return the choice_label with "mark_safe" but somewhere along 
the way the string is altered and it must be losing that quality. (For the 
example I just changed it to a  tag)

I have found the render method and confirmed that I can set the string back 
to a safe state and it works fine.

My questions

   1. Am I just making some kind of mistake when I try to send back the 
   string from the model?
   2. Am I doing something that is unexpected? It seems like this should 
   work.
   3. Would you create a custom widget to solve this issue, if not what 
   would you use?
   



#models.py
class BlogWidgetCarousel(models.Model):
entry = models.TextField()
blog = models.ForeignKey(Blog, blank=True, null=True)
position = models.PositiveSmallIntegerField("Position")
images = models.ManyToManyField("Image")

class Meta:
ordering = ('position', )

def __str__(self):
return str(self.position)

def save(self, *args, **kwargs):
self.entry = "TODO: create image slider"
super(BlogWidgetCarousel, self).save(*args, **kwargs)

def display(self):
return self.entry

class Image(models.Model):
title = models.CharField(max_length=60, blank=False, null=False)
image = models.ImageField(upload_to="images/")

def thumb(self):
return ''.\
format(MEDIA_URL + str(self.image))

def __str__(self):
return mark_safe(u'bold')
__str__.allow_tags = True


#admin.py
class BlogWidgetCarouselInline(admin.StackedInline): #, SortableInline):
model = BlogWidgetCarousel
extra = 0

formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}

fieldsets = (
("Create Carousel:", {
'fields': (("position"), 'images',)
}),
("Result:", {
'fields': ('thumb', 'display_as',)
}),
)
readonly_fields = ('display_as', 'thumb',)

def display_as(self, instance):
return instance.display()
display_as.allow_tags = True

def thumb(self, instance):
x = ""
for i in instance.images.all():
x += i.thumb()
return x 
thumb.allow_tags = True

class EntryAdmin(admin.ModelAdmin):
list_display = ("title", "created")
prepopulated_fields = {"slug": ("title",)}
inlines = [
BlogWidgetTextInline, BlogWidgetCarouselInline,
]


#dist-packages/django/forms/widgets
#...
@html_safe
@python_2_unicode_compatible
class ChoiceInput(SubWidget):
"""
An object used by ChoiceFieldRenderer that represents a single
.
"""
input_type = None  # Subclasses must define this

def __init__(self, name, value, attrs, choice, index):
self.name = name
self.value = value
self.attrs = attrs
self.choice_value = force_text(choice[0])
self.choice_label = force_text(choice[1])
self.index = index
if 'id' in self.attrs:
self.attrs['id'] += "_%d" % self.index

def __str__(self):
return self.render()

def render(self, name=None, value=None, attrs=None, choices=()):
if self.id_for_label:
label_for = format_html(' for="{}"', self.id_for_label)
else:
label_for = ''
attrs = dict(self.attrs, **attrs) if attrs else self.attrs
#print self.choice_label < Prints "bold" as expected.
return format_html('{} {}', label_for, 
self.tag(attrs), self.choice_label) # choice_label is escaped by format_html
#return format_html('{} {}', label_for, 
self.tag(attrs), mark_safe(self.choice_label)) <---Works


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4d7ef94-181c-4f09-8471-e038455793e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.8 migrate - relation “django_content_type” already exists

2015-06-16 Thread Leandro Zanuz
Maybe you need make migrations for all your apps or remove all apps to use
migrations. I had the same problems, but with auth_group. In my case, I
removed all apps to use migrations and works fine.

http://stackoverflow.com/questions/25161425/disable-migrations-when-running-unit-tests-in-django-1-7

But on django 1.9 migrations will be mandatory for all apps I think.

2015-06-16 17:18 GMT-03:00 Tim Graham :

> Take a look at the migrate --fake-initial option. It's new in 1.8. In 1.7,
> --fake-initial was an implicit default, but we decided to make it explicit
> in 1.8.
>
>
> https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
>
> On Tuesday, June 16, 2015 at 3:22:39 PM UTC-4, Adam Teale wrote:
>>
>> Hi Guys,
>>
>> Any idea why I would be getting this error when I try to migrate?
>>
>> django.db.utils.ProgrammingError: relation "django_content_type"
>>
>> I am using using django 1.8 & postgresql
>>
>> Thanks!
>>
>> Adam
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0817de32-fa2a-4b63-84df-99758b49ebe5%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Enviado via UCSMail.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACctwSiT9XZz4yriiT_2RMc%2BC4XF4J6ke5o6ztJRMAUaUqt-oQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.8 migrate - relation “django_content_type” already exists

2015-06-16 Thread Tim Graham
Take a look at the migrate --fake-initial option. It's new in 1.8. In 1.7, 
--fake-initial was an implicit default, but we decided to make it explicit 
in 1.8.

https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial

On Tuesday, June 16, 2015 at 3:22:39 PM UTC-4, Adam Teale wrote:
>
> Hi Guys,
>
> Any idea why I would be getting this error when I try to migrate?
>
> django.db.utils.ProgrammingError: relation "django_content_type"
>
> I am using using django 1.8 & postgresql
>
> Thanks!
>
> Adam
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0817de32-fa2a-4b63-84df-99758b49ebe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ProgrammingError: relation "django_content_type" already exists

2015-06-16 Thread Adam Teale
Hey guys did you manage to get anywhere with this?




On Tuesday, 24 March 2015 03:00:28 UTC-3, Mike Dewhirst wrote:
>
> This is my first stab at upgrading directly from Django 1.6.11 to 1.81c 
> to see what needs to be done. I thought I'd skip 1.7.x - is that a bad 
> idea? Is there some step in 1.7.x which eases the path to 1.8.x? 
>
> On first starting the project up using runserver on localhost it advises: 
>
> Python:   3.4 
> Django:   1.8c1 
> Database: ssds.climate.com.au 
> Postgres: 9.1 
> 16:18:54 
>
> Performing system checks... 
>
> System check identified no issues (0 silenced). 
>
> You have unapplied migrations; your app may not work properly until they 
> are applied. 
> Run 'python manage.py migrate' to apply them. 
>
> See below. Not sure where to go from here. Any ideas? 
>
> Thanks 
>
> Mike 
>
> On running manage.py migrate it returns a ProgrammingError as follows: 
>
> (xxex3) C:\Users\mike\env\xxex3\ssds>python manage.py migrate 
> Operations to perform: 
>Synchronize unmigrated apps: admindocs, messages, credit, refer, 
> company, workplace, staticfiles, substance, common 
>Apply all migrations: contenttypes, sessions, auth, sites, admin 
> Synchronizing apps without migrations: 
>Creating tables... 
>  Running deferred SQL... 
>Installing custom SQL... 
> Running migrations: 
>Rendering model states... DONE 
>Applying contenttypes.0001_initial...Traceback (most recent call last): 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py", 
> line 62, in execute 
>  return self.cursor.execute(sql) 
> psycopg2.ProgrammingError: relation "django_content_type" already exists 
>
>
> The above exception was the direct cause of the following exception: 
>
> Traceback (most recent call last): 
>File "manage.py", line 24, in  
>  execute_from_command_line(sys.argv) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",
>  
>
> line 338, in execute_from_command_line 
>  utility.execute() 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",
>  
>
> line 330, in execute 
>  self.fetch_command(subcommand).run_from_argv(self.argv) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\base.py", 
>
> line 390, in run_from_argv 
>  self.execute(*args, **cmd_options) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\base.py", 
>
> line 441, in execute 
>  output = self.handle(*args, **options) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\commands\migrate.py",
>  
>
> line 221, in handle 
>  executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\executor.py", 
>
> line 94, in migrate 
>  self.apply_migration(states[migration], migration, fake=fake, 
> fake_initial=fake_initial) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\executor.py", 
>
> line 131, in apply_migration 
>  state = migration.apply(state, schema_editor) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\migration.py",
>  
>
> line 111, in apply 
>  operation.database_forwards(self.app_label, schema_editor, 
> old_state, project_state) 
>
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\operations\models.py",
>  
>
> line 59, in database_forwards 
>  schema_editor.create_model(model) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\base\schema.py",
>  
>
> line 282, in create_model 
>  self.execute(sql, params or None) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\base\schema.py",
>  
>
> line 107, in execute 
>  cursor.execute(sql, params) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py", 
> line 64, in execute 
>  return self.cursor.execute(sql, params) 
>File "C:\Users\mike\env\xxex3\lib\site-packages\django\db\utils.py", 
> line 97, in __exit__ 
>  six.reraise(dj_exc_type, dj_exc_value, traceback) 
>File "C:\Users\mike\env\xxex3\lib\site-packages\django\utils\six.py", 
> line 658, in reraise 
>  raise value.with_traceback(tb) 
>File 
> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py", 
> line 62, in execute 
>  return self.cursor.execute(sql) 
> django.db.utils.ProgrammingError: relation "django_content_type" already 
> exists 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://

Django 1.8 migrate - relation “django_content_type” already exists

2015-06-16 Thread Adam Teale
Hi Guys,

Any idea why I would be getting this error when I try to migrate?

django.db.utils.ProgrammingError: relation "django_content_type"

I am using using django 1.8 & postgresql

Thanks!

Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d370a81f-2870-4d3d-8e7c-9f035131bc17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Core error in showing records?

2015-06-16 Thread Simon Charette
Hi MikeKJ,

I suppose the ModelAdmin subclass in use here has a list_display method 
marked as boolean 

 
that return an unexpected value 

.

Make sure it either return True, False or None.

Cheers,
Simon

Le mardi 16 juin 2015 09:11:12 UTC-4, MikeKJ a écrit :
>
> Can anyone shed any light on what this is please?
>
> Exception Type: TemplateSyntaxError  Exception Value: 
>
> Caught KeyError while rendering: 10
>
>  Exception Location: 
> /home/paston3/webapps/bbus/lib/python2.7/django/contrib/admin/templatetags/admin_list.py
>  
> in _boolean_icon, line 126
> The effect is that the first 3 pages of 395 records show but page 4 (95 
> records) throws the above error 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cc725ab0-29d3-4a5e-b5f4-3070ff8f6a49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Core error in showing records?

2015-06-16 Thread MikeKJ
Can anyone shed any light on what this is please?

Exception Type: TemplateSyntaxError  Exception Value: 

Caught KeyError while rendering: 10

 Exception Location: 
/home/paston3/webapps/bbus/lib/python2.7/django/contrib/admin/templatetags/admin_list.py
 
in _boolean_icon, line 126
The effect is that the first 3 pages of 395 records show but page 4 (95 
records) throws the above error 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46e1b536-923a-49ca-8c9d-1f2ae147534e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Scaling/Parallel patterns for a View executing complex database transaction

2015-06-16 Thread mesulphur
Exactly! We did prototype with Mongo and Riak to see if there were 
significant performance gains and the answer was no. Well tuned Postgres 
performed as well and as others. Add to this the complexities and risks 
associated with introducing a new component in your stack as against 
something stable and proven.


On Monday 15 June 2015 10:52 AM, Javier Guerra Giraldez wrote:

ity, or distribute the load on
several shards while shifting consistency tradeoffs.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/557FD0F8.9020502%40gmail.com.
For more options, visit https://groups.google.com/d/optout.