Django Tutorials for Drop Down

2017-02-02 Thread Michelle
Hello!

Does anyone know of any Django tutorials for creating a drop down? The 
one's I found thus far are subpar.

Many thanks!

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afb1e14a-adb2-434f-b458-8d1af9221329%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django custom Model.Fields

2017-02-02 Thread Fabien Millerand
Hi all,



down votefavorite 


I am trying to create a Model Fields that is basically a AutoField, but in 
base 36.

Here my definition:

  class AutoBase36Field(models.AutoField):
description = _("AutoField on base36")

@staticmethod
def base36encode(number):

try:
number = int(number)
except:
raise TypeError('number must be an integer')

if not isinstance(number, int):
raise TypeError('number must be an integer')
if number < 0:
raise ValueError('number must be positive')

alphabet, base36 = ['0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '']

while number:
number, i = divmod(number, 36)
base36 = alphabet[i] + base36

return base36 or alphabet[0]

@staticmethod
def base36decode(string):
if string is None:
return None
return int(string, 36)

def to_python(self, value):
if value is None:
return value
try:
return self.base36encode(value)
except (TypeError, ValueError):
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)

def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return self.base36encode(value)

def get_prep_value(self, value):
if value is None:
return None
return self.base36decode(value)

And here is a Model class I am using:

class Content(models.Model):

mzk_id = AutoBase36Field(auto_created=True, primary_key=True, 
serialize=False, verbose_name='ID')
name = models.TextField()

I have a test failing:

def test_incrementation_of_content_mzk_id(self):

content1 = Content(name="a")
content1.save()

mzk_id_1 = int(content1.mzk_id, 36)

As mzk_id is kept as an integer. Basically when creating the incremented 
field, Django doesn't go through to_python()... I am not sure why...

Does anyone could help me up?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c4300e7-80af-4fc5-b71c-31d6c0814a06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


set_language language switcher with 3 languages

2017-02-02 Thread Reto Steffen
Hi,

I have a website with 2 languages and am using the standard
{% load i18n %} {% 
csrf_token %}  
 {% get_current_language as LANGUAGE_CODE %} {% 
get_available_languages as LANGUAGES %} {% get_language_info_list for 
LANGUAGES as languages %} {% for language in languages %}  {{ language.name_local }} ({{ language.code }})  {% 
endfor %}   

from 
https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#the-set-language-redirect-view

But now I'm adding a third language and

is redirecting to the "next" language but not necessarily the one the user 
selects.

Is there a standard way for solving this? Or do I need to write my own 
set_language function?

Thanks!



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/517d2433-04c6-4e9b-9259-ced34016bb7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels - query_string

2017-02-02 Thread Andrew Godwin
Ah, yes, sorry, the default serializer in Django cannot serialise model
instances as it's JSON-based:
https://docs.djangoproject.com/en/1.10/topics/serialization/

