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

2015-06-20 Thread Dennis Marwood
I found that the "correct" way to address this issue is to use 
raw_id_fields.

On Tuesday, 16 June 2015 19:46:51 UTC-7, Dennis Marwood wrote:
>
> 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/9ab8d2ea-cf84-4e4f-ae21-507d70ed6e00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom UserChangeForm shows one list correctly and the other doesn't show values

2015-06-20 Thread Erik Cederstrand

> Den 20/06/2015 kl. 14.20 skrev Néstor Boscán :
> 
> I've created a custom UserChangeForm in DJango 1.7.8 where I have 2 custom 
> ComboBox associated with a Model. Both are defined exactly the same. One 
> shows the values and the + button to add a new entity. The second only shows 
> an empty list.
> 
> Any ideas?

Post your code?

Erik

-- 
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/73F6BAE5-6C05-4C54-936F-644893DE9CBF%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Inconsistency when importing views and models

2015-06-20 Thread jorrit787
Thank you for the very detailed explanations everyone!


On Saturday, June 20, 2015 at 3:11:34 AM UTC+2, jorr...@gmail.com wrote:
>
> This is mostly a cosmetic question, and I could be completely wrong 
> because I'm fairly new to Django, or it could be that there is a perfectly 
> logical explanation for this, but here goes:
>
> It seems the code required to import views in urls.py and models in 
> views.py is inconsistent (and in the case of urls.py perhaps redudant). 
>
> To import views in urls.py I have to use
>
> from  import views
>
> ...while in views.py I can simply write
>
> from models import *
>
> Why do I need to reference the appname in urls.py but not in views.py? Or 
> is there a reason for this?
>

-- 
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/7c0f2244-862e-415c-be4a-d5e9120e36f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Errors with django-rest-auth and django-allauth

2015-06-20 Thread Luis Zárate
As say Stephen Butler you need to install django.contrib.sites (it not
enable by default) and set

SITE_ID = 1 in your settings.

Here is the reference:
https://docs.djangoproject.com/en/1.8/ref/contrib/sites/#enabling-the-sites-framework



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyOFoMOBQnRXpdmH1W%3D9THLv8KmuqY6xJqZo98h_Y2Se9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Custom UserChangeForm shows one list correctly and the other doesn't show values

2015-06-20 Thread Néstor Boscán
Hi

I've created a custom UserChangeForm in DJango 1.7.8 where I have 2 custom
ComboBox associated with a Model. Both are defined exactly the same. One
shows the values and the + button to add a new entity. The second only
shows an empty list.

Any ideas?

Regards,

Néstor

-- 
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/CALyLaQ%2Bi7tEiiH8NVCcn-CzYcDzv%3D7aDV3BJhSDcWAc%2BTrUf%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: comment and uncomments in django html template

2015-06-20 Thread Daniel Roseman
On Friday, 19 June 2015 17:48:41 UTC+1, Sindhujit Ganguly wrote:
>
> This does not work for javascript defined inside html templates.. This is 
> for html structures.. I needed for multiple line comments in js scripts.
>
>> 
>>
>
That is totally false. Anything within a Django comment tag will not be 
rendered in the output, whether it's HTML or JS.

But if you need comments inside JS scripts, why don't you use JS comment 
syntax?
--
DR.

-- 
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/482d978c-cee4-4ead-bdb4-e676ce61e35b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NameError: name 'reciever' is not defined

2015-06-20 Thread Marco Neumann
Thanks for your response.

I need a extra pair of eyes. :-)

Op zaterdag 20 juni 2015 00:27:07 UTC+2 schreef Marco Neumann:
>
> Hi There,
>
> Im stuck on above error. Anyone a hint? Many thanks
>
> My code in models.py:
>
> from django.db.models.signals import post_save
> from django.dispatch import receiver
> from django.db import models
> from django.contrib.auth.models import User
>
> class UserProfile(models.Model):
> user = models.OneToOneField(User)
> bio = models.TextField(max_length=500, null=True, blank=True)
> 
> def __unicode__(self):
> return self.user.username
> 
> @reciever(post_save, sender=User)
> def create_profile(sender, instance, created, **kwargs):
> if created:
> profile, new = UserProfile.objects.get_or_created(user=instance)
>
>
>
>

-- 
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/7b3d8e1d-bd85-48db-9501-cb6e16b6d325%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NameError: name 'reciever' is not defined

2015-06-20 Thread Marco Neumann
Need a extra pair of eyes. :-)

Thanks for your answer

Op zaterdag 20 juni 2015 00:43:00 UTC+2 schreef James Schneider:
>
> Check your spelling for receiver...
>
> -James
> On Jun 19, 2015 3:26 PM, "Marco Neumann"  > wrote:
>
>> Hi There,
>>
>> Im stuck on above error. Anyone a hint? Many thanks
>>
>> My code in models.py:
>>
>> from django.db.models.signals import post_save
>> from django.dispatch import receiver
>> from django.db import models
>> from django.contrib.auth.models import User
>>
>> class UserProfile(models.Model):
>> user = models.OneToOneField(User)
>> bio = models.TextField(max_length=500, null=True, blank=True)
>> 
>> def __unicode__(self):
>> return self.user.username
>> 
>> @reciever(post_save, sender=User)
>> def create_profile(sender, instance, created, **kwargs):
>> if created:
>> profile, new = UserProfile.objects.get_or_created(user=instance)
>>
>>
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/9dd30923-5e94-49d1-a321-a199138777a5%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/259b90c0-4ec2-419d-8e9c-19f3d9a802e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Errors with django-rest-auth and django-allauth