You can try switching to an alternate serialiser like pickle which does
(but I don't recommend this), or just put the ID of the user into the
session and then re-fetch it later on.

Andrew

On Thu, Feb 2, 2017 at 12:48 AM, Sgiath  wrote:

> Thanks for explaining.
> I have one problem: when I try to save User object to the channel_session
> I get exception: TypeError: Object of type 'User' is not JSON
> serializable.
> What am I doing wrong? Should I somehow define how to JSON serialize the
> User object?
>
> On Wednesday, February 1, 2017 at 7:01:47 PM UTC+1, Andrew Godwin wrote:
>>
>> Hi,
>> You're right - a lot of the information only appears in the first
>> "connect" message. If you want to persist it, you can use a channel
>> session: http://channels.readthedocs.io/en/stable/getting-
>> started.html#persisting-data
>>
>> This will let you save information (such as the token, or even a User
>> object) into the session in the connect consumer, and then let you use it
>> in other consumers that have the same decorator.
>>
>> Andrew
>>
>>
>> On Wed, Feb 1, 2017 at 5:34 AM, Sgiath  wrote:
>>
>>> Hi,
>>> I am trying to use the query_string parameter and I want to ask what is
>>> the correct way how to use it.
>>> I am using JsonWebsocketConsumer and when debugging I noticed that on
>>> the Handshake the message content contains path, headers, query_string,
>>> client, server, reply_channel and order.
>>> But every other message contains just reply_channel, path, order and
>>> text.
>>> How should I correctly use it? Specifically I want authenticate user
>>> based on the query_string (I send token in it) I can do that in
>>> connection phase but what should I do next? On every other message the user
>>> is AnnonymousUser because there is no query_string. Should I save
>>> query_string into channel_session? Should I save user into
>>> channel_session?
>>> BTW I cannot use user from http session because I am connecting to WS
>>> from the mobile app.
>>>
>>> Thanks
>>>
>>> --
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/a30535e3-29e1-4547-af70-0e391d1b80d3%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/4a618140-c90b-4ac8-baab-2aef366545b8%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uqzq%3DQ2KJEXd2PWWFrOk97nJZD2ouvnUffgnc1mgzq2aA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


DJANGO images(upload/download)

2017-02-02 Thread Xristos Xristoou


who is the better method to take images from uses(visitors)on the fly on my 
web site and to return the new images(with some processing) back to users 
using DJANGO?

i am new i dont know how to connect my python script with the html 
templates to take the images and how to return. 

for example my script take images paths to processing new images with new 
paths. a simple image classification with GDAL :


# Input file name (thermal image)
src = "thermal.tif"
# Output file name
tgt = "classified.jpg"
# Load the image into numpy using gdal
srcArr = gdalnumeric.LoadFile(src)
# Split the histogram into 20 bins as our classes
classes = gdalnumeric.numpy.histogram(srcArr, bins=20)[1]
# Color look-up table (LUT) - must be len(classes)+1.# Specified as R,G,B 
tuples 
lut = 
[[255,0,0],[191,48,48],[166,0,0],[255,64,64],[255,115,115],[255,116,0],[191,113,48],[255,178,115],[0,153,153],[29,115,115],[0,99,99],[166,75,0],[0,204,0],[51,204,204],[255,150,64],[92,204,204],[38,153,38],
\ [0,133,0],[57,230,57],[103,230,103],[184,138,0]]
# Starting value for classification
start = 1
# Set up the RGB color JPEG output image
rgb = gdalnumeric.numpy.zeros((3, srcArr.shape[0],
srcArr.shape[1],), gdalnumeric.numpy.float32)
# Process all classes and assign colorsfor i in range(len(classes)):
mask = gdalnumeric.numpy.logical_and(start <= \
 srcArr, srcArr <= classes[i])
for j in range(len(lut[i])):
  rgb[j] = gdalnumeric.numpy.choose(mask, (rgb[j], \ lut[i][j]))
start = classes[i]+1 
# Save the image
gdalnumeric.SaveArray(rgb.astype(gdalnumeric.numpy.uint8), \
tgt, format="JPEG")


This script takes image input src a take new image with classification. but i 
dont know how to programming the post,get and image output from the python 
script in html form template .

i know to change python script in Django to can run i html template maybe for 
the input like this variable = request.POST.get('variable', False) and the 
output image like this return render_to_response ('blog/calc.html', {'variable' 
:variable,

but i dont have experience with this and i dont know if this method is better 
or no.


can i have django form without files upload to save samoe path ?


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12569464-369a-4918-9729-db6380439440%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImportError while starting django server

2017-02-02 Thread Tim Graham
It seems like your Python install might be broken. Does this import work in 
a Python shell:

>>> from logging.config import dictConfig

On Thursday, February 2, 2017 at 7:12:38 AM UTC-5, Parth Shah wrote:
>
> *Folks,*
>
> *I was following the tutorial here 
>  and was 
> successfully able to install django.*
>
> *I am using python 2.7.13 on OS X.*
>
> *I can verify the version number as below:*
>
>
> *Macitosh:project user$ python*
>
> *Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) *
>
> *[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin*
>
> *Type "help", "copyright", "credits" or "license" for more information.*
>
> *>>> import django*
>
> *>>> print(django.get_version())*
>
> *1.10.5*
>
> *>>>*
>
>
> *But when I try to run the version check using a different command I get 
> the below error, and the same error while subsequently starting the server*
>
>
> *Parths-Macitosh:project parth$ python -m django --version*
>
> *Traceback (most recent call last):*
>
> *  File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", 
> line 174, in _run_module_as_main*
>
> *"__main__", fname, loader, pkg_name)*
>
> *  File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", 
> line 72, in _run_code*
>
> *exec code in run_globals*
>
> *  File "/Library/Python/2.7/site-packages/django/__main__.py", line 9, in 
> *
>
> *management.execute_from_command_line()*
>
> *  File 
> "/Library/Python/2.7/site-packages/django/core/management/__init__.py", 
> line 367, in execute_from_command_line*
>
> *utility.execute()*
>
> *  File 
> "/Library/Python/2.7/site-packages/django/core/management/__init__.py", 
> line 341, in execute*
>
> *django.setup()*
>
> *  File "/Library/Python/2.7/site-packages/django/__init__.py", line 22, 
> in setup*
>
> *configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)*
>
> *  File "/Library/Python/2.7/site-packages/django/utils/log.py", line 69, 
> in configure_logging*
>
> *logging_config_func = import_string(logging_config)*
>
> *  File 
> "/Library/Python/2.7/site-packages/django/utils/module_loading.py", line 
> 27, in import_string*
>
> *six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])*
>
> *  File 
> "/Library/Python/2.7/site-packages/django/utils/module_loading.py", line 
> 23, in import_string*
>
> *return getattr(module, class_name)*
>
> *ImportError: Module "logging.config" does not define a "dictConfig" 
> attribute/class*
>
>
> Any thoughts?
>
>
> Thanks,
>
> PS
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6792993e-f4e7-425c-b9f8-d269651ec821%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Email attachments in Django1.10 failing

2017-02-02 Thread Tim Graham
Could you include a complete traceback that shows which line is causing the 
error?

On Wednesday, February 1, 2017 at 8:10:53 PM UTC-5, E kamande wrote:
>
> Hi Kindly need help to be able attaching a logo and a pdf when emailing, I 
> have been following this great articles 1 
> 
>  
> and 2 
> 
>  
>  but it seems am always getting something wrong.
> Here is a sample code of mine , It fails the following error 
>  " is not JSON 
> serializable"
>
> connection = mail.get_connection()
> msg = EmailMultiAlternatives(
> subject, from_email, receiver)
>
> msg.attach_alternative(mail_body, 'text/html')
> image = MIMEImage(insurer.company_logo.read())
> image.add_header('Content-ID', '<{}>'.format('logo.png'))
>
> msg.attach('logo.png',image, 'image/png')
> msg.send()
> connection.send_messages([msg])
>
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e9f27aeb-2d60-45cb-a232-226b6ceee148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sqlmigrate does not quote default string values

2017-02-02 Thread Tim Graham
It looks like a bug at first glance. I encourage you to look at Django's 
source code and try to confirm and fix it.

On Wednesday, February 1, 2017 at 8:11:21 PM UTC-5, Michael Grijalva wrote:
>
> Not sure if this is considered a bug, but the SQL output from sqlmigrate 
> contains a small syntax error with default string values:
>
> Add a new column as so:
> class City(models.Model):
> ...
> name = models.CharField(max_length=100, default='a b c d')
>
> Create migration, and run sqlmigrate command:
> BEGIN;
> --
> -- Add field name to city
> --
> ALTER TABLE `map_city` ADD COLUMN `name ` varchar(100) DEFAULT a b c d 
> NOT NULL;
> ALTER TABLE `map_city` ALTER COLUMN `name ` DROP DEFAULT;
> COMMIT;
>
> Notice 'a b c d' is missing quotes. When this migration is actually 
> applied it runs through cursor.execute, which properly quotes the value.
>
> I realize sqlmigrate is only for getting a preview of the SQL, but other 
> parts like the table name and columns are correctly quoted, so why not the 
> default?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb9e589e-1528-4cba-89dd-0ec07609a691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Link to urls containing slug

2017-02-02 Thread 'David Turner' via Django users
Hi Matthew
Yes the error was in the view.

Many thanks for all you help.

On 2 February 2017 at 14:14, David Turner  wrote:

> Hi Matthew
> I understand what you are saying but I think the issue rests with my view
> as the link does not resolve but effectively creates the following:
>   /jobs/1/slug-name/%E2%80%9D/jobs/1/slug-name/job_application/%E2%80%9D
>
> Best
>
> On 1 February 2017 at 19:04, Matthew Pava  wrote:
>
>> Hi David,
>>
>> Thank you for the clarification, but it doesn’t change my response much.
>>
>> Use the {% url %} tag in your detail view template.
>>
>> Job
>> Application Form
>>
>>
>>
>> I thought you had a JobApplication model, but you can use the Job model
>> just as above.  Use the job object you passed into the detail view to
>> obtain the job_id and slug of the job.
>>
>> Thank you,
>>
>> Matthew
>>
>>
>>
>> *From:* 'David Turner' via Django users [mailto:django-users@googlegro
>> ups.com]
>> *Sent:* Wednesday, February 1, 2017 1:44 AM
>>
>> *To:* django-users@googlegroups.com
>> *Subject:* Re: Link to urls containing slug
>>
>>
>>
>> Hi Matthew
>>
>>
>>
>> I think I might not have explained my issue fully.
>>
>> Within my jobs models.py I have the following:
>>
>> def get_absolute_url(self):
>>
>> kwargs = {
>>
>>   'job_id': self.job_id,
>>
>>   'slug': self.slug,
>>
>>}
>>
>> return reverse('job_detail', kwargs=kwargs)
>>
>>
>>
>> I have the following urls patterns:
>>
>> url(r'^$', views.JobListView.as_view(), name='job_list'),
>>
>> url(r'^(?P[-\w]*)/(?P[-\w]*)/$',
>> views.JobDetail.as_view(), name='job_detail'),
>>
>>
>>
>> At this stage everything works fine so that clicking on a job in the job
>> list takes you through to the detail for that job.
>>
>> I have then created an application form for the jobs as follows:
>>
>> def job_application(request, job_id, slug):
>>
>> # Retrieve job by id
>>
>> job = get_object_or_404(Job, job_id=job_id)
>>
>> sent = False
>>
>>
>>
>> if request.method == 'POST':
>>
>> # Form was submitted
>>
>> form = JobForm(request.POST)
>>
>> if form.is_valid():
>>
>> # Form fields passed validation
>>
>> cd = form.cleaned_data
>>
>> job_url = request.build_absolute_uri(job.get_absolute_url())
>>
>> subject = '{} ({}) Application for  "{}"'.format(cd['name'],
>> cd['email'], job.title)
>>
>> message = 'Application for "{}" at {}\n\n{}\'s comments:
>> {}'.format(job.title,  job_url, cd['name'], cd['comments'])
>>
>> from_email = ''
>>
>> to_list = ['']
>>
>> send_mail(subject, message, from_email, to_list)
>>
>> sent = True
>>
>> else:
>>
>> form = JobForm()
>>
>> return render(request, 'jobs/job_application.html', {'job': job,
>> 'form': form, 'sent': sent})
>>
>>
>>
>> The url for this form is:
>>
>> url(r'^(?P[-\w]*)/(?P[-\w]*)/job_application/$',
>> views.job_application, name='job_application'),
>>
>>
>>
>> I can go to this link directly in my browser as follows:
>>
>> http://localhost:8000/jobs/1/slug-name/job_application/
>>
>> What I am looking to achieve is a link within the job detail page for
>> that specific job that takes you through to the application fom for that
>> job.
>>
>>
>>
>> Any advice gratefully appreciated.
>>
>>
>>
>> On 31 January 2017 at 16:32, Matthew Pava  wrote:
>>
>> Hi David,
>>
>> Please make sure you have a get_absolute_url method on your
>> JobApplication model in order for that to work and that you passing
>> job_application in through the context in the template.
>>
>> If you don’t have that method, you could use the {% url %} tag, but you
>> would have to provide the pk and slug as arguments.
>>
>> > slug=job_application.slug %}”>{{ job_application }}
>>
>>
>>
>> Good luck!
>>
>>
>>
>> *From:* 'David Turner' via Django users [mailto:django-users@googlegro
>> ups.com]
>> *Sent:* Tuesday, January 31, 2017 9:09 AM
>> *To:* django-users@googlegroups.com
>> *Subject:* Re: Link to urls containing slug
>>
>>
>>
>> I had tried that but unfortunately it doesn't work but thanks anyway.
>>
>>
>>
>> On 31/01/2017 14:57, Matthew Pava wrote:
>>
>> Assuming I’m understanding your question correctly, all you need to do is
>> reference get_absolute_url in your template.
>>
>> Something like so:
>>
>>
>>
>> {{ job_application
>> }}
>>
>>
>>
>> *From:* 'dtdave' via Django users [mailto:django-users@googlegroups.com
>> ]
>> *Sent:* Tuesday, January 31, 2017 8:46 AM
>> *To:* Django users
>> *Subject:* Link to urls containing slug
>>
>>
>>
>> Within my model I have the following that links through to a detail page.
>>
>> def get_absolute_url(self):
>>
>>
>>
>> kwargs = {
>>
>>   'job_id': self.job_id,
>>
>>   'slug': self.slug,
>>
>>}
>>
>> return reverse('job_detail', kwargs=kwargs)
>>
>>
>>
>> Everything works fine with this.
>>