2015-06-20 Thread Stephen J. Butler
One of your other apps needs django.contrib.sites, so you need to put it in
your INSTALLED_APPS. That's what this means here:

Model class django.contrib.sites.models.Site doesn't declare an explicit
app_label and either *isn't in an application in INSTALLED_APPS* or else
was imported before its application was loaded.

And here:

Field defines a relation with model 'Site', which is either *not installed*,
or is abstract



On Sat, Jun 20, 2015 at 2:53 AM, Daniel Grace  wrote:

> I have installed Django (1.8), django-allauth (0.20.0) django-rest-auth
> (0.4.0).
>
> I added to INSTALLED_APPS in settings.py:
> 'rest_framework',
> 'rest_framework.authtoken',
> 'rest_auth'
> 'allauth',
> 'allauth.account',
> 'rest_auth.registration',
> 'allauth.socialaccount',
> 'allauth.socialaccount.providers.facebook',
>
> And I added to TEMPLATES - OPTIONS - context_processors in settings.py:
> 'django.core.context_processors.request',
> 'allauth.account.context_processors.account',
> 'allauth.socialaccount.context_processors.socialaccount',
>
> When I run the server (python manage.py runserver) I get several errors:
>
> C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
> : RemovedInDjango19Warning: Model class django.contrib.sites.models.Site
> doesn't
>  declare an explicit app_label and either isn't in an application in
> INSTALLED_A
> PPS or else was imported before its application was loaded. This will no
> longer
> be supported in Django 1.9.
>   class Site(models.Model):
>
>
> C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
> : RemovedInDjango19Warning: Model class django.contrib.sites.models.Site
> doesn't
>  declare an explicit app_label and either isn't in an application in
> INSTALLED_A
> PPS or else was imported before its application was loaded. This will no
> longer
> be supported in Django 1.9.
>   class Site(models.Model):
>
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrapper
>  at 0x0438DBF8>
> Traceback (most recent call last):
>   File
> "C:\Users\Daniel\venvs\castle\lib\site-packages\django\utils\autoreload.p
> y", line 223, in wrapper
> fn(*args, **kwargs)
>   File
> "C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\co
> mmands\runserver.py", line 110, in inner_run
> self.validate(display_num_errors=True)
>   File
> "C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
> se.py", line 465, in validate
> return self.check(app_configs=app_configs,
> display_num_errors=display_num_er
> rors)
>   File
> "C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
> se.py", line 524, in check
> raise SystemCheckError(msg)
> django.core.management.base.SystemCheckError: SystemCheckError: System
> check ide
> ntified some issues:
>
> ERRORS:
> socialaccount.SocialApp.sites: (fields.E300) Field defines a relation with
> model
>  'Site', which is either not installed, or is abstract
>
> --
> 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/826d3374-9eb3-4067-93e2-6be3e7bbe805%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAD4ANxU-9ci6KeZ810TjMT7be2Cj6EiVetgxYeXANcVZe1o8Aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Errors with django-rest-auth and django-allauth

2015-06-20 Thread Daniel Grace
I have installed Django (1.8), django-allauth (0.20.0) django-rest-auth 
(0.4.0).

I added to INSTALLED_APPS in settings.py:
'rest_framework',
'rest_framework.authtoken',
'rest_auth'
'allauth',
'allauth.account',
'rest_auth.registration',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',

And I added to TEMPLATES - OPTIONS - context_processors in settings.py:
'django.core.context_processors.request',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',

When I run the server (python manage.py runserver) I get several errors:
C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site 
doesn't
 declare an explicit app_label and either isn't in an application in 
INSTALLED_A
PPS or else was imported before its application was loaded. This will no 
longer
be supported in Django 1.9.
  class Site(models.Model):

C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site 
doesn't
 declare an explicit app_label and either isn't in an application in 
INSTALLED_A
PPS or else was imported before its application was loaded. This will no 
longer
be supported in Django 1.9.
  class Site(models.Model):

Performing system checks...

Unhandled exception in thread started by .wrapper
 at 0x0438DBF8>
Traceback (most recent call last):
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\utils\autoreload.p
y", line 223, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\co
mmands\runserver.py", line 110, in inner_run
self.validate(display_num_errors=True)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
se.py", line 465, in validate
return self.check(app_configs=app_configs, 
display_num_errors=display_num_er
rors)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
se.py", line 524, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System 
check ide
ntified some issues:

ERRORS:
socialaccount.SocialApp.sites: (fields.E300) Field defines a relation with 
model
 'Site', which is either not installed, or is abstract

-- 
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/826d3374-9eb3-4067-93e2-6be3e7bbe805%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.