Re: Link to urls containing slug

2017-02-02 Thread 'David Turner' via Django users
Hi Matthew
I understand what you are saying but I think the issue rests with my view
as the link does not resolve but effectively creates the following:
  /jobs/1/slug-name/%E2%80%9D/jobs/1/slug-name/job_application/%E2%80%9D

Best

On 1 February 2017 at 19:04, Matthew Pava  wrote:

> Hi David,
>
> Thank you for the clarification, but it doesn’t change my response much.
>
> Use the {% url %} tag in your detail view template.
>
> Job
> Application Form
>
>
>
> I thought you had a JobApplication model, but you can use the Job model
> just as above.  Use the job object you passed into the detail view to
> obtain the job_id and slug of the job.
>
> Thank you,
>
> Matthew
>
>
>
> *From:* 'David Turner' via Django users [mailto:django-users@
> googlegroups.com]
> *Sent:* Wednesday, February 1, 2017 1:44 AM
>
> *To:* django-users@googlegroups.com
> *Subject:* Re: Link to urls containing slug
>
>
>
> Hi Matthew
>
>
>
> I think I might not have explained my issue fully.
>
> Within my jobs models.py I have the following:
>
> def get_absolute_url(self):
>
> kwargs = {
>
>   'job_id': self.job_id,
>
>   'slug': self.slug,
>
>}
>
> return reverse('job_detail', kwargs=kwargs)
>
>
>
> I have the following urls patterns:
>
> url(r'^$', views.JobListView.as_view(), name='job_list'),
>
> url(r'^(?P[-\w]*)/(?P[-\w]*)/$', views.JobDetail.as_view(),
> name='job_detail'),
>
>
>
> At this stage everything works fine so that clicking on a job in the job
> list takes you through to the detail for that job.
>
> I have then created an application form for the jobs as follows:
>
> def job_application(request, job_id, slug):
>
> # Retrieve job by id
>
> job = get_object_or_404(Job, job_id=job_id)
>
> sent = False
>
>
>
> if request.method == 'POST':
>
> # Form was submitted
>
> form = JobForm(request.POST)
>
> if form.is_valid():
>
> # Form fields passed validation
>
> cd = form.cleaned_data
>
> job_url = request.build_absolute_uri(job.get_absolute_url())
>
> subject = '{} ({}) Application for  "{}"'.format(cd['name'],
> cd['email'], job.title)
>
> message = 'Application for "{}" at {}\n\n{}\'s comments:
> {}'.format(job.title,  job_url, cd['name'], cd['comments'])
>
> from_email = ''
>
> to_list = ['']
>
> send_mail(subject, message, from_email, to_list)
>
> sent = True
>
> else:
>
> form = JobForm()
>
> return render(request, 'jobs/job_application.html', {'job': job,
> 'form': form, 'sent': sent})
>
>
>
> The url for this form is:
>
> url(r'^(?P[-\w]*)/(?P[-\w]*)/job_application/$',
> views.job_application, name='job_application'),
>
>
>
> I can go to this link directly in my browser as follows:
>
> http://localhost:8000/jobs/1/slug-name/job_application/
>
> What I am looking to achieve is a link within the job detail page for that
> specific job that takes you through to the application fom for that job.
>
>
>
> Any advice gratefully appreciated.
>
>
>
> On 31 January 2017 at 16:32, Matthew Pava  wrote:
>
> Hi David,
>
> Please make sure you have a get_absolute_url method on your JobApplication
> model in order for that to work and that you passing job_application in
> through the context in the template.
>
> If you don’t have that method, you could use the {% url %} tag, but you
> would have to provide the pk and slug as arguments.
>
>  slug=job_application.slug %}”>{{ job_application }}
>
>
>
> Good luck!
>
>
>
> *From:* 'David Turner' via Django users [mailto:django-users@
> googlegroups.com]
> *Sent:* Tuesday, January 31, 2017 9:09 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Link to urls containing slug
>
>
>
> I had tried that but unfortunately it doesn't work but thanks anyway.
>
>
>
> On 31/01/2017 14:57, Matthew Pava wrote:
>
> Assuming I’m understanding your question correctly, all you need to do is
> reference get_absolute_url in your template.
>
> Something like so:
>
>
>
> {{ job_application }}
>
>
>
> *From:* 'dtdave' via Django users [mailto:django-users@googlegroups.com
> ]
> *Sent:* Tuesday, January 31, 2017 8:46 AM
> *To:* Django users
> *Subject:* Link to urls containing slug
>
>
>
> Within my model I have the following that links through to a detail page.
>
> def get_absolute_url(self):
>
>
>
> kwargs = {
>
>   'job_id': self.job_id,
>
>   'slug': self.slug,
>
>}
>
> return reverse('job_detail', kwargs=kwargs)
>
>
>
> Everything works fine with this.
>
>
>
> Within my urls.py I have the following:
>
> url(r'^$', views.JobListView.as_view(), name='job_list'),
>
> url(r'^(?P[-\w]*)/(?P[-\w]*)/$', views.JobDetail.as_view(),
> name='job_detail'),
>
> url(r'^(?P[-\w]*)/(?P[-\w]*)/job_application/$',
> views.job_application, name=‘job_application'),
>
>
>
> Then within my views.py the following:
>
> def

Re: ImportError while starting django server

2017-02-02 Thread Antonis Christofides
Hi,

the --version option of the "python" command shows you the version of Python,
not of Django. The -m option doesn't merely import the module you specify, it
imports it and executes it, and Django isn't designed to do this. So the way to
check its version the one you showed first. If you want to run it with a
one-liner, it's this:

python -c 'import django; print(django.get_version())'

Antonis Christofides
http://djangodeployment.com


On 02/02/2017 07:16 AM, Parth Shah wrote:
> /Folks,/
> /
> /
> /I was following the tutorial here
>  and was
> successfully able to install django./
> /
> /
> /I am using python 2.7.13 on OS X./
> /
> /
> /I can verify the version number as below:/
>
>
> *Macitosh:project user$ python*
>
> *Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) *
>
> *[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin*
>
> *Type "help", "copyright", "credits" or "license" for more information.*
>
> *>>> import django*
>
> *>>> print(django.get_version())*
>
> *1.10.5*
>
> *>>>*
>
> */
> /*
>
> /But when I try to run the version check using a different command I get the
> below error, and the same error while subsequently starting the server/
>
>
> *Parths-Macitosh:project parth$ python -m django --version*
>
> *Traceback (most recent call last):*
>
> *  File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",
> line 174, in _run_module_as_main*
>
> *"__main__", fname, loader, pkg_name)*
>
> *  File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",
> line 72, in _run_code*
>
> *exec code in run_globals*
>
> *  File "/Library/Python/2.7/site-packages/django/__main__.py", line 9, in
> *
>
> *management.execute_from_command_line()*
>
> *  File
> "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line
> 367, in execute_from_command_line*
>
> *utility.execute()*
>
> *  File
> "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line
> 341, in execute*
>
> *django.setup()*
>
> *  File "/Library/Python/2.7/site-packages/django/__init__.py", line 22, in 
> setup*
>
> *configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)*
>
> *  File "/Library/Python/2.7/site-packages/django/utils/log.py", line 69, in
> configure_logging*
>
> *logging_config_func = import_string(logging_config)*
>
> *  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py",
> line 27, in import_string*
>
> *six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])*
>
> *  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py",
> line 23, in import_string*
>
> *return getattr(module, class_name)*
>
> **
>
> *ImportError: Module "logging.config" does not define a "dictConfig"
> attribute/class*
>
> *
> *
>
> Any thoughts?
>
>
> Thanks,
>
> PS
>
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ff5c496c-7be7-4ca7-a5b4-88b2744ee3c2%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc2cb83b-db26-0a27-4d94-61b8d80f6bd3%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


ImportError while starting django server

2017-02-02 Thread Parth Shah
*Folks,*

*I was following the tutorial here 
 and was 
successfully able to install django.*

*I am using python 2.7.13 on OS X.*

*I can verify the version number as below:*


*Macitosh:project user$ python*

*Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) *

*[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin*

*Type "help", "copyright", "credits" or "license" for more information.*

*>>> import django*

*>>> print(django.get_version())*

*1.10.5*

*>>>*


*But when I try to run the version check using a different command I get 
the below error, and the same error while subsequently starting the server*


*Parths-Macitosh:project parth$ python -m django --version*

*Traceback (most recent call last):*

*  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", 
line 174, in _run_module_as_main*

*"__main__", fname, loader, pkg_name)*

*  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", 
line 72, in _run_code*

*exec code in run_globals*

*  File "/Library/Python/2.7/site-packages/django/__main__.py", line 9, in 
*

*management.execute_from_command_line()*

*  File 
"/Library/Python/2.7/site-packages/django/core/management/__init__.py", 
line 367, in execute_from_command_line*

*utility.execute()*

*  File 
"/Library/Python/2.7/site-packages/django/core/management/__init__.py", 
line 341, in execute*

*django.setup()*

*  File "/Library/Python/2.7/site-packages/django/__init__.py", line 22, in 
setup*

*configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)*

*  File "/Library/Python/2.7/site-packages/django/utils/log.py", line 69, 
in configure_logging*

*logging_config_func = import_string(logging_config)*

*  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py", 
line 27, in import_string*

*six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])*

*  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py", 
line 23, in import_string*

*return getattr(module, class_name)*

*ImportError: Module "logging.config" does not define a "dictConfig" 
attribute/class*


Any thoughts?


Thanks,

PS

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff5c496c-7be7-4ca7-a5b4-88b2744ee3c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: good doc and example on how to use bootstrap with DJango

2017-02-02 Thread Thames Khi
Thanks I will take a look. So much to learn too much fun.

On Thursday, February 2, 2017 at 2:40:15 AM UTC, Melvyn Sopacua wrote:
>
> On Wednesday 01 February 2017 02:40:48 Thames Khi wrote:
>
>  
>
> > I tried to use locally installed bootstrap. My render HTML function is
>
> > calling my page. However using the relative path or even if add the
>
> > complete path, nothing works.
>
>  
>
> Save some time down the road:
>
> https://github.com/dyve/django-bootstrap3
>
>  
>
> > Is there any decent documentation and examples of using locally
>
> > installed bootstrap with django?
>
>  
>
> Answered by Andreas.
>
> -- 
>
> Melvyn Sopacua
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/300b9c6c-fc25-466f-8c3f-0289dc1bb857%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels - query_string

2017-02-02 Thread Sgiath
Thanks for explaining.
I have one problem: when I try to save User object to the channel_session I 
get exception: TypeError: Object of type 'User' is not JSON serializable.
What am I doing wrong? Should I somehow define how to JSON serialize the 
User object?

On Wednesday, February 1, 2017 at 7:01:47 PM UTC+1, Andrew Godwin wrote:
>
> Hi,
> You're right - a lot of the information only appears in the first 
> "connect" message. If you want to persist it, you can use a channel 
> session: 
> http://channels.readthedocs.io/en/stable/getting-started.html#persisting-data
>
> This will let you save information (such as the token, or even a User 
> object) into the session in the connect consumer, and then let you use it 
> in other consumers that have the same decorator.
>
> Andrew
>
>
> On Wed, Feb 1, 2017 at 5:34 AM, Sgiath > 
> wrote:
>
>> Hi,
>> I am trying to use the query_string parameter and I want to ask what is 
>> the correct way how to use it.
>> I am using JsonWebsocketConsumer and when debugging I noticed that on 
>> the Handshake the message content contains path, headers, query_string, 
>> client, server, reply_channel and order.
>> But every other message contains just reply_channel, path, order and text
>> . 
>> How should I correctly use it? Specifically I want authenticate user 
>> based on the query_string (I send token in it) I can do that in 
>> connection phase but what should I do next? On every other message the user 
>> is AnnonymousUser because there is no query_string. Should I save 
>> query_string into channel_session? Should I save user into 
>> channel_session?
>> BTW I cannot use user from http session because I am connecting to WS 
>> from the mobile app.
>>
>> Thanks
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a30535e3-29e1-4547-af70-0e391d1b80d3%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4a618140-c90b-4ac8-baab-2aef366545b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.