Sending unsafe requests from web extension to DRF - cannot send Referer

2021-09-30 Thread Brad Solomon
We have a web extension using Chrome Manifest V3 
, which talks with 
a backend web service written with Django (3.2) / Django Rest Framework, 
and served with Gunicorn/Nginx.

After turning on HTTPS, we are no longer to successfully make unsafe (e.g. 
POST) requests to the Django app. The reason things has broken is clear to 
us, but it seems unclear how they can be fixed without turning off csrf 
protection everywhere.

*> csrf failed: referer checking failed: no referer *

As explained in the Django docs, in this scenario, Django requires that the 
client send both a csrf token and a Referer header. 
 Our 
extension can easily grab the csrf token, but it seems impossible to 
actually send a Referer header, which instead seems to be stripped out by 
the browser. Chrome MV3 has switched to `chrome.declarativenetrequest`, 
which currently does not allow a modify or set on request headers (only 
response). This appears to be a known "bug" or a point of contention, 
though depends who you ask.

The Django app requires SessionAuthentication. It uses 
SECURE_REFERRER_POLICY = "no-referrer-when-downgrade". Nginx sends 
X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto to the Django app.

All of this leaves us seemingly SOL. What makes things more tricky is that 
the chrome extension URL is effectively random, e.g. 
chrome-extension://asdfasdfadsf, and this doesn't seem to work with 
CSRF_TRUSTED_ORIGINS anyway.

Are we missing anything here, or are we left to just blanket-csrf_exempt 
everything?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/560b42d9-ec18-4912-ad14-cfab998d8722n%40googlegroups.com.


Replicating complex query with two dense_rank() functions using ORM

2020-11-03 Thread Brad Buran
I have a "puzzle of the day" that users can answer. I track the puzzle of 
the day using the Puzzle model. I track the answers using the PuzzleAnswer 
model. I would like to calculate the number of consecutive puzzles a 
particular user (i.e., the author) gets right in a row. The current SQL I 
use that can calculate the start date of the streak, end date of the streak 
and the number of days in the streak. As you can see, it does a dens_rank 
over the puzzles (to count them in order), then does a join with the 
PuzzleAnswer, then does a second dense rank over the merged tables. I 
figured out how to use the DenseRank function in the Django ORM on the 
Puzzle manager, but I cannot figure out how to do the left join next. Any 
advice?

SELECT min(s.id) AS id, 
   count(s.date) AS streak, 
   min(s.date) AS start_streak, 
   max(s.date) AS end_streak, 
   s.author_id 
  FROM ( SELECT dense_rank() OVER (ORDER BY ROW(pa.author_id, pr.rank)) AS 
id, 
   pa.created AS date, 
   (pr.rank - dense_rank() OVER (ORDER BY ROW(pa.author_id, 
pr.rank))) AS g, 
   pa.author_id 
  FROM (( SELECT "POTD_puzzle".id, 
   dense_rank() OVER (ORDER BY "POTD_puzzle".published) AS 
rank 
  FROM public."POTD_puzzle") pr 
JOIN public."POTD_puzzleanswer" pa ON ((pr.id = pa.puzzle_id))) 
 WHERE pa.correct) s 
 GROUP BY s.author_id, s.g 
 ORDER BY count(s.date) DESC;

The models are:

class PuzzleAnswer(models.Model): 
   puzzle = models.ForeignKey(Puzzle, editable=True, on_delete=models.CASCADE) 

   answer = models.CharField(max_length=64)   
   correct = models.BooleanField(editable=False)
   created = models.DateTimeField(auto_now_add=True) 
   author = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, 

  on_delete=models.SET_NULL) 

  

class Puzzle(models.Model):
   category = models.ForeignKey(PuzzleCategory, on_delete=models.CASCADE, 
help_text=category_help)
   notation = models.CharField(max_length=64) 
   correct_answer = models.CharField(max_length=64) 
   published = models.DateField(blank=True, null=True, db_index=True, unique
=True)

 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3d8106a7-df44-4697-91fe-06c861132ae6n%40googlegroups.com.


Django formset, forms passing unique choices into a choicefield for each form

2019-12-18 Thread Brad Allgood
Initially posted on stack overflow:

https://stackoverflow.com/questions/59395761/passing-dynamic-choices-into-a-formset-unique-for-each-form

I am working on what I thought was a simple college football confidence 
pool. The concept is as follows:

   - Bowl Model: Model that stores information of each bowl game being 
   played this season
   - Team Model: Model for all the teams playing in a bowl with a foreign 
   key to the bowl

models.py

from django.db import models
from django.contrib.auth.models import Group, User

class Bowl(models.Model):
"""Model for Bowl Game information"""
name = models.CharField(max_length=200)
b_date = models.DateField(null=True, blank=True)
b_time = models.TimeField(null=True, blank=True)
tv = models.CharField(max_length=10)
location = models.CharField(max_length=200)

def __str__(self):
"""String for representing the bowl object"""
return self.name

class Team(models.Model):
name = models.CharField(max_length=200)
bowl = models.ForeignKey(Bowl,on_delete=models.SET_NULL,null=True)

def __str__(self):
"""String for representing the intermediate table"""
return self.name   

I'm attempting to create a page has a formset which allows the user to pick 
the predicted winner of each game. Therefore I constructed the following 
view to call the form and formset.
views.py

   def fs_test(request):

   bowl_list = Bowl.objects.all()
   bowl_len = len(bowl_list)
   bowl_data = []

   TestFormSet = formset_factory(TestForm, extra=0)

   for bowl in bowl_list:
  bowl_data.append({
  't_bowl': bowl.name,'t_user':request.user,'t_weight':1,
  't_winner':winner_data,
  })

   if request.method == 'POST':
   pass
   else:
   formset = TestFormSet(initial=bowl_data)

   context = {
   'formset':formset, 'bowl_data':bowl_data
   }
   return render(request, 'catalog/test_bowl.html',context)

The following form inherits pre-populated data via passing "bowl_data" in 
the "initial" parameter.
forms.py

class TestForm(forms.Form):
 def __init__(self, *args, **kwargs):
 super(TestForm, self).__init__(*args, **kwargs)
 self.fields['t_bowl'] = forms.CharField()
 self.fields['t_weight'] = forms.IntegerField()
 self.fields['t_user'] = forms.CharField()
 self.fields['t_winner'] = forms.ChoiceField(
 widget=forms.RadioSelect,
 required=True,
 choices=[(o.name, o.name)
 for o in Team.objects.filter(bowl__name__exact=self.t_bowl)]
 )

I believe pre-populating the t_winner choices are failing because using the 
self.t_bowl in the query is just a field reference not the name of the 
field. I don't know how to pass in the "bowl" name to the form query. Or 
maybe I pre-populate the "choices" in the view but I don't know how to pass 
a dict into it and reference the correct index.

I've done some reading on the get_form_kwargs, but I'm not clear on how to 
use it in this instance.

It's entirely possible I'm using the wrong data model for this task, 
however I've been stumped for a couple of day on this. It took me a while 
to even figure out how to pass in unique "initial" values for each form in 
the formset.

Any recommendations would save what little hair I have left. Thank you!



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f19f3ef-7c5d-409c-98ab-150c07a196e1%40googlegroups.com.


django.core.exceptions.ImproperlyConfigured DJANGO_SETTINGS_MODULE

2019-09-18 Thread Brad S


I am trying to get a new server up and running and I am make a n00b error 
somewhere.


django.core.exceptions.ImproperlyConfigured: Requested setting MIDDLEWARE, but 
settings are not configured. You must either define the environment variable 
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
unable to load app 0 (mountpoint='') (callable not found or import error)


$ cat nerds/settings.py 
"""
Django settings for nerds project.

Generated by 'django-admin startproject' using Django 2.2.5.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ui2+3#j-67et^^76$b^h4pw3c7qbxdc5rj0xuqcq)=0=2'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["nerds.tech","www.nerds.tech"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'support.apps.SupportConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'nerds.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'nerds.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'nerds.db'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'EST'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
#DJANGO_SETTINGS_MODULE="nerds.settings"



$ cat ../uwsgi.ini 
[uwsgi]
module = wsgi:application
#module = wsgi
master = true
chdir = /home/www/nerds.tech/nerds
wsgi-file = /home/www/nerds.tech/nerds/nerds/wsgi.py
#wsgi-file = nerds/nerds/wsgi.py
uid = www-data
gid = www-data
vacuum = true
chmod-socket = 660
socket = /tmp/uwsgi.sock
#plugins = python
die-on-term = true
virtualenv = /home/www/nerds.tech/venv
#pythonpath = /home/www/nerds.tech/venv/lib/python3.5/dist-packages
pythonpath = /home/www/nerds.tech/venv/lib/python3.5/site-packages
pythonpath = /home/www/nerds.tech/venv/lib/python3.5
#pythonpath = ./nerds
pythonpath = /home/www/nerds.tech/nerds
module = django.core.handlers.wsgi:WSGIHandler()
logto = /var/log/nginx/uwsgi.log






$ cat nerds/wsgi.py 
"""
WSGI config for nerds project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os
from django.core.wsgi import get_wsgi_application

#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nerds.settings')

os.environ['DJANGO_SETTINGS_MODULE'] = 'nerds.settings'


#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nerds.settings')

application = get_wsgi_application()

-- 
You received this message because you are subscribed to the Google Groups 
"Django 

mod_wsgi picking up wrong settings

2019-05-14 Thread Brad Rice
I have multiple websites setup on a linode cloud. I am using Virtual Host 
containers with WSGI paths and Virtual Envs for each app. When I set any of 
the apps to Debug = False, they throw 500 errors.

It appears they are using the same wsgi environment settings because the 
error is ALLOWED_HOSTS and it tells me it can't use the ALLOWED_HOSTS 
listed in the other app, not the one I'm trying to run. It appears the the 
wsgi running in deamon mode is bleeding into each other. Any idea what I 
need to do to get it to work? If I set Debug = True, everything works fine. 
I'm not to savy when it comes to wsgi and apache. I just want to build 
sites.

Here are the vhosts:


ServerAdmin bradri...@gmail.com
ServerName dianarice.art
ServerAlias www.dianarice.art



Require all granted



RewriteEngine on
RewriteCond %{SERVER_NAME} =dianarice.art [OR]
RewriteCond %{SERVER_NAME} =www.dianarice.art
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]



ServerAdmin bradri...@gmail.com
ServerName dianarice.art
ServerAlias www.dianarice.art



Require all granted


WSGIScriptAlias / /var/www/webapps/dianarice/dianarice/wsgi.py
WSGIDaemonProcess dianarice.art python-home=/usr/local/venvs/dianarice-env 
python-path=/var/www/webapps/dianarice
WSGIProcessGroup dianarice.art

Alias /robots.txt /var/www/html/static.dianarice.art/public_html/robots.txt
Alias /favicon.ico 
/var/www/html/static.dianarice.art/public_html/favicon.ico
Alias /images /var/www/html/dianarice.art/public_html/images
Alias /static /var/www/html/dianarice.art/public_html/static

LogLevel warn
ErrorLog /var/www/webapps/dianarice/log/error.log
CustomLog /var/www/webapps/dianarice/log/access.log combined


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/dianarice.art-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/dianarice.art-0001/privkey.pem




ServerAdmin bradri...@gmail.com
ServerName medinadiversityproject.org
ServerAlias www.medinadiversityproject.org


Require all granted

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.medinadiversityproject.org [OR]
RewriteCond %{SERVER_NAME} =medinadiversityproject.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


ServerAdmin bradri...@gmail.com
ServerName medinadiversityproject.org
ServerAlias www.medinadiversityproject.org


Require all granted
WSGIScriptAlias / 
/var/www/webapps/medinadiversityproject/medinadiversityproject/wsgi.py
WSGIDaemonProcess medinadiversityproject.org 
python-home=/usr/local/venvs/medinadiversityproject-env 
python-path=/var/www/webapps/medinadiversityproject
WSGIProcessGroup medinadiversityproject.org
# Log file locations
LogLevel info
ErrorLog /var/www/webapps/medinadiversityproject/log/error.log
CustomLog /var/www/webapps/medinadiversityproject/log/access.log combined


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile 
/etc/letsencrypt/live/www.medinadiversityproject.org/fullchain.pem
SSLCertificateKeyFile 
/etc/letsencrypt/live/www.medinadiversityproject.org/privkey.pem



ServerAdmin bradri...@gmail.com
ServerName oh-joy.org
ServerAlias www.oh-joy.org


Require all granted

RewriteEngine on
RewriteCond %{SERVER_NAME} =oh-joy.org [OR]
RewriteCond %{SERVER_NAME} =www.oh-joy.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]



ServerAdmin bradri...@gmail.com
ServerName oh-joy.org
ServerAlias www.oh-joy.org


Require all granted

WSGIProcessGroup ohjoy
WSGIScriptAlias / /var/www/webapps/ohjoy/ohjoy/wsgi.py process-group=ohjoy
WSGIDaemonProcess ohjoy python-home=/usr/local/venvs/ohjoy-env 
python-path=/var/www/webapps/ohjoy 
# Log file locations
LogLevel info
ErrorLog /var/www/webapps/ohjoy/log/error.log
CustomLog /var/www/webapps/ohjoy/log/access.log combined



Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/oh-joy.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/oh-joy.org/privkey.pem


-- 
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/ae96439e-bca1-4f69-8fe0-87aae8a1f988%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Make mobile app from webapp

2019-01-07 Thread Brad Pitcher
The basic formula we've used in the past:
1. Decouple back- and front-end using API
2. Use django-bakery (https://django-bakery.readthedocs.io/en/latest/) to
export the needed pages to HTML (requires the use of class-based views,
which are actually really awesome)
3. Use Phonegap to wrap these HTML pages into an app

Steps 2 and 3 are build steps, the HTML should not be edited or checked in
to source control.

On Mon, Jan 7, 2019 at 11:15 AM maunish dave 
wrote:

> Ya i have little experience of creating API using django rest framework
>
> On Mon 7 Jan, 2019, 11:42 PM Nebojsa Hajdukovic, <
> nebojsa.zero...@gmail.com> wrote:
>
>> You need to create rest api from that app, and then to use in ionic,
>> flutter etc.
>>
>> Do you have experience with django rest framework?
>>
>> pon, 07. jan 2019. 19:10 maunish dave  je
>> napisao/la:
>>
>>> Hi i have a website built with django and now i want to make a mobile
>>> app for it how to do it any suggestions?
>>>
>>> --
>>> 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/CALpJ3uLaDOHgjeuM8dez0hKxZ2M%2BwJn7DhzkbX8hf0GV1mqKOw%40mail.gmail.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/CAJ60hW3UtZbzNuXpgP38%3D2aF6gC4qUHHdV-rPU2YhheKL0RLVw%40mail.gmail.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/CALpJ3u%2B8dOiOXHeyfLxWRwXOtUbWJGTiLV7fnB-VDhcut7H8bw%40mail.gmail.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/CAMFpZrgsZxrHopZf0_cWHaTmmHhYHGFWbF_9p-_4DuaF9mojpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: issue in hosting https://www.pythonanywhere.com

2018-12-25 Thread Brad Pitcher
Atul,
Have you looked over the troubleshooting in
https://help.pythonanywhere.com/pages/DebuggingImportError ? It looks like
your web app is using a separate django installed to the system python
based on the paths in the error log. You should be able to fix that in the
*_wsgi.py file.

On Tue, Dec 25, 2018 at 7:58 AM Brad Pitcher  wrote:

> Can you share your wsgi file created on pythonanywhere?
>
> On Tue, Dec 25, 2018, 1:01 AM Atul Anand 
>> Hi
>> I have activated the venv by below cmd:
>> 07:57 ~/simplesocial (master)$ workon djangoVenv
>> Please let me know do I need to do something else ? Note: I have tried
>> doing the same with cmd:  07:57 ~/simplesocial (master)$ activate. But
>> it throwing error " bash:
>> /home/crackjeeonline/.virtualenvs/djangoVenv/bin/activate: Permission
>> denied"
>>
>>
>> Regard,
>> Atul
>>
>> On Tue, Dec 25, 2018 at 1:08 PM Joel Mathew  wrote:
>>
>>> Did you activate it?
>>> Sincerely yours,
>>>
>>>  Joel G Mathew
>>>
>>>
>>>
>>> On Tue, 25 Dec 2018 at 12:27, Atul Anand 
>>> wrote:
>>>
>>>> Hi Brad,
>>>>
>>>> Thanks for helping, but I am using a venv.
>>>> please find the below snapshot of the venv detail.
>>>>
>>>> Please guide me if I am doing something wrong.
>>>>
>>>> Virtualenv:
>>>>
>>>> Use a virtualenv to get different versions of flask, django etc from
>>>> our default system ones. More info here
>>>> <https://help.pythonanywhere.com/pages/Virtualenvs>. You need to *Reload
>>>> your web app* to activate it; NB - will do nothing if the virtualenv
>>>> does not exist.
>>>>
>>>> /home/crackjeeonline/.virtualenvs/djangoVenv
>>>> <https://www.pythonanywhere.com/user/crackjeeonline/webapps/#>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Dec 25, 2018 at 11:05 AM Brad Pitcher 
>>>> wrote:
>>>>
>>>>> The paths in your logs indicate you aren't using a virtualenv. Find
>>>>> the virtualenv section in the web tab and make sure you specify the path 
>>>>> to
>>>>> your virtualenv there. Should be something like
>>>>> /home/[username]/.virtualenvs/djangoVenv
>>>>>
>>>>> On Mon, Dec 24, 2018 at 8:09 AM Atul Anand 
>>>>> wrote:
>>>>>
>>>>>> I am using virtual env: * djangoVenv*
>>>>>>
>>>>>>
>>>>>> On Mon, Dec 24, 2018 at 7:45 PM Joel Mathew  wrote:
>>>>>>
>>>>>>> Use virtualenv
>>>>>>> Sincerely yours,
>>>>>>>
>>>>>>>  Joel G Mathew
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, 24 Dec 2018 at 19:34, Atul Anand 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> y code is working in local. But the same code when I am uploading
>>>>>>>> into https://www.pythonanywhere.com. Its throwing error.
>>>>>>>>
>>>>>>>> Note: I have updated few things to make it compatible for
>>>>>>>> django2,which is working for me in my local windows box.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> https://www.pythonanywhere.com/user/crackjeeonline/webapps/#tab_id_crackjeeonline_pythonanywhere_com
>>>>>>>>
>>>>>>>> https://github.com/atulanandnitt/simplesocial
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> result of pip freeze
>>>>>>>>
>>>>>>>>
>>>>>>>>1. (djangoVenv) 07:50 ~/simplesocial (master)$ pip freeze
>>>>>>>>2. -f /usr/share/pip-wheels
>>>>>>>>3. argon2-cffi==18.3.0
>>>>>>>>4. bcrypt==3.1.5
>>>>>>>>5. certifi==2018.10.15
>>>>>>>>6. cffi==1.11.5
>>>>>>>>7. chardet==3.0.4
>>>>>>>>8. coreapi==2.3.3
>>>>>>>>9. coreschema==0.0.4
>>>>>>>>10. Django==2.0.9
>>>>>>&g

Re: issue in hosting https://www.pythonanywhere.com

2018-12-25 Thread Brad Pitcher
Can you share your wsgi file created on pythonanywhere?

On Tue, Dec 25, 2018, 1:01 AM Atul Anand  Hi
> I have activated the venv by below cmd:
> 07:57 ~/simplesocial (master)$ workon djangoVenv
> Please let me know do I need to do something else ? Note: I have tried
> doing the same with cmd:  07:57 ~/simplesocial (master)$ activate. But it
> throwing error " bash:
> /home/crackjeeonline/.virtualenvs/djangoVenv/bin/activate: Permission
> denied"
>
>
> Regard,
> Atul
>
> On Tue, Dec 25, 2018 at 1:08 PM Joel Mathew  wrote:
>
>> Did you activate it?
>> Sincerely yours,
>>
>>  Joel G Mathew
>>
>>
>>
>> On Tue, 25 Dec 2018 at 12:27, Atul Anand 
>> wrote:
>>
>>> Hi Brad,
>>>
>>> Thanks for helping, but I am using a venv.
>>> please find the below snapshot of the venv detail.
>>>
>>> Please guide me if I am doing something wrong.
>>>
>>> Virtualenv:
>>>
>>> Use a virtualenv to get different versions of flask, django etc from our
>>> default system ones. More info here
>>> <https://help.pythonanywhere.com/pages/Virtualenvs>. You need to *Reload
>>> your web app* to activate it; NB - will do nothing if the virtualenv
>>> does not exist.
>>>
>>> /home/crackjeeonline/.virtualenvs/djangoVenv
>>> <https://www.pythonanywhere.com/user/crackjeeonline/webapps/#>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Dec 25, 2018 at 11:05 AM Brad Pitcher 
>>> wrote:
>>>
>>>> The paths in your logs indicate you aren't using a virtualenv. Find the
>>>> virtualenv section in the web tab and make sure you specify the path to
>>>> your virtualenv there. Should be something like
>>>> /home/[username]/.virtualenvs/djangoVenv
>>>>
>>>> On Mon, Dec 24, 2018 at 8:09 AM Atul Anand 
>>>> wrote:
>>>>
>>>>> I am using virtual env: * djangoVenv*
>>>>>
>>>>>
>>>>> On Mon, Dec 24, 2018 at 7:45 PM Joel Mathew  wrote:
>>>>>
>>>>>> Use virtualenv
>>>>>> Sincerely yours,
>>>>>>
>>>>>>  Joel G Mathew
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, 24 Dec 2018 at 19:34, Atul Anand 
>>>>>> wrote:
>>>>>>
>>>>>>> y code is working in local. But the same code when I am uploading
>>>>>>> into https://www.pythonanywhere.com. Its throwing error.
>>>>>>>
>>>>>>> Note: I have updated few things to make it compatible for
>>>>>>> django2,which is working for me in my local windows box.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> https://www.pythonanywhere.com/user/crackjeeonline/webapps/#tab_id_crackjeeonline_pythonanywhere_com
>>>>>>>
>>>>>>> https://github.com/atulanandnitt/simplesocial
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> result of pip freeze
>>>>>>>
>>>>>>>
>>>>>>>1. (djangoVenv) 07:50 ~/simplesocial (master)$ pip freeze
>>>>>>>2. -f /usr/share/pip-wheels
>>>>>>>3. argon2-cffi==18.3.0
>>>>>>>4. bcrypt==3.1.5
>>>>>>>5. certifi==2018.10.15
>>>>>>>6. cffi==1.11.5
>>>>>>>7. chardet==3.0.4
>>>>>>>8. coreapi==2.3.3
>>>>>>>9. coreschema==0.0.4
>>>>>>>10. Django==2.0.9
>>>>>>>11. django-bootstrap3==11.0.0
>>>>>>>12. django-braces==1.13.0
>>>>>>>13. django-cors-headers==2.4.0
>>>>>>>14. django-debug-toolbar==1.10.1
>>>>>>>15. django-filter==2.0.0
>>>>>>>16. django-tables2==2.0.3
>>>>>>>17. djangorestframework==3.9.0
>>>>>>>18. Faker==1.0.1
>>>>>>>19. idna==2.7
>>>>>>>20. itypes==1.1.0
>>>>>>>21. Jinja2==2.10
>>>>>>>22. Markdown==3.0.1
>>>>>>>23. MarkupSafe==1.1.0
>>>>>>>24. misaka==2.1.1
>>>>>>>25.

Re: issue in hosting https://www.pythonanywhere.com

2018-12-24 Thread Brad Pitcher
The paths in your logs indicate you aren't using a virtualenv. Find the
virtualenv section in the web tab and make sure you specify the path to
your virtualenv there. Should be something like
/home/[username]/.virtualenvs/djangoVenv

On Mon, Dec 24, 2018 at 8:09 AM Atul Anand 
wrote:

> I am using virtual env: * djangoVenv*
>
>
> On Mon, Dec 24, 2018 at 7:45 PM Joel Mathew  wrote:
>
>> Use virtualenv
>> Sincerely yours,
>>
>>  Joel G Mathew
>>
>>
>>
>> On Mon, 24 Dec 2018 at 19:34, Atul Anand 
>> wrote:
>>
>>> y code is working in local. But the same code when I am uploading into
>>> https://www.pythonanywhere.com. Its throwing error.
>>>
>>> Note: I have updated few things to make it compatible for django2,which
>>> is working for me in my local windows box.
>>>
>>>
>>>
>>>
>>>
>>> https://www.pythonanywhere.com/user/crackjeeonline/webapps/#tab_id_crackjeeonline_pythonanywhere_com
>>>
>>> https://github.com/atulanandnitt/simplesocial
>>>
>>>
>>>
>>> result of pip freeze
>>>
>>>
>>>1. (djangoVenv) 07:50 ~/simplesocial (master)$ pip freeze
>>>2. -f /usr/share/pip-wheels
>>>3. argon2-cffi==18.3.0
>>>4. bcrypt==3.1.5
>>>5. certifi==2018.10.15
>>>6. cffi==1.11.5
>>>7. chardet==3.0.4
>>>8. coreapi==2.3.3
>>>9. coreschema==0.0.4
>>>10. Django==2.0.9
>>>11. django-bootstrap3==11.0.0
>>>12. django-braces==1.13.0
>>>13. django-cors-headers==2.4.0
>>>14. django-debug-toolbar==1.10.1
>>>15. django-filter==2.0.0
>>>16. django-tables2==2.0.3
>>>17. djangorestframework==3.9.0
>>>18. Faker==1.0.1
>>>19. idna==2.7
>>>20. itypes==1.1.0
>>>21. Jinja2==2.10
>>>22. Markdown==3.0.1
>>>23. MarkupSafe==1.1.0
>>>24. misaka==2.1.1
>>>25. Pillow==5.3.0
>>>26. pycparser==2.19
>>>27. python-dateutil==2.7.5
>>>28. pytz==2018.7
>>>29. requests==2.20.1
>>>30. six==1.12.0
>>>31. sqlparse==0.2.4
>>>32. text-unidecode==1.2
>>>33. uritemplate==3.0.0
>>>
>>>
>>>
>>> Snippet from
>>> https://www.pythonanywhere.com/user/crackjeeonline/files/var/log/crackjeeonline.pythonanywhere.com.error.log
>>>
>>>
>>>1. 2018-12-23 06:53:44,347: Error running WSGI application
>>>2. 2018-12-23 06:53:44,355: ModuleNotFoundError: No module named 
>>> 'debug_toolbar'
>>>3. 2018-12-23 06:53:44,356:   File 
>>> "/var/www/crackjeeonline_pythonanywhere_com_wsgi.py", line 54, in 
>>>4. 2018-12-23 06:53:44,356: django.setup()
>>>5. 2018-12-23 06:53:44,356:
>>>6. 2018-12-23 06:53:44,356:   File 
>>> "/usr/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
>>>7. 2018-12-23 06:53:44,357: apps.populate(settings.INSTALLED_APPS)
>>>8. 2018-12-23 06:53:44,357:
>>>9. 2018-12-23 06:53:44,357:   File 
>>> "/usr/lib/python3.6/site-packages/django/apps/registry.py", line 89, in 
>>> populate
>>>10. 2018-12-23 06:53:44,357: app_config = AppConfig.create(entry)
>>>11. 2018-12-23 06:53:44,358:
>>>12. 2018-12-23 06:53:44,358:   File 
>>> "/usr/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
>>>13. 2018-12-23 06:53:44,358: module = import_module(entry)
>>>14. 2018-12-23 06:53:44,358: 
>>> ***
>>>15. 2018-12-23 06:53:44,359: If you're seeing an import error and don't 
>>> know why,
>>>16. 2018-12-23 06:53:44,359: we have a dedicated help page to help you 
>>> debug:
>>>17. 2018-12-23 06:53:44,359: 
>>> https://help.pythonanywhere.com/pages/DebuggingImportError/
>>>
>>>
>>> Regards,
>>> Atul
>>>
>>> --
>>> 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/CAKHpVdTdwqMXje4KzTOSX1QF9FNR89oOQAB%2BkDncKQ7ZP93pyg%40mail.gmail.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/CAA%3Diw_8KJ0rwiy1CF8MQGBBCxufQHBcjFRxvrpctJsi9TJeUOQ%40mail.gmail.com
>> 

change display value of filter in admin

2016-05-31 Thread Brad Rice
I have a field that has two values set "S" or "E". I use it to filter 
records in the admin. I would like the values in the filter to be spelled 
out as "Signature" and "Emerging". How do I have it show like that in Admin?


This is my filter:


list_filter = ('app_complete', 'app_type')


app_type is the field I want to change how the field values show to filter 
on.

-- 
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/f48a68a6-1f87-4de1-a515-44e5ef982d25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Setting a crispy form label from a db model field

2016-01-15 Thread Brad Rice
I'm using Crispy forms for an app that I created. I want to have the labels 
for the form come from a db entry. Is there a way, and how would you set 
the label using a model-view variable?

-- 
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/5ac4cd4e-4b7c-4814-a5ea-8dccfe65e6dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Index(View) rendering template instead of view

2015-02-24 Thread Brad Rice
So I have a RedirectView.as_view() going to a page in an app called web.

In the app web this is my view:

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

However, instead of showing that, when I get redirected to the app it shows 
my base template and index template even though I have not specified them 
in my Index view. It appears my url is not hitting the view.

Here is my urls.py in web: 

from django.conf.urls import *
import os
from .views import Index, gallery

urlpatterns = patterns('',
url(r'^$', Index.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)

Here is the website: www.lodiharrisvillehistorical.org

notice it going to /web but not echoing out Hello, World!

also notice gallery is working and finding the view.

Why is it not picking up the Index view and instead displaying a template 
with no context?

-- 
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/fc79434f-bf1a-4549-9708-0d5cf40439d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: RedirectView()

2015-02-23 Thread Brad Rice
OK, thanks. I had added that. I was just putting the url to the particular 
file in place. This is my whole urls.py at the top: So you are saying don't 
add the line that includes the web.urls?

urlpatterns = patterns('',

url(r'^admin/', include(admin.site.urls)),
url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
url(r'^web/', include('web.urls', namespace='web'),
)
)

Then this is the web urls.py

urlpatterns = patterns('',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)

On Monday, February 23, 2015 at 10:01:53 AM UTC-5, Andréas Kühne wrote:
>
>
> 2015-02-23 15:30 GMT+01:00 Brad Rice <brad...@gmail.com >:
>
>> I'm using RedirectView and it is redirecting to my app, but is not 
>> rendering the view in the app I am pointing to.
>>
>> I want to redirect my root / to my app /web
>>
>> I have this in my primary app urls:
>>
>> url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
>>
>> I have this in web.urls.py
>>
>> url(r'^$', IndexView.as_view(), name='index'),
>>
>> I have his in my web.vews.py
>>
>> class Index(View):
>>
>> def get(self, request, *args, **kwargs):
>> return HttpResponse('Hello, World!')
>>
>> when I go to / I do get redirected to /web/ but I get a index.html 
>> template display rather than Hello World. It isn't finding my Index(View) 
>> class for some reason.
>>
>> Can anybody explain to me how this should work?
>>
>> -- 
>> Brad Rice
>> brad...@gmail.com 
>> --
>> To succeed in life, you need two things: ignorance and confidence.
>> -Mark Twain
>>  
>> -- 
>> 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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> Hi Brad,
>
> You have not correctly written the web.urls.py file. It should be:
>
> url(r'^web/$', IndexView.as_view(), name='index'),
>
> The urls file doesn't know about in which app it resides, så you have to 
> add the complete url yourself. As long as you don't add the web.urls.py 
> into your main urls.py file with:
>
> url(r'^web/', include(web.urls)),
>
> then your code should work ok.
>
> Regards,
>
> Andréas
>

-- 
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/98517b28-588f-4344-a5a3-1f778a154f98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RedirectView()

2015-02-23 Thread Brad Rice
I'm using RedirectView and it is redirecting to my app, but is not
rendering the view in the app I am pointing to.

I want to redirect my root / to my app /web

I have this in my primary app urls:

url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),

I have this in web.urls.py

url(r'^$', IndexView.as_view(), name='index'),

I have his in my web.vews.py

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

when I go to / I do get redirected to /web/ but I get a index.html template
display rather than Hello World. It isn't finding my Index(View) class for
some reason.

Can anybody explain to me how this should work?

-- 
Brad Rice
bradri...@gmail.com
--
To succeed in life, you need two things: ignorance and confidence.
-Mark Twain

-- 
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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Class Based Views tutorials

2015-01-06 Thread Brad Rice
When I was working with formsets, it seemed to me best to just use a single 
UpdateView with post and get functions defined rather than having a 
separate CreateView class. Seemed to handle both create and update ok.

On Tuesday, January 6, 2015 9:39:49 AM UTC-5, Sergiy Khohlov wrote:
>
> Diff is simple : UpdateView is using for changing already created object. 
> CreateView is using  for creating new object.
> I have few simpleast class for your request. But I have not  commented 
> yet.  
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Tue, Jan 6, 2015 at 3:49 PM, Brad Rice <brad...@gmail.com 
> > wrote:
>
>> Does anyone have a recommendation for intermediate reading to understand 
>> Class Based Views? It seems most of the Django books were written when 
>> function based views were prevalent. I'm still having trouble understanding 
>> what the differences are between CreateView and UpdateView and what Meta is 
>> as well as slug_field and pk. Perhaps my issue is understanding Object 
>> oriented python? I wish there were some tutorials or cookbooks that offer 
>> better understanding.
>>
>> -- 
>> 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/7fac53a2-7ff6-488f-903f-ed46edf15deb%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/7fac53a2-7ff6-488f-903f-ed46edf15deb%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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/703f0448-2152-418a-9466-4e87e1226b62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Class Based Views tutorials

2015-01-06 Thread Brad Rice
Does anyone have a recommendation for intermediate reading to understand 
Class Based Views? It seems most of the Django books were written when 
function based views were prevalent. I'm still having trouble understanding 
what the differences are between CreateView and UpdateView and what Meta is 
as well as slug_field and pk. Perhaps my issue is understanding Object 
oriented python? I wish there were some tutorials or cookbooks that offer 
better understanding.

-- 
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/7fac53a2-7ff6-488f-903f-ed46edf15deb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Recommendations for hosting service?

2015-01-06 Thread Brad Rice
I like webfaction, too. I think they would have all the stuff you list as 
well as more.

On Tuesday, January 6, 2015 6:30:18 AM UTC-5, Bobby Mozumder wrote:
>
> Anyone have recommendations for hosting services that can do Django, 
> Node.js, Postgreqsl, python3, as well as PHP/MySQL for legacy stuff?  I’m 
> also looking to have IMAP email.  This would be for several domains, with 
> maybe 100GB of data. 
>
> -bobby

-- 
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/1c61b6c7-ae41-48fa-a2f1-2eb1b8a7ea68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ANN: Django website redesign launched

2014-12-16 Thread Brad Rice
I noticed today when I went in to look something up. I like it.

On Tuesday, December 16, 2014 11:12:54 AM UTC-5, Jannis Leidel wrote:
>
> Hi everyone, 
>
> We're incredibly proud to share with you the new design of the Django 
> website, the documentation and the issue tracker. 
>
> This is a long time coming and we couldn't be happier to finally ship it 
> :) 
>
> As you can imagine, there will be bugs, so please bear with us and report 
> issues to the issue tracker at 
> https://github.com/django/djangoproject.com/issues 
>
> More infos about the redesign and its history can be found in the blog 
> post: 
>
>   
> https://www.djangoproject.com/weblog/2014/dec/15/announcing-django-website-redesign/
>  
>
> Happy coding, everyone! 
>
> Jannis 
>
>

-- 
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/4a4c04ca-8e57-4351-8f1b-be30e920d64a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: control attributes on form fields in formset

2014-12-16 Thread Brad Rice
Ah, found it on the django read the docs site. This is what I did in my 
inline formset factory

BookFormset = inlineformset_factory(Author, Book, extra=3, max_num=3, 
widgets={'name': forms.TextInput(attrs={'class':'u-full-width'})})

On Tuesday, December 16, 2014 8:34:25 AM UTC-5, Brad Rice wrote:
>
> When I do a model form I can control the fields with attributes using 
>
> name = 
> forms.CharField(widget=forms.TextInput(attrs={'class':'u-full-width'}))
>
> How do I do something like that in an inline formset? I don't see where I 
> can set attributes.
>

-- 
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/78efe089-edd2-44f5-9da3-563af3cd1eba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


control attributes on form fields in formset

2014-12-16 Thread Brad Rice
When I do a model form I can control the fields with attributes using 

name = 
forms.CharField(widget=forms.TextInput(attrs={'class':'u-full-width'}))

How do I do something like that in an inline formset? I don't see where I 
can set attributes.

-- 
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/f549611e-986f-43c9-b229-3ea7360669b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CBV with inline formset

2014-12-15 Thread Brad Rice
Thanks. I think I figured out how to do this with a straight createView.

class BookCreate(CreateView):
model = Book
form_class = BookForm
template_name = 'book_template.html'
success_url = u'/dp/thanks'

def get(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(instance=author)
return self.render_to_response(self.get_context_data(formset=formset))

def post(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(request.POST,request.FILES,instance=author)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse('dp:thanks'))

def form_valid(self, formset):
context = self.get_context_data()
book_formset = context['formset']
if book_formset.is_valid():
# self.object = book_formset.save()
book_formset.instance = self.object
book_formset.save()
return HttpResponseRedirect(self.get_success_url())
else:
return 
self.render_to_response(self.get_context_data(formset=book_formset))

On Monday, December 15, 2014 4:09:29 PM UTC-5, Vijay Khemlani wrote:
>
> Try changing the name of the parameter in the url from author_id to pk
>
> On Mon, Dec 15, 2014 at 5:39 PM, Brad Rice <brad...@gmail.com 
> > wrote:
>>
>> I've pretty much butchered the code for 3 days now and cannot figure out 
>> how to insert an inline formset. Can anybody help me?
>>
>> I've tried to pare everything down to use two simple Models just to try 
>> to get an insert. I'm using django Author - Book relationship to keep it 
>> simple.
>>
>> class Author(models.Model):
>> name = models.CharField(max_length=100)
>>
>> def __unicode__(self):  # __unicode__ on Python 2
>> return self.name
>>
>>
>> class Book(models.Model):
>> name = models.CharField(max_length=100)
>> author = models.ForeignKey(Author)
>>
>> So I have a page where you can insert and author. The author page takes 
>> you to a page to insert books for that author using an inline formset of 3 
>> books.
>>
>> In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
>> BookCreate.as_view(), name='book_create'),
>>
>> When you go to book_create I can see the author_id getting passed in the 
>> kwargs. Now how to I insert from there books into the db with the Foreign 
>> Key to that author passed in the kwargs?
>>
>> After banging away for so long, I decided to try to switch to django 
>> extra views. this is what I have in my views.py
>>
>> class BookCreate(InlineFormSetView):
>> model = Author
>> inline_model = Book
>> form_class = BookForm
>> extra = 3
>> template_name = 'book_template.html'
>>
>> def get_queryset(self):
>> slug = self.kwargs['author_id']
>> return super(BookCreate, self).get_queryset().filter(id=slug)
>>
>> When I go to the book_create page I get this error:
>>
>> Generic detail view BookCreate must be called with either an object pk or a 
>> slug.
>>
>>  -- 
>> 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/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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/d3e56823-8b3d-45b7-8815-2c444bec75b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


CBV with inline formset

2014-12-15 Thread Brad Rice
I've pretty much butchered the code for 3 days now and cannot figure out 
how to insert an inline formset. Can anybody help me?

I've tried to pare everything down to use two simple Models just to try to 
get an insert. I'm using django Author - Book relationship to keep it 
simple.

class Author(models.Model):
name = models.CharField(max_length=100)

def __unicode__(self):  # __unicode__ on Python 2
return self.name


class Book(models.Model):
name = models.CharField(max_length=100)
author = models.ForeignKey(Author)

So I have a page where you can insert and author. The author page takes you 
to a page to insert books for that author using an inline formset of 3 
books.

In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
BookCreate.as_view(), name='book_create'),

When you go to book_create I can see the author_id getting passed in the 
kwargs. Now how to I insert from there books into the db with the Foreign 
Key to that author passed in the kwargs?

After banging away for so long, I decided to try to switch to django extra 
views. this is what I have in my views.py

class BookCreate(InlineFormSetView):
model = Author
inline_model = Book
form_class = BookForm
extra = 3
template_name = 'book_template.html'

def get_queryset(self):
slug = self.kwargs['author_id']
return super(BookCreate, self).get_queryset().filter(id=slug)

When I go to the book_create page I get this error:

Generic detail view BookCreate must be called with either an object pk or a 
slug.

-- 
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/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


modelformst save

2014-12-05 Thread Brad Rice
For the life of me I can't figure out how to use a modelformset with class 
view. I get it to display but it won't save. Also, when it goes into 
form_invalid, it doesn't display the 3 formsets. Can anyone shed a little 
light? 

I'm using crispy forms with this in my template:

{% crispy reference_form referencehelper %}

This is my model

class Reference(models.Model):
ref_name = models.CharField(max_length=256)
ref_phone = models.CharField(max_length=20, 
validators=[RegexValidator(regex='\(?([0-9]{3})\)?([ .-]?)([0-9]{3})([ 
.-]?)([0-9]{4})', message='Looks like your phone number is not formatted 
correctly', code='Invalid number')])
ref_email = models.EmailField(max_length=256)
created_by = models.ForeignKey(User, unique=True)
applicant = models.ForeignKey("Applicant")
application = models.ForeignKey("Application")

This is my form.py form

class ReferenceForm(forms.ModelForm):
class Meta:
model = Reference
exclude = ('created_by', 'application', 'applicant')

def __init__(self, *args, **kwargs):
super(ReferenceForm, self).__init__(*args, **kwargs)


class ReferenceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(ReferenceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.layout = Layout(
Fieldset('Reference',
'ref_name',
'ref_phone',
'ref_email',
))
self.add_input(Submit("submit", "Save"))



ReferenceFormSet = modelformset_factory(Reference, form=ReferenceForm, 
extra=3, max_num=3, can_delete=True)

This is my view:

class ReferenceCreate(LoginRequiredMixin, CreateView):
model = Reference
form_class = ReferenceForm
template_name = 'requestform/reference_form.html'

def dispatch(self, *args, **kwargs):
return super(ReferenceCreate, self).dispatch(*args, **kwargs)

def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates blank versions of the form
and its inline formsets.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
reference_form = ReferenceFormSet()
refhelper = ReferenceFormSetHelper()
return self.render_to_response(
self.get_context_data(
  reference_form=reference_form,
  referencehelper=refhelper
  ))

def form_valid(self, form):
"""
Called if all forms are valid. Creates a Recipe instance along with
associated Ingredients and Instructions and then redirects to a
success page.
"""
self.object = form.save()
reference_form.instance = self.object
reference_form.save()
return HttpResponseRedirect(reverse('requestform:app_check', 
kwargs={'app_id': obj.application_id}))


def form_invalid(self, reference_form):
refhelper = ReferenceFormSetHelper()
return self.render_to_response(self.get_context_data(
  reference_form=reference_form,
  referencehelper=refhelper
  ))

-- 
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/e823091d-a160-4575-b26e-56872aa21831%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Alternative to fabric

2014-11-17 Thread Brad Pitcher
I agree Ansible is a good fit for your situation. Since Ansible works from
yaml files, you don't have to write any Python 2.x compatible code as you
would with Fabric.

On Mon Nov 17 2014 at 8:24:24 AM Brian Schott  wrote:

> Ansible is a good choice.
>
> Sent from my iPhone
>
> On Nov 17, 2014, at 11:07 AM, Cal Leeming [iops.io]  wrote:
>
> There isn't really such a thing as a "deployment plugin", there are many
> aspects to deployment workflow that should be considered.
>
> It really depends on how you are intending on deploying your application,
> if you are dockerizing it then your CI system should be building the images
> and pushing to a repository of your choice (docker hub, S3 etc). If you are
> snapshotting on the hosting provider, then you can use packer.io and a
> bunch of shell scripts. Pushing code to a single server via SSH isn't
> really a scalable way to do deployment, and if this is what you are doing
> then you might as well run a tmux/screen session on the server instead.
>
> Sadly other than Amazon Beanstalk and Heroku, both of which are
> horrifically expensive, there isn't much in the way of choices. You can
> look at dokku and deis, both of which are not considered stable for
> production but use the same build pack idea as Heroku.
>
> If you want to go super ghetto, you should use a shell script which SSHs
> into your "single use" box, issue a "docker pull" then restart the running
> container. All of these things require a lot of plumbing work.
>
> Another approach would be to install python 2.6 in a venv (assuming you
> have the relevant system libs) and run Fabric with that instead... In fact
> putting fabric in its own venv is probably better because having fabric
> inside your application space anyway would be considered cross
> contamination (e.g. deployment tooling mixed in with application code).
> This may feel weird at first, but once you get into the concept of
> separating plumbing from application code, it feels more normal. If you do
> this, use virtualenvwrapper to save headaches.
>
> If you're a JS guy, there's also a bunch of SSH tooling for node too, but
> I can't give any personal recommendation on those.
>
> Cal
>
>
>
> On Mon, Nov 17, 2014 at 11:28 AM, Andreas Kuhne <
> andreas.ku...@suitopia.com> wrote:
>
>> Hi all,
>>
>> We are just about ready to release our newly rewritten website. It is
>> based on Django 1.6 and Python 3.
>>
>> We have worked through all of the problems with using python 3 (migrated
>> some plugins ourselves, other plugins were updated during the course of the
>> project). The only problem we have left is a good deployment plugin, so
>> that we easily can deploy new versions of our site.
>>
>> We previously used fabric, but that doesn't work with python 3. So I was
>> wondering if anyone has any python 3 compatible fabric alternative that
>> they are using?
>>
>> Regards,
>>
>> Andréas
>>
>> --
>> 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/CALXYUb%3DTpr7RfejfXs2H5vryg6vGp45_bbE%2Bp8tm%3D8CgQN2hzw%40mail.gmail.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/CAHKQagGz1tNLfdF09%3DcFBJaAWfBWFNbWCP%3DTANonGVkZSbvGfg%40mail.gmail.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/4679766C-BFEC-4A96-A1D2-BDBD316053EE%40gmail.com
> 

Re: Please help: urgent deployment problem with django post office

2014-10-03 Thread Brad Pitcher
If you want to simply disable logging, you could try setting the LOG_LEVEL
to 0:

POST_OFFICE = {
'LOG_LEVEL': 0  # Don't log anything
}


On Fri, Oct 3, 2014 at 4:55 AM, Sabine Maennel 
wrote:

> Hello Collins, I need post office for other purposes not for error
> logging.
>
> I worte an issue in their issue queue, this is what they wrote back:
> >>As explained by @RafRaf  , the emails are
> sent by BrokenLinkEmailsMiddleware, you can disable it insettings.py if
> you need to.
>
> *But my settings.py has this middleware only:*
> MIDDLEWARE_CLASSES = (
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> )
>
> So should I remove Common Middleware for deployment. Could it be coming
> from that one? Can you please give me some advice,
>
> Thanks so much in advance!
>
> Am Donnerstag, 2. Oktober 2014 20:42:19 UTC+2 schrieb Collin Anderson:
>>
>> It seems like django-post_office recommends using sentry for the errors.
>> Getting a better feel for your situation: Why django-post_office at all?
>> What's wrong with the error emails getting logged?
>>
>  --
> 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/7f3d7edc-cbfe-411a-9f16-7acc2044540c%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/CAMFpZrg2xopvfmY76_dJKDTgCNajk%2BQ-12b8OOwrk6c_NwC_ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: try, except problem

2014-09-06 Thread Brad Rice
Andréas that was it. I guess I wasn't thinking about that correctly. I sure 
appreciate the help. This Django group is a very good group.

On Saturday, September 6, 2014 1:19:57 PM UTC-4, Andréas Kühne wrote:
>
> Hi Brad,
>
> 1. Why would app not be not be set if it is in the try statement?
>
> Because the except parameter has the app variable in it (which it 
> shouldn't). The correct except definition should be: "except 
> Application.DoesNotExist". You are not looking for if the app variable 
> doesn't exist but rather an object of type Application in the database.
>
> 2. See above :)
>
> Med vänliga hälsningar,
>
> Andréas Kühne
> Software Development Manager
> Suitopia Scandinavia AB
>
>
> 2014-09-06 18:38 GMT+02:00 Brad Rice <brad...@gmail.com >:
>
>> I'm trying to write a try: except: to check for three things. First I 
>> want to check if an application has already been filled out, thus, check 
>> for existence. Second if it has been filled out a flag that is is complete 
>> is set to true. Then the else would be neither of those things, they need 
>> to create a new app.
>>
>> This is what I have started with:
>>
>> class Main(TemplateView):
>> # app_started = Application.objects.get(created_by=request.user)
>> @method_decorator(login_required(login_url='/accounts/login/'))
>> def dispatch(self, *args, **kwargs):
>> try:
>> app = Application.objects.get(created_by=self.request.user)
>> # if it is true check for if the app is set to complete
>> except app.DoesNotExist:
>> app = None
>> return 
>> HttpResponseRedirect(reverse('requestform:registrant_create'))
>> else:
>> return 
>> HttpResponseRedirect(reverse('requestform:registrant_update'))
>>
>> I keep getting this error:
>>
>> local variable 'app' referenced before assignment
>>
>>
>> Why would app not be not be set if it is in the try statement?
>>
>>
>> How would I check if it does exist, to then check if the flag is true?
>>
>>
>> I'm sort of a Django newbie and this portion of the code I am writing is 
>> really mystifying me.
>>
>> -- 
>> 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/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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/0ea310cb-93d4-41f2-85bb-181fce4c0bd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


try, except problem

2014-09-06 Thread Brad Rice
I'm trying to write a try: except: to check for three things. First I want 
to check if an application has already been filled out, thus, check for 
existence. Second if it has been filled out a flag that is is complete is 
set to true. Then the else would be neither of those things, they need to 
create a new app.

This is what I have started with:

class Main(TemplateView):
# app_started = Application.objects.get(created_by=request.user)
@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
try:
app = Application.objects.get(created_by=self.request.user)
# if it is true check for if the app is set to complete
except app.DoesNotExist:
app = None
return 
HttpResponseRedirect(reverse('requestform:registrant_create'))
else:
return 
HttpResponseRedirect(reverse('requestform:registrant_update'))

I keep getting this error:

local variable 'app' referenced before assignment


Why would app not be not be set if it is in the try statement?


How would I check if it does exist, to then check if the flag is true?


I'm sort of a Django newbie and this portion of the code I am writing is 
really mystifying me.

-- 
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/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: crispy forms two forms and context

2014-09-02 Thread Brad Rice
I wrote an app that allows people to login to fill out an application. It 
has quite a few text areas that have to be filled out, so the idea was to 
allow them to fill out partial and come back and work on it and eventually 
submit it. The last stage before submit I pull all the data into a final 
form and allow them to submit it if they are satisfied. It set's required 
on the fields at that stage. There are three related db tables (models). So 
maybe, I'm thinking about this wrong. Instead of having two or three forms 
on a single page, maybe I need to built one from from the three related 
models at the end.

On Monday, September 1, 2014 8:45:05 PM UTC-4, James Schneider wrote:
>
> I would assume you want something akin to the first example here:
>
> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> Once you have the form object built with the instance of your Answer 
> object, just pass it along.
>
> Since I've never needed more than one form on a page, there may be other 
> gotchas, but you should be able to Google for those. I don't believe that 
> you'll need to do anything special though. Keep in mind that only one of 
> the forms will be submitted (assuming each has it's own set of  
> tags). If you need to combine them and submit info for both, you may need 
> to roll a single custom form class that can handle all of the data, or 
> possibly look into Django formsets.
>
> -James
>
>
> On Monday, September 1, 2014, Brad Rice <brad...@gmail.com > 
> wrote:
>
>> Here is my entire view class to go with a ModelForm. How do I get the 
>> various forms as context into my template?
>>
>> class ApplicationVerify(UpdateView):
>> model = Answers
>> form_class = ApplicationCheckForm
>> template_name = 'requestform/application_detail.html'
>>
>> @method_decorator(login_required(login_url='/accounts/login/'))
>> def dispatch(self, *args, **kwargs):
>> return super(ApplicationVerify, self).dispatch(*args, **kwargs)
>>
>> def get_object(self, queryset=None):
>> return Answers.objects.get(created_by=self.request.user)
>>
>> def form_valid(self, form):
>> obj = form.save(commit=False)
>> obj.created_by = self.request.user
>> obj.save()
>> a = Application.objects.get(created_by=self.request.user)
>> b = Answers.objects.get(created_by=self.request.user)
>> c = Applicant.objects.get(created_by=self.request.user)
>> return HttpResponseRedirect(reverse('requestform:app_complete', 
>> kwargs={'app_id': a.id}))
>>
>>
>> def get_context_data(self, **kwargs):
>> context = super(ApplicationVerify, 
>> self).get_context_data(**kwargs)
>> context['app'] = Application.objects.get(id=self.kwargs['app_id'])
>> context['answers'] = 
>> Answers.objects.get(created_by=self.request.user)
>> context['applicant'] = 
>> Applicant.objects.get(created_by=self.request.user)
>> return context
>>
>> On Monday, September 1, 2014 4:15:39 PM UTC-4, James Schneider wrote:
>>>
>>> It looks like you are passing the context an actual Answers object, not 
>>> a Form or ModelForm object that will add/update an Answers object, 
>>> hence the reason the trace back complains about a lack of 'fields'.
>>>
>>> -James
>>>
>>> On Monday, September 1, 2014, Brad Rice <brad...@gmail.com> wrote:
>>>
>>>> This document seems to indicate I can have two forms inside one set of 
>>>> form tags:
>>>>
>>>> http://django-crispy-forms.readthedocs.org/en/latest/
>>>> crispy_tag_forms.html#rendering-several-forms-with-helpers
>>>>
>>>> I cannot figure out how to set the context to be able to iterate over 
>>>> both forms.
>>>>
>>>> {% crispy form %}
>>>>
>>>> works on my model form.
>>>>
>>>>  If I try to set context in my view like this:
>>>>
>>>> def get_context_data(self, **kwargs):
>>>> context = super(ApplicationVerify, self).get_context_data(**
>>>> kwargs)
>>>> context['app'] = Application.objects.get(id=
>>>> self.kwargs['app_id'])
>>>> context['answers'] = Answers.objects.get(created_
>>>> by=self.request.user)
>>>> context['applicant'] = Applicant.objects.get(created_
>>>> by=self.request.user)
>>>> return context
>>>>
>>>> and then use instead of crispy form
&g

Re: crispy forms two forms and context

2014-09-01 Thread Brad Rice
Here is my entire view class to go with a ModelForm. How do I get the 
various forms as context into my template?

class ApplicationVerify(UpdateView):
model = Answers
form_class = ApplicationCheckForm
template_name = 'requestform/application_detail.html'

@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
return super(ApplicationVerify, self).dispatch(*args, **kwargs)

def get_object(self, queryset=None):
return Answers.objects.get(created_by=self.request.user)

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
a = Application.objects.get(created_by=self.request.user)
b = Answers.objects.get(created_by=self.request.user)
c = Applicant.objects.get(created_by=self.request.user)
return HttpResponseRedirect(reverse('requestform:app_complete', 
kwargs={'app_id': a.id}))


def get_context_data(self, **kwargs):
context = super(ApplicationVerify, self).get_context_data(**kwargs)
context['app'] = Application.objects.get(id=self.kwargs['app_id'])
context['answers'] = 
Answers.objects.get(created_by=self.request.user)
context['applicant'] = 
Applicant.objects.get(created_by=self.request.user)
return context

On Monday, September 1, 2014 4:15:39 PM UTC-4, James Schneider wrote:
>
> It looks like you are passing the context an actual Answers object, not a 
> Form or ModelForm object that will add/update an Answers object, hence 
> the reason the trace back complains about a lack of 'fields'.
>
> -James
>
> On Monday, September 1, 2014, Brad Rice <brad...@gmail.com > 
> wrote:
>
>> This document seems to indicate I can have two forms inside one set of 
>> form tags:
>>
>>
>> http://django-crispy-forms.readthedocs.org/en/latest/crispy_tag_forms.html#rendering-several-forms-with-helpers
>>
>> I cannot figure out how to set the context to be able to iterate over 
>> both forms.
>>
>> {% crispy form %}
>>
>> works on my model form.
>>
>> If I try to set context in my view like this:
>>
>> def get_context_data(self, **kwargs):
>> context = super(ApplicationVerify, 
>> self).get_context_data(**kwargs)
>> context['app'] = Application.objects.get(id=self.kwargs['app_id'])
>> context['answers'] = 
>> Answers.objects.get(created_by=self.request.user)
>> context['applicant'] = 
>> Applicant.objects.get(created_by=self.request.user)
>> return context
>>
>> and then use instead of crispy form
>>
>> {% crispy answers %}
>>
>> I get errors.
>>
>> 'Answers' object has no attribute 'fields'
>>
>> How do I set a form to have context from several models?
>>
>> I do see the context is coming into the template, it just is not treating 
>> them as having form widgets.
>>
>> -- 
>> 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/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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/ae25d932-a31b-4a23-aac3-4b9920fb710e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


crispy forms two forms and context

2014-09-01 Thread Brad Rice
This document seems to indicate I can have two forms inside one set of form 
tags:

http://django-crispy-forms.readthedocs.org/en/latest/crispy_tag_forms.html#rendering-several-forms-with-helpers

I cannot figure out how to set the context to be able to iterate over both 
forms.

{% crispy form %}

works on my model form.

If I try to set context in my view like this:

def get_context_data(self, **kwargs):
context = super(ApplicationVerify, self).get_context_data(**kwargs)
context['app'] = Application.objects.get(id=self.kwargs['app_id'])
context['answers'] = 
Answers.objects.get(created_by=self.request.user)
context['applicant'] = 
Applicant.objects.get(created_by=self.request.user)
return context

and then use instead of crispy form

{% crispy answers %}

I get errors.

'Answers' object has no attribute 'fields'

How do I set a form to have context from several models?

I do see the context is coming into the template, it just is not treating 
them as having form widgets.

-- 
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/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: update a field of a related table on form save

2014-07-30 Thread Brad Rice
Thank you both for those suggestions. I got Tundebazby's to work as it was 
closest to what I was doing. I'll have to study the post_save some more.

On Wednesday, July 30, 2014 2:33:57 AM UTC-4, Tundebabzy wrote:
>
> Hi Brad, my response is inline
>
> On 30 Jul 2014 02:26, "Brad Rice" <brad...@gmail.com > wrote:
> >
> > I have three tables. The first one is application which has a flag for 
> if an app has been submitted as well as created date and modified date. The 
> other two tables relate to the application table. I have two forms that get 
> update those tables. What I want to do is update the application modified 
> date from the save on the other forms.
> >
> > I have this in the Application model
> > modified= models.DateTimeField(auto_now_add=True)
> >
> > but since it is the other tables I am saving to, I'm not sure how to 
> update that field whenever the other two tables update.
> >
> > My view for one of the forms looks like this:
> >
> > class AnswersUpdate(UpdateView):
> > model = Answers
> > form_class = AnswersForm
> > slug_field = 'created_by'
> > template_name = 'requestform/applicant_form.html'
> >
> > @method_decorator(login_required(login_url='/accounts/login/'))
> > def dispatch(self, *args, **kwargs):
> > return super(AnswersUpdate, self).dispatch(*args, **kwargs)
> >
> > def get_object(self, queryset=None):
> > return Answers.objects.get(created_by=self.request.user)
> >
> > def form_valid(self, form):
> > obj = form.save(commit=False)
> > obj.created_by = self.request.user
> > obj.save()
> > a = Application.objects.get(created_by=self.request.user)
> >## how do I save to the Application here?
>
> #if its a new record, something like 
> application =  Application.objects.create(...)
>
> #if you are updating a record, something like...
> application = Application.objects.get(...) # can throw exception
> application.field_name = something
> application.save ()
>
> > return HttpResponseRedirect(reverse('requestform:app_check', 
> kwargs={'app_id': obj.id}))
> >
> > Any help would be appreciated.
> >
> > --
> > 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/2a2b6f24-b4c2-4575-9a52-85a892256c79%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/99b2a53f-5388-4b90-8313-7e7c29f9ce60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


update a field of a related table on form save

2014-07-29 Thread Brad Rice
I have three tables. The first one is application which has a flag for if 
an app has been submitted as well as created date and modified date. The 
other two tables relate to the application table. I have two forms that get 
update those tables. What I want to do is update the application modified 
date from the save on the other forms.

I have this in the Application model
modified= models.DateTimeField(auto_now_add=True)

but since it is the other tables I am saving to, I'm not sure how to update 
that field whenever the other two tables update.

My view for one of the forms looks like this:

class AnswersUpdate(UpdateView):
model = Answers
form_class = AnswersForm
slug_field = 'created_by'
template_name = 'requestform/applicant_form.html'

@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
return super(AnswersUpdate, self).dispatch(*args, **kwargs)

def get_object(self, queryset=None):
return Answers.objects.get(created_by=self.request.user)

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
a = Application.objects.get(created_by=self.request.user)
   ## how do I save to the Application here?
return HttpResponseRedirect(reverse('requestform:app_check', 
kwargs={'app_id': obj.id}))

Any help would be appreciated.

-- 
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/2a2b6f24-b4c2-4575-9a52-85a892256c79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 1.6.5 as a zip for download?

2014-05-28 Thread Brad Pitcher
Is this what you're looking for?

https://github.com/django/django/archive/1.6.5.zip


On Wed, May 28, 2014 at 9:51 AM, Neil Walker wrote:

> Hello,
> I wish to download 1.6.5 stable zip without using pip and not as a tar/gz
> (limitations on software I can use at work), but when I visit the download
> site and follow the links for manually installing all I get is the latest
> development build as a zip or 1.6.5 as as tar/z file.
>
> Is there a stable release version as a zip available?
>
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fa1080dd-ad78-41fa-b00f-6fac7bc431ea%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/CAMFpZri3Jcd19b27ucR9CstV0_vQzyfWkHQdTkWtHs6iu94O-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Centos 6.5 Python 3.3.x Django 1.6 Apache 2.2

2014-05-05 Thread Brad Pitcher
It's just something that was passed down to me from a senior programmer :-)

-
Brad Pitcher


On Mon, May 5, 2014 at 2:45 PM, Guillem Liarte <
guillem.lia...@googlemail.com> wrote:

> Hello Brad,
>
> Thanks for the suggestion, I was suspecting something like that. I will
> let you know how it goes.
>
> Where do you find this? I Could not find anything like that in the wsgi
> documentation.
>
> Thank you,
>
> Guillem
>
>
> On Friday, 2 May 2014 16:37:35 UTC+2, Brad Pitcher wrote:
>
>> What does your Apache vhost config look like? You will need to add a
>> WSGIDaemonProcess directive where you can specify the python path for the
>> virtual environment, like so:
>>
>> WSGIDaemonProcess processname user=wsgi group=apache processes=1
>> threads=10 umask=0022 display-name=displayname
>> python-path=/data/app/guillem-py3-dj17-test/lib64/python3.3/
>> site-packages/
>>
>> -
>> Brad Pitcher
>>
>>
>> On Fri, May 2, 2014 at 4:11 AM, Guillem Liarte <guillem...@googlemail.com
>> > wrote:
>>
>>>  Hello,
>>>
>>> I have looked through the web in several different especialised forums
>>> but I cannot find the way to do this properly.
>>>
>>> My aim is to have an environment to host Django applications running
>>> Centos 6. So far I have managed to:
>>>
>>> - Get Centos 6.5 + Ptython 3.3.2 + Django 1.6 (virtual env), running a
>>> test application using python's webserver. Time to move into Apache.
>>> - I manage to get it working from Apache but instead of Python 3.3.2, it
>>> uses the Python 2.6 installed in the system. No matter if I launch apache
>>> from the virtual environment, even once I have enabled python3.
>>>
>>> I know Djanog 1.6 can use python 2.6. But that is not what i want to
>>> achieve, as 1.7 will not.
>>>
>>> Just to give some idea of what I have installed:
>>>
>>>
>>>
>>> In the system:
>>> python --version
>>> Python 2.6.6
>>>
>>> From RedHat SCL:
>>>
>>> source /opt/rh/python33/enable
>>>
>>> python --version
>>> Python 3.3.2
>>>
>>> Inside the virtual environment I have:
>>>
>>> Django (1.6.3)
>>> pip (1.4.1)
>>> setuptools (0.9.8)
>>>
>>> That starts successfully:
>>>
>>> python manage.py runserver 192.168.0.16:8000
>>>
>>>
>>>
>>> Starting development server at http://192.168.0.16:8000/
>>>
>>>
>>>
>>> Quit the server with CONTROL-C.
>>>
>>> When getting to admin or any error page:
>>>
>>> Django Version:
>>>   1.6.3
>>> Python Version:
>>>   3.3.2
>>>
>>> Python Path:
>>>
>>>
>>> ['/data/app/guillem-py3-dj17-test/guillem_test',
>>>  '/data/app/guillem-py3-dj17-test/lib64/python33.zip',
>>>  '/data/app/guillem-py3-dj17-test/lib64/python3.3',
>>>  '/data/app/guillem-py3-dj17-test/lib64/python3.3/plat-linux',
>>>  '/data/app/guillem-py3-dj17-test/lib64/python3.3/lib-dynload',
>>>  '/opt/rh/python33/root/usr/lib64/python3.3',
>>>  '/opt/rh/python33/root/usr/lib/python3.3',
>>>  '/data/app/guillem-py3-dj17-test/lib/python3.3/site-packages']
>>> ___
>>>
>>>
>>> When starting this from Apache 2.2 instead of the python embedded server:
>>>
>>>
>>> httpd -k restart -e debug
>>>
>>>
>>>
>>> ...
>>> [Fri May 02 11:53:29 2014] [debug] mod_so.c(246): loaded module wsgi_module
>>> ...
>>>
>>> The Apache service starts in my port of choice:
>>>
>>> tcp0  0 192.168.0.16:8082   0.0.0.0:*   
>>> LISTEN  1676/httpdWhat I get now is:
>>>
>>>
>>>
>>>
>>> So now I get:
>>>
>>> Django Version: 1.6
>>> Python Executable:  /data/app/guillem-py3-dj17-test/bin/python
>>> Python Version: 2.6.6
>>> Python Path:
>>>
>>> ['/data/app/django-test/dev/test-1/HELLO_WORLD/lib/python2.6/site-packages',
>>>
>>>
>>>
>>>
>>>  '/data/app/django-test/dev/test-1/HELLO_WORLD/HELLO_WORLD/..',
>>>  '/usr/lib64/python26.zip',
>>>  '/usr/lib64/python2.6',
>>>  '/usr/lib64/python2.6/plat-linux2',
>>>  '/usr/lib64/python2.6/lib-tk',
>>>
>>>
&

Re: django 1.6.4 - markup / markdown (for django blog tutorial)

2014-05-05 Thread Brad Pitcher
django.contrib.markup has been deprecated. You could try using the
standalone project that is a copy of the same code from django:

pip install django_markup_deprecated

Then add "markup_deprecated" to your INSTALLED_APPS instead of
django.contrib.markup.

-
Brad Pitcher


On Mon, May 5, 2014 at 1:07 PM, Alex Leonhardt <alex.t...@gmail.com> wrote:

> fwiw - this is the tutorial I was trying :
> http://www.creativebloq.com/netmag/get-started-django-7132932 it mentions
> django.contrib.markup ... but that doesnt seem to work :\
>
>
> On Monday, 5 May 2014 16:44:47 UTC+1, Alex Leonhardt wrote:
>>
>> Hi all,
>>
>> am new to django and followed a tiny tutorial to start off - I wanted to
>> add the ability to use Markdown syntax in the blog posts. It was suggested
>> to use django.contrib.markup, but that wont work anymore ( i guess it's
>> been removed ) - what do I need to use Markdown in my posts ?
>>
>> Thanks all!
>> Alex
>>
>>  --
> 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/56aaacc5-48e1-47f8-a1bc-ac027246964a%40googlegroups.com<https://groups.google.com/d/msgid/django-users/56aaacc5-48e1-47f8-a1bc-ac027246964a%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> 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/CAMFpZrj1XV3qTx3eMUPCUDNQMV5D2CRH8vik8jSuGbSZ5tFsVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Centos 6.5 Python 3.3.x Django 1.6 Apache 2.2

2014-05-02 Thread Brad Pitcher
What does your Apache vhost config look like? You will need to add a
WSGIDaemonProcess directive where you can specify the python path for the
virtual environment, like so:

WSGIDaemonProcess processname user=wsgi group=apache processes=1 threads=10
umask=0022 display-name=displayname
python-path=/data/app/guillem-py3-dj17-test/lib64/python3.3/site-packages/

-
Brad Pitcher


On Fri, May 2, 2014 at 4:11 AM, Guillem Liarte <
guillem.lia...@googlemail.com> wrote:

> Hello,
>
> I have looked through the web in several different especialised forums but
> I cannot find the way to do this properly.
>
> My aim is to have an environment to host Django applications running
> Centos 6. So far I have managed to:
>
> - Get Centos 6.5 + Ptython 3.3.2 + Django 1.6 (virtual env), running a
> test application using python's webserver. Time to move into Apache.
> - I manage to get it working from Apache but instead of Python 3.3.2, it
> uses the Python 2.6 installed in the system. No matter if I launch apache
> from the virtual environment, even once I have enabled python3.
>
> I know Djanog 1.6 can use python 2.6. But that is not what i want to
> achieve, as 1.7 will not.
>
> Just to give some idea of what I have installed:
>
>
>
> In the system:
> python --version
> Python 2.6.6
>
> From RedHat SCL:
>
> source /opt/rh/python33/enable
>
> python --version
> Python 3.3.2
>
> Inside the virtual environment I have:
>
> Django (1.6.3)
> pip (1.4.1)
> setuptools (0.9.8)
>
> That starts successfully:
>
> python manage.py runserver 192.168.0.16:8000
>
>
>
> Starting development server at http://192.168.0.16:8000/
>
> Quit the server with CONTROL-C.
>
> When getting to admin or any error page:
>
> Django Version:
>   1.6.3
> Python Version:
>   3.3.2
>
> Python Path:
>
>
> ['/data/app/guillem-py3-dj17-test/guillem_test',
>  '/data/app/guillem-py3-dj17-test/lib64/python33.zip',
>  '/data/app/guillem-py3-dj17-test/lib64/python3.3',
>  '/data/app/guillem-py3-dj17-test/lib64/python3.3/plat-linux',
>  '/data/app/guillem-py3-dj17-test/lib64/python3.3/lib-dynload',
>  '/opt/rh/python33/root/usr/lib64/python3.3',
>  '/opt/rh/python33/root/usr/lib/python3.3',
>  '/data/app/guillem-py3-dj17-test/lib/python3.3/site-packages']
> ___
>
>
> When starting this from Apache 2.2 instead of the python embedded server:
>
>
> httpd -k restart -e debug
>
>
> ...
> [Fri May 02 11:53:29 2014] [debug] mod_so.c(246): loaded module wsgi_module
> ...
>
> The Apache service starts in my port of choice:
>
> tcp0  0 192.168.0.16:8082   0.0.0.0:*   
> LISTEN  1676/httpdWhat I get now is:
>
>
> So now I get:
>
> Django Version:   1.6
> Python Executable:/data/app/guillem-py3-dj17-test/bin/python
> Python Version:   2.6.6
> Python Path:  
>
> ['/data/app/django-test/dev/test-1/HELLO_WORLD/lib/python2.6/site-packages',
>
>
>  '/data/app/django-test/dev/test-1/HELLO_WORLD/HELLO_WORLD/..',
>  '/usr/lib64/python26.zip',
>  '/usr/lib64/python2.6',
>  '/usr/lib64/python2.6/plat-linux2',
>  '/usr/lib64/python2.6/lib-tk',
>
>
>  '/usr/lib64/python2.6/lib-old',
>  '/usr/lib64/python2.6/lib-dynload',
>  '/usr/lib64/python2.6/site-packages',
>  '/usr/lib64/python2.6/site-packages/gst-0.10',
>  '/usr/lib64/python2.6/site-packages/gtk-2.0',
>
>
>  '/usr/lib/python2.6/site-packages',
>  '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info',
>  '/data/app/django-test/dev/test-1/virtual/lib/python3.3/site-packages',
>  '/data/app/django-test/dev/test-1/HELLO_WORLD/']
>
>
>
> Just to make it clear, that python inside the virtual env is python 3.3.2:
>
> (guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# pwd
> /data/app/guillem-py3-dj17-test/bin
> (guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# which 
> python
>
>
> /data/app/guillem-py3-dj17-test/bin/python
> (guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# 
> ./python --version
> Python 3.3.2
>
>
>
> 
>
>
> So, for some reason which most possibly lies with a misconfiguration from my 
> part, Apache ignores the fact that theer is another python installed in the 
> system.
>
>
> I believe this happens because the installed mod_wsgi is not compatible:
>
>
> mod_wsgi-3.2-3.el6.x86_64
>
> Is this the case?
>
>
>
>
> For whatI read here:
>
> http://code.google.com/p/modwsgi/wiki/SupportForPython3X
>
> I should be fine with mod_wsgi 3.2
>
> ___
>
>
> What I have tried:
>
> - I

Re: validate answers from a detail view

2014-04-14 Thread Brad Rice
What I am building is an app that the user can come back to to finish
filling out, so I don't want to have too many required fields until right
before they submit the form, I want to check if they forgot anything and
prompt them to fill it out. Now that I think about it, I can probably do
this with javascript on the detail view page. I suppose that is the route I
will take.


On Sun, Apr 13, 2014 at 3:37 PM, Fabio Caritas Barrionuevo da Luz <
bna...@gmail.com> wrote:

> I think this would be facilitated if the FormWizard possessed a
> confirmation step. There is a ticket open on this exact feature
>
> https://code.djangoproject.com/ticket/21644
>
>
>
> Em sábado, 12 de abril de 2014 14h28min01s UTC-3, Brad Rice escreveu:
>
>> I'm using a Class based Generic Detail View to show end users their
>> answers to previous mulit-page forms. How can I use that final detail view
>> to validate the answers? Should I not be using a Detail view or can I
>> somehow do a conditional get to the next view based upon those answers?
>> Right now I just have a link to the next page where they can submit all
>> their answers from the forms. If they haven't filled out a field, I want to
>> take them back to the form they need to go to to fix that. All it does on
>> that final page after the datail is set a true value in the db that they
>> are done updating their application form.
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/odM4dnFb8Zg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/fff50189-cf9f-4c8f-927d-575f9d38173a%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fff50189-cf9f-4c8f-927d-575f9d38173a%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Brad Rice
bradri...@gmail.com
--
“Be curious. Read widely. Try new things. What people call intelligence
just boils down to curiosity.”
- Aaron Swartz

-- 
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/CAMqTKp4hRF4%3DZE5LXy%3D%2BLpBJVQRZHR-_TJQ38QmmKMuo9Odh7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


validate answers from a detail view

2014-04-12 Thread Brad Rice
I'm using a Class based Generic Detail View to show end users their answers 
to previous mulit-page forms. How can I use that final detail view to 
validate the answers? Should I not be using a Detail view or can I somehow 
do a conditional get to the next view based upon those answers? Right now I 
just have a link to the next page where they can submit all their answers 
from the forms. If they haven't filled out a field, I want to take them 
back to the form they need to go to to fix that. All it does on that final 
page after the datail is set a true value in the db that they are done 
updating their application form.

-- 
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/1dbd99b0-f12f-4eff-aa10-754da6828184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Printing things to the server console in Django?

2014-02-21 Thread Brad Pitcher
print("information")

-
Brad Pitcher


On Fri, Feb 21, 2014 at 1:00 PM, wasingej <wasin...@onid.oregonstate.edu>wrote:

> Hi guys.  I'm pretty new to Django and I'm trying to figure out how I can
> print out information to my console that I started my web application on
> using "python manage.py runserver".
>
> Thanks,
> Jared
>
> --
> 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/bb6c3e9d-c0b3-4acc-9481-612c29ae41a1%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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/CAMFpZriode-qcfQ0CFso1TVm2x575-Tzp%2BD%3Dwq1cFRFpyhck_A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Do you think Django's future is threatened by JS frameworks in both client & server?

2014-01-27 Thread Brad Moore
The tech giants are pushing JavaScript more than Python these days. 
 JavaScript is said to be the future language for enterprise applications. 
I think Python will be around but will play a third place role behind 
JavaScript and PHP. Yes, I said PHP and I apologize but its true just look 
at the cloud support that is quietly being offered for PHP. I have used PHP 
extensively and it can be very good and very bad depending on the 
developer. .NET is terrible I almost quit an IT career before it started 
because we were forced to use Visual Studio and Microsoft technologies for 
web development in college. My opinion as long as good design principles 
are followed using an MVC approach all three are good choices. Python is 
not going to go away because it is being used to teach the next generation 
of computer scientists throughout the world. Get used to { } all over the 
place or just stick with Python and Django it will not matter.  

On Monday, January 27, 2014 5:44:12 PM UTC-5, damond...@gmail.com wrote:
>
> Hi,
>
> I would like to know if this community is somewhat worried about the 
> future relevance of Django (and other purely server-side MV* Python web 
> app frameworks such as web2py for that matter) given the current momentum 
> of JavaScript (JS) everywhere?
>
> There are many competing architecture patterns for a WHOLE web app today 
> ranging:
> a)  from client-heavy SPA with a client-side MVC framework synching its 
> models via a REST API with a server-side reduced to a database access layer
>
> b) to light client apps with a server-side MVC frameworks and very little 
> or no Ajax 
>
> c) and everything in the middle.
>
> I guess it is not too controversial to say that which is best (or even 
> merely adequate) depends on the generally moving target of the app 
> requirements (especially the non-functional ones) and thus a long 
> lifecycle app can be expected to have to change pattern at some point.
>
>
> Given that:
> 1) full web apps following any pattern can today be developed exclusively 
> with JavaScript (JS) frameworks on both sides who have incorporated most 
> (if not all) great design ideas from Django (and Rails)
>
> 2) IDEs ranging from Visual Studio to browser-based ones are available to 
> support such development
>
> 3) Python in the browser projects do not yet provide productive debugging 
> support (and will they ever without support from a tech giant?)
>
> 4) Cloud giants (Amazon, Google, Heroku, Microsoft) all offering JS framework 
> running servers
>
> are the productivity gains from the more legible, concise and abstract 
> Python code as compared to JS code really compensate the productivity 
> loss of having to port part of the app from one language to other every 
> time it must be pushed from one side (say server) to the other (say 
> client), or even to maintain a code base in two languages instead of one?
>
> Why then adopt Django (or web2py) for a new project today, instead of 
> going pure JS?
>
> I am a big Python fan in terms of design and principles, but I am fearing 
> that it has started to lose the popularity/adoption/community size battle 
> against JS, which, from a pragmatic productivity standpoint is relevant 
> and thus potentially snowballing after a tipping point is reached. Trends 
> are deadly fast in web development, cf. how quickly J2EE+static HTML, then 
> J2EE+Flash and .NET+Silverlight have fallen from grace.
>
> Any thought on 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/02a3d0f6-2304-422e-acc5-083d4af7d219%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save to User table first_name and last_name from a page with a different form

2014-01-22 Thread Brad Rice
I think I figured it out. The user is on the reuqest so it was pretty easy.

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.application_id = self.kwargs['app_id']
u = self.request.user
u.last_name = obj.last_name;
u.first_name = obj.first_name;
obj.save()
u.save()
#reverse_lazy = lambda name=answers, *args : lazy(reverse, 
str)(name, args=args)
return HttpResponseRedirect(reverse('requestform:answers', 
kwargs={'app_id': obj.application_id}))


On Wednesday, January 22, 2014 9:48:27 AM UTC-5, Brad Rice wrote:
>
> I have a registration and login page that only takes username and 
> password. After they register or login, they are taken to a profile form 
> where they can provide additional information such as address and phone 
> numbers. I'm using a Model Form CreateView there. On that page I want the 
> First Name and Last Name fields to  save to the auth_user table rather than 
> that Profile Form model. How do I have two fields submit data to the 
> auth_user table and the other fields submit to the Profile table?
>

-- 
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/dcf1ea7c-92fb-405b-885d-9656c91d782f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Save to User table first_name and last_name from a page with a different form

2014-01-22 Thread Brad Rice
I have a registration and login page that only takes username and password. 
After they register or login, they are taken to a profile form where they 
can provide additional information such as address and phone numbers. I'm 
using a Model Form CreateView there. On that page I want the First Name and 
Last Name fields to  save to the auth_user table rather than that Profile 
Form model. How do I have two fields submit data to the auth_user table and 
the other fields submit to the Profile table?

-- 
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/9ee380ec-3f2d-465c-a784-5b44518cc655%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: NoReverseMatch error on redirect

2014-01-14 Thread Brad Rice
I figured it out. I had a namespaced url so it needed:

return HttpResponseRedirect(reverse('requestform:registrant_add', 
kwargs={'app_id': obj.id}))

On Monday, January 13, 2014 12:22:59 PM UTC-5, Brad Rice wrote:
>
> I have a mulit-page form I am building. I get the start page to enter the 
> data for the application, validate and save. When I try using reverse to 
> move to the next page I get this error:
>
> NoReverseMatch at /requestform/start/Reverse for 'registrant_add' with 
> arguments '()' and keyword arguments '{'app_id': 11}' not found.
>
> I have this url in my urls.py
>
> url(r'^step1/(?P\d+)/$, RegistrantCreate.as_view(), 
> name="registrant_add"),
>
> I am trying to call the view this way:
>
> class ApplicationCreate(CreateView):
> model = Application
> form_class = ApplicationForm
> slug_field = 'created_by'
> template_name = 'requestform/start_form.html'
>
> @method_decorator(login_required)
> def dispatch(self, *args, **kwargs):
> return super(ApplicationCreate, self).dispatch(*args, **kwargs)
>
>
> def form_valid(self, form):
> obj = form.save(commit=False)
> obj.created_by = self.request.user
> obj.created = datetime.datetime.today()
> obj.modified = datetime.datetime.today()
> obj.save()
> return HttpResponseRedirect(reverse('registrant_add', 
> kwargs={'app_id': obj.id}))
>
> Why doesn't django recognize the named url 'registrant_add' and redirect 
> to it?
>
>
>
>

-- 
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/c8908fe0-1b86-4dcb-a977-cb4a6c999186%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


NoReverseMatch error on redirect

2014-01-13 Thread Brad Rice
I have a mulit-page form I am building. I get the start page to enter the 
data for the application, validate and save. When I try using reverse to 
move to the next page I get this error:

NoReverseMatch at /requestform/start/Reverse for 'registrant_add' with 
arguments '()' and keyword arguments '{'app_id': 11}' not found.

I have this url in my urls.py

url(r'^step1/(?P\d+)/$, RegistrantCreate.as_view(), 
name="registrant_add"),

I am trying to call the view this way:

class ApplicationCreate(CreateView):
model = Application
form_class = ApplicationForm
slug_field = 'created_by'
template_name = 'requestform/start_form.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(ApplicationCreate, self).dispatch(*args, **kwargs)


def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.created = datetime.datetime.today()
obj.modified = datetime.datetime.today()
obj.save()
return HttpResponseRedirect(reverse('registrant_add', 
kwargs={'app_id': obj.id}))

Why doesn't django recognize the named url 'registrant_add' and redirect to 
it?



-- 
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/a7a2ad99-0be5-4aa8-8c1f-05fc3e0b85c0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


using success_url

2014-01-10 Thread Brad Rice
I can't seem to find success using success_url

If I try this in my urls.py file

url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), 
name='answers'),

and then in my view:

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
return HttpResponseRedirect(self.get_success_url())

I get a successful save but it does not take me to the next url defined in 
success_url

Is there another way to do it, or what am I doing wrong?

-- 
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/775978f7-774f-4ef5-b12e-9e97f3c3864a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to edit a model with an inline formset

2014-01-10 Thread Brad Rice
I'm following that blog entry, too, and getting an error when I try to 
save: [u'ManagementForm data is missing or has been tampered with']

On Thursday, January 9, 2014 11:57:37 AM UTC-5, Cody Scott wrote:
>
> I am trying to create a model with an inline formset. I followed the guide 
> here 
> http://kevindias.com/writing/django-class-based-views-multiple-inline-formsets/
>
>
> Creating my model as in the guide works. But I am trying to edit my model. 
> The EditPage renders fine with the form but when I submit the form I get an 
> error on the {{ skill_form.management_form }} line in my template. list index 
> out of range.
>
>
> #modelsclass Job(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='jobs')
> title = models.CharField('job title', max_length=255)
> slug = models.SlugField(max_length=255, blank=True, default='')
> city = models.CharField(max_length=255)
> company = models.CharField(max_length=255)
> start_date = models.DateField()
> type = models.CharField("Work Shedule", max_length=255)
> remote = models.BooleanField("Remote Work")
> contact = models.TextField()
>
> description = models.TextField()
> requirements = models.TextField(null=True, blank=True)
> responsibilities = models.TextField(null=True, blank=True)
> education = models.TextField(null=True, blank=True)
> experience = models.TextField(null=True, blank=True)
> perks = models.TextField(null=True, blank=True)
> about = models.TextField("About the Company", null=True, blank=True)
>
> post_date = models.DateField(auto_now_add=True, editable=False)
> updated_date = models.DateTimeField(auto_now=True, editable=False)
>
> class Meta:
> ordering = ["-updated_date", "title"]
>
> def __unicode__(self):
> return self.title
>
> def save(self, *args, **kwargs):
> if not self.slug:
> self.slug = slugify(self.title)
> super(Job, self).save(*args, **kwargs)
>
> def get_absolute_url(self):
> return reverse('job:view', args=(), kwargs={'id': self.id, 'slug': 
> self.slug})
>
> class Skill(models.Model):
> job = models.ForeignKey(Job, related_name='skills')
> skill = models.CharField(max_length=255)
>
>
> def __unicode__(self):
> return self.skill
> #formsclass JobForm(forms.ModelForm):
> type = forms.ChoiceField(choices=[('Full-Time', 'Full-Time'), 
> ('Part-Time', 'Part-Time')])
>
> class Meta:
> model = Job
> fields = ['title', 'city', 'company', 'start_date', 'description',
>   'requirements', 'responsibilities', 'education', 'experience',
>   'perks', 'contact', 'remote', 'about']
>
> SkillFormSet = inlineformset_factory(Job, Skill)
>
> #viewsclass CreateJob(generic.CreateView):
> model = Job
> template_name = 'job/add.html'
> form_class = JobForm
>
> def get(self, request, *args, **kwargs):
> """instantiates blank versions of the formand its 
> inline formsets"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet()
> return self.render_to_response(self.get_context_data(
> form=form,
> skill_form=skill_form,
> ))
>
> def post(self, request, *args, **kwargs):
> """instantiates the form with its inline formsetswith 
> the passed POST data and validates"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet(self.request.POST)
> if form.is_valid() and skill_form.is_valid():
> return self.form_valid(form, skill_form)
> else:
> return self.form_invalid(form, skill_form)
>
> def form_valid(self, form, skill_form):
> """If both forms are valid then create Job with skills and 
> redirect"""
> self.object = form.save(commit=False)
> self.object.user = self.request.user
> self.object.save()
> skill_form.instance = self.object
> skill_form.save()
> return HttpResponseRedirect(self.object.get_absolute_url())
>
> def form_invalid(self, form, skill_form):
> """If either of the forms are invalidRe-render the 
> page with data-filled forms and errors"""
> return self.render_to_response(self.get_context_data(form=form, 
> skill_form=skill_form))
>
> @method_decorator(login_required(login_url=reverse_lazy('login')))
> def dispatch(self, *args, **kwargs):
> return super(CreateJob, self).dispatch(*args, **kwargs)
>
> class EditJob(generic.UpdateView):
> model = Job
> template_name = 'job/edit.html'
> context_object_name = 'job'
>
> def get(self, request, *args, **kwargs):
> """instantiates the form and 

Re: saving to two models from one class view

2014-01-10 Thread Brad Rice
Thanks for the help.

I've modified the Applicant model:

class Application(models.Model):
app_complete = models.BooleanField(default=False)
applicant = models.ForeignKey('Applicant', unique=True)
created_by = models.ForeignKey(User, related_name='+')

There is really no data being entered by the end user, I just want to 
create a row with the application_id (auto generated), user, a relation to 
the applicant table and the default value of false in the app_complete 
field. When I fill out the form and post I still get Validation Errors on 
the related formset.

[u'ManagementForm data is missing or has been tampered with']

My template is simple:

{% extends "base.html" %}
{% block title %}Add Applicant Information{% endblock %}
{% block head %}Add Applicant Information{% endblock %}
{% block content %}

{% csrf_token %}

{{ form.as_p }}

{{ application_form.management_form }}
{{ application_form.non_form_errors }}


{% endblock %}

I'm really feeling the newbie moniker.


On Friday, January 10, 2014 2:49:43 AM UTC-5, trojactory wrote:
>
> Hi Brad,
>
> At the moment, two models do not have any relationship. I think you made 
> an error in Line 3:
>
> created_by = models.ForeignKey(User, unique=True)
>
> I think you meant "Applicant" instead of User.
>
> Regards,
> Arun
>
> On Friday, January 10, 2014 3:13:42 AM UTC+5:30, Brad Rice wrote:
>>
>> I have been banging around trying to write to two models from one view 
>> for a couple days and just cannot figure it out.
>>
>> I am using a CreateView. I want to write to a model with just the 
>> created_by user and a default value of False in app_complete to. I'm 
>> getting this error:
>>
>> [u'ManagementForm data is missing or has been tampered with']
>>
>> Could anyone help me figure out how to save to two models from a class 
>> view?
>>
>> Models I'm trying to save to:
>>
>> class Application(models.Model):
>> app_complete = models.BooleanField(default=False)
>> created_by = models.ForeignKey(User, unique=True)
>>
>>
>> class Applicant(models.Model):
>> first_name = models.CharField(max_length=100)
>> last_name = models.CharField(max_length=100)
>> title = models.CharField(max_length=100)
>> ... more fields
>>
>> My forms view:
>>
>> class RegistrantForm(forms.ModelForm):
>> ADDRESS_CHOICES = (('home', 'Home',), ('business', 'Business',))
>> address_type = forms.ChoiceField(
>> choices=ADDRESS_CHOICES, widget=forms.Select
>> )
>> street2 = forms.CharField(required=False)
>> cell_phone = forms.CharField(required=False)
>> fax_phone = forms.CharField(required=False)
>>
>> class Meta:
>> model = Applicant
>> fields = ('first_name', 'last_name', 'title', 'years_at_job', 
>> 'street1', 'street2', 'city', 'state', 'zip', 'address_type', 'residence', 
>> 'phone', 'cell_phone',
>>   'fax_phone')
>> exclude = ['created_by']   # Will be taken from the request
>>
>> class ApplicationForm(forms.ModelForm):
>> app_complete = forms.BooleanField(required=True, label="Check this to 
>> confirm the application is complete.")
>>
>> class Meta:
>> model = Application
>> fields = ('app_complete', 'created_by')
>>
>>
>> ApplicationFormSet = inlineformset_factory(Application, Applicant)
>>
>> Then my view which doesn't work:
>>
>> class RegistrantCreate(CreateView):
>> model = Applicant
>> form_class = RegistrantForm
>> template_name = 'applicant_form.html'
>> success_url = '/requestform/update2/'
>>
>> @method_decorator(login_required)
>> def dispatch(self, *args, **kwargs):
>> return super(RegistrantCreate, self).dispatch(*args, **kwargs)
>>
>> def get(self, request, *args, **kwargs):
>> """
>> Handles GET requests and instantiates blank versions of the form
>> and its inline formsets.
>> """
>> self.object = None
>> form_class = self.get_form_class()
>> form = self.get_form(form_class)
>> application_form = ApplicationFormSet()
>> return self.render_to_response(
>> self.get_context_data(form=form,
>>   applicaton_form=application_form))
>>
>> def post(self, request, *args, **kwargs):
>> """
>&

saving to two models from one class view

2014-01-09 Thread Brad Rice
I have been banging around trying to write to two models from one view for 
a couple days and just cannot figure it out.

I am using a CreateView. I want to write to a model with just the 
created_by user and a default value of False in app_complete to. I'm 
getting this error:

[u'ManagementForm data is missing or has been tampered with']

Could anyone help me figure out how to save to two models from a class view?

Models I'm trying to save to:

class Application(models.Model):
app_complete = models.BooleanField(default=False)
created_by = models.ForeignKey(User, unique=True)


class Applicant(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
title = models.CharField(max_length=100)
... more fields

My forms view:

class RegistrantForm(forms.ModelForm):
ADDRESS_CHOICES = (('home', 'Home',), ('business', 'Business',))
address_type = forms.ChoiceField(
choices=ADDRESS_CHOICES, widget=forms.Select
)
street2 = forms.CharField(required=False)
cell_phone = forms.CharField(required=False)
fax_phone = forms.CharField(required=False)

class Meta:
model = Applicant
fields = ('first_name', 'last_name', 'title', 'years_at_job', 
'street1', 'street2', 'city', 'state', 'zip', 'address_type', 'residence', 
'phone', 'cell_phone',
  'fax_phone')
exclude = ['created_by']   # Will be taken from the request

class ApplicationForm(forms.ModelForm):
app_complete = forms.BooleanField(required=True, label="Check this to 
confirm the application is complete.")

class Meta:
model = Application
fields = ('app_complete', 'created_by')


ApplicationFormSet = inlineformset_factory(Application, Applicant)

Then my view which doesn't work:

class RegistrantCreate(CreateView):
model = Applicant
form_class = RegistrantForm
template_name = 'applicant_form.html'
success_url = '/requestform/update2/'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(RegistrantCreate, self).dispatch(*args, **kwargs)

def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates blank versions of the form
and its inline formsets.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
application_form = ApplicationFormSet()
return self.render_to_response(
self.get_context_data(form=form,
  applicaton_form=application_form))

def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a form instance and its inline
formsets with the passed POST variables and then checking them for
validity.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
application_form = ApplicationFormSet(self.request.POST)
if (form.is_valid() and application_form.is_valid() and
application_form.is_valid()):
return self.form_valid(form, application_form)
else:
return self.form_invalid(form, application_form)

def form_valid(self, form, application_form):
"""
Called if all forms are valid. Creates a Recipe instance along with
associated Ingredients and Instructions and then redirects to a
success page.
"""
self.object = form.save(commit=False)
self.object.created_by = self.request.user
self.object = form.save()
application_form.instance = self.object
application_form.save(commit=False)
application_form.instance.created_by = self.request.user
application_form.save()
return HttpResponseRedirect(self.get_success_url())

def form_invalid(self, form, application_form):
"""
Called if a form is invalid. Re-renders the context data with the
data-filled forms and errors.
"""
return self.render_to_response(
self.get_context_data(form=form,
  application_form=application_form)
)

-- 
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/a4429a32-dfe1-42fd-a9ce-ccf8e7e2885b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Admin permissions for proxy ModelAdmins?

2013-11-27 Thread Brad Smith
Hello all, 

I want to have multiple admin interfaces for editing the same model under 
different circumstances. The way I've been doing this is to register 
multiple proxy models, each with their own ModelAdmins. However, the proxy 
models don't seem to generate permissions, so they don't show up in the 
admin interface for non-superusers. The fact that they do show up for 
superusers suggests that there's a way to make them available to others, 
but I'm having trouble figuring out how.

Based on things I've read since I came up with this plan, it's sounding 
like a better way to do what I'm trying to do would be to override 
change_view() on a single ModelAdmin anyway, but I'm still curious about 
the above, in case it ever becomes relevant again (and, while I'm at it, a 
sanity-check on my suspicion that the change_view approach is indeed the 
more appropriate solution would be nice!).

Thanks!
--Brad

-- 
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/4c82321c-c4a1-4738-9bdb-277b07ebbefb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using admin views "outside" of admin

2013-11-21 Thread Brad Smith
...and of course now I find a FAQ item that seems to talk about exactly 
what I want to do:

  
https://docs.djangoproject.com/en/1.6/faq/admin/#how-do-i-limit-admin-access-so-that-objects-can-only-be-edited-by-the-users-who-created-them

I'm still curious to hear comments, though, because if this is possible 
then I'm no longer clear what the conventional wisdom is regarding when and 
how to use AdminSite vs when it's time to buckle down and write your own 
interface. 

While I'm at it, and possibly related to the above, ultimately what I'd 
like to be able to do is load and submit editing forms from within the view 
interface via AJAX (ie click an icon on an object and the regular content 
is replaced with the corresponding admin edit form).  It looks like you can 
add '_popup=1' to any admin url and get something that could work 
reasonably well for embedding, and then you'd just need some javascript to 
cause the submit button to use e.g. jQuery.post()... right? 

Any tips/warnings with regard to this?

--Brad

-- 
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/dfae28eb-b7d6-4abd-afac-564e7f389521%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using admin views "outside" of admin

2013-11-21 Thread Brad Smith
Thanks for the reply! The main thing I'm looking for is the ability to 
create more granular permissions. For example, I want only the person who 
creates an instance of something (plus a few admins) the be able to modify 
that instance. I talk about working "outside" the admin interface because 
my understanding from other threads I've read is that the admin is designed 
on the assumption that everyone either has admin privileges or doesn't on a 
per-class (as opposed to per-object) basis, and if you want more than that 
you're going to have to build your own editing interface. 

Of course, what I'd love to hear is that I have this all wrong and there's 
an easy way to implement the concept of object ownership, custom 
permissions, etc in the existing admin interface. I guess subclassing 
AdminSite could be a start to this, but at least at first glanceI don't see 
anything in the docs about replacing or extending the access control 
mechanism. Anyone have advice along those lines?

Thanks again!
--Brad

On Wednesday, November 20, 2013 5:32:30 PM UTC-5, Gonzalo Delgado wrote:
>
> -BEGIN PGP SIGNED MESSAGE- 
> Hash: SHA256 
>
> El 20/11/13 12:54, Brad Smith escribi�: 
> > Based on other threads I've read here, it seems that the 
> > conventional wisdom is that the admin interface is only for 
> > low-level access to the database, and isn't designed for anything 
> > "fancy", like users with different levels of administrative rights 
> > within an app, etc. Ok, I get that, but if I may grasp at some 
> > straws briefly I'd like to ask one follow-up that I haven't seen 
> > answered elsewhere: my app has a bunch of objects with complicated 
> > relationships for which I've devised a reasonably pretty and 
> > intuitive editing interface using Django's admin and Grappelli. 
> > Since this took a nontrivial amount of effort, I wanted to ask here 
> > if there are any tricks I should know about for re-using *any* 
> > views, inlines, etc from that admin interface in a more integrated 
> > editing interface with granular access controls, or do I just need 
> > to suck it up and rewrite everything from scratch using regular 
> > Django forms? 
>
> The django admin code is very extensible and re-usable. The 
> documentation may not stress this enough, but it is possible to do 
> virtually anything you want with it. 
>
> If I'm understanding your "outside" of the admin concept correctly, 
> what you want to do is extend the AdminSite[0] class (or maybe not 
> even that, just create a new instance) and attach the ModelAdmins you 
> want to it. I think you can even use autodiscover with a custom 
> AdminSite instance too if you need to have all models from 
> settings.INSTALLED_APPS attached to it. 
>
>
> [0] 
> https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#adminsite-objects<https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.6%2Fref%2Fcontrib%2Fadmin%2F%23adminsite-objects=D=1=AFQjCNHS1o9zmTuOBtsRtLct8Erv3F29KQ>
>  
>
> - -- 
> Gonzalo Delgado 
> -BEGIN PGP SIGNATURE- 
> Version: GnuPG v1.4.15 (Darwin) 
> Comment: Using GnuPG with Thunderbird - 
> http://www.enigmail.net/<http://www.google.com/url?q=http%3A%2F%2Fwww.enigmail.net%2F=D=1=AFQjCNEmzvPO3jS2yzcUMn8rNiYnCtPc-g>
>  
>
> iF4EAREIAAYFAlKNOH4ACgkQzbfdFL5JoUlCVQD6A1TUqYfKbgBDITrpvFblkQfo 
> nrVMCxnxSPIiREHgJaMBAKTR2auknxE6sX5s62B0j8eiH+AJB1EG1+AxeXoVHlGX 
> =kthG 
> -END PGP SIGNATURE- 
>

-- 
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/4bd041e0-2e4c-449c-9da8-2260c3af66f4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Using admin views "outside" of admin

2013-11-20 Thread Brad Smith
Hello all,

Based on other threads I've read here, it seems that the conventional 
wisdom is that the admin interface is only for low-level access to the 
database, and isn't designed for anything "fancy", like users with 
different levels of administrative rights within an app, etc. Ok, I get 
that, but if I may grasp at some straws briefly I'd like to ask one 
follow-up that I haven't seen answered elsewhere: my app has a bunch of 
objects with complicated relationships for which I've devised a reasonably 
pretty and intuitive editing interface using Django's admin and Grappelli. 
Since this took a nontrivial amount of effort, I wanted to ask here if 
there are any tricks I should know about for re-using *any* views, inlines, 
etc from that admin interface in a more integrated editing interface with 
granular access controls, or do I just need to suck it up and rewrite 
everything from scratch using regular Django forms?

Thanks to anyone who can offer some advice. 
--Brad 

-- 
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/e0f27e3a-5c6b-4a92-b6c5-c266323fa118%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-17 Thread Brad Pitcher
To make my code work, you could set DJANGO_SETTINGS_MODULE to
'my_project.settings', and just put formdesigner.py directly under
my_project.

If you wanted to keep formdesigner.py where it is, you would want to change
the sys.path.append line to this:

sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),
'..'))


-
Brad Pitcher


On Tue, Sep 17, 2013 at 12:25 AM, DJ-Tom <eventel...@gmail.com> wrote:

>
> Hi,
>
> I'm also not sure if the python file is at the correct location.
>
> This is how the directory structure looks:
>
> my_project
> \my_project\
>  settings.py
> \my_app\ # this is where my models are defined
>  models.py
>  formdesigner.py
>
>
> Where should my formdesigner.py be located?
>
> my_project ?
> my_project\my_project ?
> my_project\my_app ?
>
> What do I put into DJANGO_SETTINGS_MODULE?
>
> 'my_project.settings'?
>
>
> Am Montag, 16. September 2013 18:17:21 UTC+2 schrieb Brad Pitcher:
>
>> You need to do something like this before import django stuff:
>>
>> import os
>> import sys
>>
>> sys.path.append(os.path.**abspath(os.path.dirname(__**file__)))
>> os.environ['DJANGO_SETTINGS_**MODULE'] = 'web.settings'
>>
>>
>> -
>>
>>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-16 Thread Brad Pitcher
You need to do something like this before import django stuff:

import os
import sys

sys.path.append(os.path.abspath(os.path.dirname(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'


-
Brad Pitcher


On Mon, Sep 16, 2013 at 8:19 AM, Nigel Legg <nigel.l...@gmail.com> wrote:

> Shouldn't it be
>
>from django.db import models
>
> ??
>
> Cheers, Nigel
> 07914 740972
>
>
>
> On 16 September 2013 15:25, DJ-Tom <eventel...@gmail.com> wrote:
>
>> For reporting purposes I want to use List & Label from Combit. The
>> web/online part is no big deal since the reporting module can be run
>> without user interface (creating Excel or PDF files)
>>
>> But the actual form designer part that is used to define the report
>> layout is a windows GUI application, so I would like to have a python file
>> inside my Django app that I can call to start the designer part on my local
>> machine.
>>
>> I have now read a bunch of descriptions on how to use Django in a
>> standalone application but did not succeed so far in actually running my
>> form designer.
>>
>> This is what I currently have, i tried to start this via "python
>> formdesigner.py", after activating the correct virtualenv:
>>
>> from Tkinter import *
>> from ctypes import *
>> import django
>> from models import *
>>
>> LL = windll.cmll18
>>
>> ### Declaration of application class omitted, this is plain python  
>>
>> app = Application()
>> app.master.title("List & Label sample application")
>> app.mainloop()
>>
>>
>> Regardless what I try, I can't get the model class import to work.
>>
>> I also tried SET DJANGO_SETTINGS_MODULE=settings and project.settings and
>> project.app.settings... nothing worked.
>>
>> thomas
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: SQLite3 database error!!!

2013-04-21 Thread Brad Pitcher
Can you post the rest of the traceback?
On Apr 21, 2013 7:06 AM, "Kakar"  wrote:

> I am in settings.py and using SQLite3. But when i execute manage.py
> syncdb, it gives me error: "Value error: Empty module name" I didn't
> understood this part. Plz help me guyz.
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread Brad Pitcher
I see what you're saying. Maybe you're looking for something more like this?

def method1(self, param1=sensible_default, param2=sensible_default,
param3=sensible_default):
print param1, param2, param3

The variable names must be specified in the method arguments like above if
you wish to reference them by name inside the method itself. With this
method, you will also need to call it with: model.method1(**params)

On Tue, Apr 16, 2013 at 9:59 PM, jayhalleaux <jay.halle...@gmail.com> wrote:

> but if I did that then i would have a variable named kwargs.
>
> and it would be print kwargs['param1'], etc
>
> Why even unpack the dictionary?  I could just pass the dictionary instead.
>
>
> On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>
>> It should be:
>> model.method1(**params)
>> On Apr 16, 2013 7:49 PM, "jayhalleaux" <jay.ha...@gmail.com> wrote:
>>
>>>  Not really a Django question but I'm trying to create a model method
>>> that does not have a fixed set of parameters.
>>>
>>> models.py
>>> Class Model_A(model.Model):
>>> ...
>>>
>>> def method1(self, **kwargs):
>>>
>>> print param1, param2, param3
>>>
>>>
>>>
>>> views.py
>>> params = dict(
>>>
>>> param1=something1,
>>> param2=something2,
>>>  param3=something3,
>>> ...
>>>
>>> )
>>>
>>> model.method1(params)
>>>
>>> In this example when I try to do something like this it states that I
>>> should have passed only 1 parameter instead of 2.
>>>
>>> I thought the whole point of using '**' to unpack dictionaries is so you
>>> don't have to have a fixed number of parameters.
>>>
>>> Is there something I am missing or am I doing this incorrect? First time
>>> I'm trying to create a method like this.  Normally I explicitly state all
>>> parameters.
>>>
>>> Any help is appreciated.
>>>
>>> --
>>> 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?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread Brad Pitcher
It should be:
model.method1(**params)
On Apr 16, 2013 7:49 PM, "jayhalleaux"  wrote:

> Not really a Django question but I'm trying to create a model method that
> does not have a fixed set of parameters.
>
> models.py
> Class Model_A(model.Model):
> ...
>
> def method1(self, **kwargs):
>
> print param1, param2, param3
>
>
>
> views.py
> params = dict(
>
> param1=something1,
> param2=something2,
> param3=something3,
> ...
>
> )
>
> model.method1(params)
>
> In this example when I try to do something like this it states that I
> should have passed only 1 parameter instead of 2.
>
> I thought the whole point of using '**' to unpack dictionaries is so you
> don't have to have a fixed number of parameters.
>
> Is there something I am missing or am I doing this incorrect? First time
> I'm trying to create a method like this.  Normally I explicitly state all
> parameters.
>
> Any help is appreciated.
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django-social-auth problem with facebook

2013-04-15 Thread Brad Pitcher
In my experience, that particular error always means that the database
doesn't match what you have in your models. Try a syncdb and/or check your
south migrations to make sure your database is up to date.

-
Brad Pitcher
Software Developer
(702)723-8255


On Sun, Apr 14, 2013 at 11:01 PM, Jeff Hsu <jyhsu1...@gmail.com> wrote:

> Hi, I just pip installed django-social-auth from omab today on
> github(beginner here).  I think I can almost get it to work with facebook
> login, but I always have this "InternalError: Exception Value: current
> transaction is aborted, commands ignored until end of transaction block",
> after I log in with my facebook account and before I redirect to the
> profile page.  The request url shows
>
> http://127.0.0.1:8000/complete/facebook/?redirect_state=xxx=xxx=xxx.
>  I'm using Django 1.5.  Can anybody give me some directions to debug this?
>
> Thank you tons,
> Jeff
>
>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Implementing query with Django ORM - left join with length() and replace() functions

2013-04-05 Thread Brad Buran
 I'm trying to replicate a query using Django's ORM; however, I'm having a 
bit of difficulty figuring out how to accomplish it.  The model that I'm 
querying is defined as:

class Word(models.Model):

objects = WordManager()
spelling = models.CharField(max_length=128)
ipa = models.CharField(max_length=128)

The query I'm trying to accomplish:

SELECT 
a.id, a.spelling, a.ipa
b.spelling as b_spelling, b.ipa as b_ipa
FROM 
dictionary_word as a, dictionary_word as b 
WHERE
a.ipa != b.ipa
and length(a.ipa) = length(b.ipa)
and a.ipa = replace(b.ipa, '%s', '%s')

The idea of this query is to find all pairs of words that differ by one 
phoneme (e.g. "mat" and "bat" differ by only one sound).  Is this query 
possible to accomplish with the ORM, or do I need to use a raw query?

Thanks,
Brad

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Can't store valid JSON in JSONField because of SubfieldBase/to_python issues

2013-03-21 Thread Brad Jasper
I ended up moving this to the Django bug tracker thinking it was an issue 
with Django itself: https://code.djangoproject.com/ticket/20090

Someone over there pointed me in the right direction: You need to subclass 
SubfieldBase and call your own method instead of to_python. You can pass 
the custom ModelField along with the value and check the state that way. 
This seems to have solved my problem pretty well.

For an example, check out what we used on 
django-jsonfield: 
https://github.com/bradjasper/django-jsonfield/blob/master/jsonfield/subclassing.py

On Thursday, March 14, 2013 11:23:21 AM UTC-4, Brad Jasper wrote:
>
> I maintain django-jsonfield, a project that allows you to store arbitrary 
> JSON objects in the database.
>
> It's having a problem with the way to_python is called while 
> using SubfieldBase. A full explanation of the problem is here (
> https://github.com/bradjasper/django-jsonfield/issues/33), but here's my 
> best attempt at a summary:
>
> - We're unable to tell whether the value passed in to_python is already 
> encoded JSON
> - Because of this we can't store certain types of JSON values that should 
> be valid
> - The issues seems to be with the fact that Django uses to_python for both 
> the serialized and original value
>
> This might be an issue that needs to be fixed with Django itself, but I 
> wanted to reach out here first and see if anyone had any suggestions on how 
> to solve this.
>
> Any help is appreciated.
>
> Thanks,
> Brad
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Suggestion for using distinct on django 1.4+ in your unit tests?

2013-03-06 Thread Brad Pitcher
I believe sqlite supports "distinct" just not "distinct on". I have always
managed to find workarounds using "distinct" anywhere I formerly used
"distinct on".
On Mar 6, 2013 7:01 AM, "Toran Billups"  wrote:

> I recently upgraded to django 1.4 and found that my "distinct" queries
> don't work anymore in my test code because sqlite doesn't support it -how
> is everyone using this for integration testing?
>
> Thank you in advance
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Upgrade to django 1.5

2013-03-04 Thread Brad Pitcher
It should be safe, just test things out. Also, if you have DEBUG=False you
must also include an ALLOWED_HOSTS array, which became required in Django
1.4.4:
https://www.djangoproject.com/weblog/2013/feb/19/security/#s-issue-host-header-poisoning

It should contain a list of domains used to access the site.

On Sun, Mar 3, 2013 at 6:29 PM, Randa Hisham  wrote:

> Iam now working in aproject using django 1.4.2 could I upgrade to django
> 1.5?
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to abstract model methods to a separate class?

2013-02-26 Thread Brad
On Tue, 2013-02-26 at 07:53 -0800, Richard Brockie wrote:
> class myLinksClass:
> basepath = 'testing/'
> 
> def self(self):
> return "%s" % (self.basepath, )
> 
> def view1(self):
> return "%s%s" % (self.basepath, 'view1', )
> 
> def view2(self):
> return "%s%s" % (self.basepath, 'view2', )
> 
> class MyModel(models.Model):
> 
> date = models.DateField()
> slug = models.SlugField()
> 
> def links(self):
> thelinks = myLinksClass
> return thelinks

If this is the actual syntax you used, then my best guess is that the
problem is that you are passing a class rather than an instanciated
object and those aren't class methods. Either instanciate an object or
remove the "self" arguments to make those class methods and it should
work.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I get the current user in a model?

2013-02-11 Thread Brad
Sounds like you are maybe calling a user method from a template? You
will probably want to create a custom tag or filter:
https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/

A filter would look like this:
{{ my_model_item|price:request.user }}

And the filter itself something like this:

def price(my_model_item, user):
"""Returns the price for the user"""
# Logic to evaluate the price could be here on in a
# model method, but if it's in the model method you
# will need to pass the user as a parameter to that
# method.
return evaluated_price

On Mon, 2013-02-11 at 07:05 -0800, frocco wrote:
> What I am trying to do, is I have four price fields in my model and
> need to return just one based on current user logged in.
> 
> 
> price_a
> price_b
> price_c
> price_d
> 
> 
> I want to always return a field named price, based on one of those
> fields.
> 
> On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote:
> Ok, but is request available in models.py?
> 
> 
> On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
> On Mon, Feb 11, 2013 at 7:42 PM, frocco
>  wrote: 
> > Hello, 
> > 
> > I have some logic I want to put in a model, but it
> requires know the current 
> > user logged in. 
> > Is there a way to get this? 
> > 
> This gets the current logged in user : 
> 
> current_user = request.user 
> 
> -- 
> Sandeep Kaur 
> E-Mail: mkaur...@gmail.com 
> Blog: sandymadaan.wordpress.com 
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Collectstatic not working

2013-02-10 Thread Brad
The problem is that you have your STATIC_ROOT as one of the
STATICFILES_DIRS. The STATIC_ROOT directory should be empty, that is
where all the static files from different places will be gathered when
you run collectstatic. You should probably create a static directory
under the myapp directory and move all your static files there. Leave
the STATIC_ROOT setting as you have it now, and don't specify
STATICFILES_DIRS. By default django looks in static directories under
all apps in INSTALLED_APPS.

On Mon, 2013-02-11 at 01:50 +0530, Satinderpal Singh wrote:
> On running ./manage.py  collectstatic in the terminal, gives
> following message.
> 
> 
> 
> "The STATICFILES_DIRS setting should "
> django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS
> setting should not contain the STATIC_ROOT setting


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why i can't get the debug informations (in case of error) when i run LiveServerTestCase tests?

2013-02-09 Thread Brad
I admit it is vexing that Django overrides what you have specified in
the settings file in this case, but it doesn't seem to be hard to
override. I simply added "settings.DEBUG = True" to the beginning of the
"setUp" function for the test class and that seems to do the trick.
Btw, I see tracebacks in the console when a page has errors while
running tests, don't you? Maybe that's a feature of django-nose, which I
am using, I don't know.

On Tuesday, January 29, 2013 2:39:58 AM UTC-6, Alessandro Pelliciari
wrote:
> When i run my selenium tests (LiveServerTestCase type) and i have some
> error in my code (not in the test, i mean in the code executed, like
> the homepage view i reach with selenium) i get the 500 public template
> (that usually i get when i have DEBUG = False) even if i have:
> 
> DEBUG = True 
> INTERNAL_IPS = ('127.0.0.1',)
> 
> 
> I'm stuck with that and i can't see why my test failed (because in the
> public 500 ofc i don't show the exceptions).
> 


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I get the integer of a decimal string?

2013-02-09 Thread Brad
Convert it to float first:
int(float("14.00"))

On Sat, 2013-02-09 at 09:27 -0800, frocco wrote:
> Hello,
> 
> 
> I am reading a cdv file and one col has the value of "14.00"
> I want to get the integer value if 14
> I tried int("14.00")
> 
> 
> Thanks in advance
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why i can't get the debug informations (in case of error) when i run LiveServerTestCase tests?

2013-02-09 Thread Brad Pitcher
Have you tried adding a:
import pdb; pdb.set_trace()
in the view to debug that way?
On Jan 30, 2013 12:31 AM, "Alessandro Pelliciari" 
wrote:

> Thanks for the answer!
>
> Because i'm developing and integrating some flow (social registration etc)
> through tests.
>
> So, instead of creating every time a new user, creating a new social
> association, and then after every try delete them from the database, the
> test does it from me.
>
> So, its like a kind of dirty TDD with functional (selenium because i have
> facebook login for example) testing.
>
>
> Anyway i think i can resolve with the 500 response logging the error to
> the console, but it's my first project in Django (and python) so i can't
> understand completely the way to logging at this moment.
>
>
> Alessandro
>
>
> Il giorno mercoledì 30 gennaio 2013 03:18:46 UTC+1, Ramiro Morales ha
> scritto:
>>
>> Ramiro Morales
>> On Jan 29, 2013 12:33 PM, "Alessandro Pelliciari" 
>> wrote:
>> >
>> > thanks for the link!
>> >
>> > So Isn't there a way to set DEBUG=True in tests?
>>
>> No. There isn't (at least with the built-in testing toolbox).
>>
>> Now, I'm trying to understand why do you rely in the debugging 500
>> response contents on your tests. Do you screen scrap it to extract
>> information about the origin of the failure?
>>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: No module named models again

2013-02-06 Thread Brad
On Wed, 2013-02-06 at 11:49 -0800, frocco wrote:
> Line 22 does not make any sense to me as to why it is failing.
> If I remove receipt, it runs fine

It can be surprising sometimes what code can cause other code to get
imported and run. My guess is, in trying to find your url route there,
Django looks through ntw.urls. When it sees 'receipts' it imports
ntw.checkout.views to see if that view is there. Suffice it to say,
Django is trying to run the code in ntw\checkout\views.py and it would
be a good idea to make it work.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: No module named models again

2013-02-06 Thread Brad
On Wed, 2013-02-06 at 10:31 -0800, frocco wrote:
> Exception Location:C:\ndsutil\Menus\CTD-NDSUser\PycharmProjects\ntw
> \checkout\views.py in , line 5

Django gives you the line in the file where the error occurs so you
don't need to track it down ;-)
It's probably failing when you try to import something in views.py.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Help - No module named models

2013-02-04 Thread Brad Pitcher
On Sun, 2013-02-03 at 10:04 -0800, frocco wrote:
> from catalog.models import Category

It is probably this line. Maybe there is no __init__.py file in the
catalog directory?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: newbie needs to copy a record in admin to a new record

2013-01-11 Thread Brad Pitcher
I think what should work well for your use case is an admin action:

https://docs.djangoproject.com/en/1.4/ref/contrib/admin/actions/

You can write code for a copy action in admin.py. This will add a "copy"
item to the dropdown in the list view, so you can select any number of list
items and copy them.

-
Brad Pitcher
Software Developer
(702)723-8255


On Fri, Jan 11, 2013 at 7:06 AM, frocco <faro...@gmail.com> wrote:

> Hello,
>
> I am just learning django and want to allow a user in admin to copy a
> record from the list to create a new record and make changes.
> This will prevent having to type similar data.
>
> How do I add a link to the admin list?
> where do I put code to dup the record?
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/odBD_lyCqmsJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Email notifications app

2012-11-23 Thread Brad Pitcher
Checkout django drip:
https://github.com/zapier/django-drip
On Nov 23, 2012 7:22 AM, "Arnaud BRETON"  wrote:

> Hi everybody,
>
> I'm looking for a powerful third-app for Django to manage time-driven
> email notifications.
>
> I found django-notifications (
> https://github.com/jtauber/django-notification) but it seems not
> maintained anymore..
>
> Thanks !
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/UeHxWh5cp4kJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: selenium test for fallback page loaded from app cache when server is unavailable

2012-11-03 Thread Brad Pitcher
Are you having the selenium test go to online.html first like in your
manual test?
Maybe you need to have selenium hit offline.html first and cache that page?
On Nov 3, 2012 6:14 AM, "Joao Coelho"  wrote:

> Hi. I haven't been able to figure this one out. Trying to write an
> automated test that uses selenium.webdriver.firefox.webdriver
>
> The manifest file has
> FALLBACK:
> /online.html /offline.html
>
> So that at /online.html the browser displays the cached copy of
> /offline.html when the server is offline
>
> Also, to simulate server unavailable for testing
> /online.html returns a 200 response
> /online.html?offline=1 returns 503
>
> This all works fine when I browse manually
> /online.html displays "I am online"
> /online.html?offline=1 displays "I am a cached page"
>
> I want the selenium test to get /online.html?offline=1 and see "I am a
> cached page" /offline.html
> But it's only showing a blank page
> I think it's stopping at the 503 and not loading from the app cache
>
> def test_offline(self):
> """Simulate site being offline"""
> self.selenium.get('%s%s' % (self.live_server_url,
> '/online.html?offline=1'))
> self.assertIn('cached page', self.selenium.page_source)
>
> How can I make it test this? Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/YrAnOOsSaKAJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to reference model instance fields dynamically

2012-10-26 Thread Brad Pitcher
Use setattr's counterpart, getattr :-)

getattr(inst, k).add(relatedObject)

On Fri, Oct 26, 2012 at 5:16 PM, Chris Pagnutti <chris.pagnu...@gmail.com>wrote:

> Awesome.  Thanks Brad.  Now the question is, what if the attribute is a
> ManyToManyField.
>
> e.g.
> inst.k.add(relatedObject)
>
> How to reference k properly if k is a string containing the name of a
> ManyToManyField of inst?
>
>
> On Friday, October 26, 2012 11:37:36 AM UTC-4, Chris Pagnutti wrote:
>>
>> Say I have a model like
>> class MyModel(models.Model)
>>name = models.CharField(max_length=**100)
>>number = models.IntegerField()
>>
>> In a script, I want to have something like
>> fields = {"name":"Joe", "number":5}
>>
>> And I want to update a MyModel instance using the fields dictionary,
>> something like this
>> inst = MyModel.objects.get(pk=2)
>> for k,v in fields.iteritems():
>>inst.k = v   # I tried with inst.F(k) = v and inst.eval(k) = v but
>> python doesn't like that either
>>
>> I hope I'm being clear in what I'm trying to do.  The reason I have to do
>> it this way is that I don't know which model, and therefore fields, I'm
>> dealing with until run-time.
>> Please ask questions if this isn't clear.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Rvpb5l-sbaQJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to reference model instance fields dynamically

2012-10-26 Thread Brad Pitcher
You can use python's setattr function to do this:

for k,v in fields.iteritems():
setattr(inst, k, v)

On Fri, Oct 26, 2012 at 8:37 AM, Chris Pagnutti wrote:

> Say I have a model like
> class MyModel(models.Model)
>name = models.CharField(max_length=100)
>number = models.IntegerField()
>
> In a script, I want to have something like
> fields = {"name":"Joe", "number":5}
>
> And I want to update a MyModel instance using the fields dictionary,
> something like this
> inst = MyModel.objects.get(pk=2)
> for k,v in fields.iteritems():
>inst.k = v   # I tried with inst.F(k) = v and inst.eval(k) = v but
> python doesn't like that either
>
> I hope I'm being clear in what I'm trying to do.  The reason I have to do
> it this way is that I don't know which model, and therefore fields, I'm
> dealing with until run-time.
> Please ask questions if this isn't clear.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/4ZtEPAjlksQJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Best way to detect if a user has changed password

2012-10-24 Thread Brad Pitcher
You could use a "pre_save" signal. kwargs['instance'] will contain the
updated record and you can get the old record with "User.objects.get(id=
user.id) if user.pk else None". I've done this in the past to check for a
changed email address.

On Wed, Oct 24, 2012 at 2:23 PM, Roarster  wrote:

> I'm running a Django 1.4 site and I have some operations I want to perform
> if a user changes their password.  I'm using the standard contrib.auth user
> accounts with the normal password_change view and I'm not sure if I should
> somehow hook into this view or if I should use a signal on post_save for
> the user.  If I do use the signal, is it possible to tell when the password
> has been changed?  I do feel that if I can use a signal this might be the
> best approach since it would handle any other password change mechanisms
> that I might add later without any extra work.
>
> Does anyone have any ideas on the best way to do this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/yrhcGbYf0f4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: static files

2012-10-11 Thread Brad Pitcher
I believe the best way of doing this is to have your image(s) in
static/images and your css in static/css.  Then you can use a relative URL
to set the background image like so:

background-image : url("../images/PAE.jpg")

It's better not to have any CSS mixed in with your HTML anyway.
On Oct 11, 2012 7:49 AM, "luca72"  wrote:

> hello my project is lacated here:
>
> /home/
>   /luca72
> /Scrivania
>   /Quintas_Disegno_definitivo
> /quintas/ here i have the file manage.py ,
>
> than i have the file settings,py here:
> /home
>/luca72
>   /Scrivania
>  /Quintas_Disegno_definitivo
> /quintas
>/quintas, here i have add a folder "static" with and image
> called PAE.jpg.
>
> How i have to configure the file setting.py in a way that in my template
> when i write via CSS background-image : url("PAE.jpg") the image is load
>
> I have try a lot of thing but i get that the image is not found.
>
> I use apache in localhost.
>
> Thaks
>
> Luca
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/VXS19g9Ie7MJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Possible spam from mailing list? ("China Mobile")

2012-09-10 Thread Brad Pitcher
Yes, I received a similar email about the post "Re: I can't install django
on my mac. I'm not sure wh..." which I recently responded to. Not sure what
to make of it.

On Mon, Sep 10, 2012 at 12:27 PM, Kurtis  wrote:

> I just received a very unusual e-mail that included a recent post's
> subject. The post in question was: "Re: form doesn't validate when trying
> to upload file". It was sent directly to my email address; by-passing the
> User Group.
>
> Google roughly translated this email as coming from "China Mobile" and
> included the domain "139.com". Has anyone else seen this sort of thing?
> Unfortunately, I am unable to read the language and the Google Translation
> isn't very clear; but it's definitely displayed using a very clean and
> fancy template. I'm not sure if it's spam or something else.
>
> Just figured I'd see if anyone else has gotten an email similar to this.
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/cs6UrXOcBOkJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I can't install django on my mac. I'm not sure why. Details inside.

2012-09-09 Thread Brad Pitcher
Glad to here you got it working, and please let us know if you have any
other questions.


On Sun, Sep 9, 2012 at 5:52 PM, Shayan Afridi wrote:

> It works! Thank you all so much. It feels great to know that there is a
> very responsive and helpful support system for django users. Thanks again!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I can't install django on my mac. I'm not sure why. Details inside.

2012-09-09 Thread Brad Pitcher
I can't speak authoritatively on this, since that's not how it installs in
Linux, but in my understanding the contents of the django.pth file should
be the directory django has been installed to. Check the contents of that
file to see if everything is in order.
An alternative to this is to update PYTHONPATH to point to the folder
django is installed to. A quick test on Mac OSX would look like:
PYTHONPATH=/location/of/django python -c "import django;
print(django.get_version())"
and you could make it more permanent by adding
PYTHONPATH=/location/of/django to your ~/.profile
In windows, you may need to look at your environment variable settings.

On Sun, Sep 9, 2012 at 3:53 PM, Shayan Afridi wrote:

> There is a django.pth there and a README
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I can't install django on my mac. I'm not sure why. Details inside.

2012-09-09 Thread Brad Pitcher
The question is, is django inside one of those directories? It should
probably be installed to C:\Python27\lib\site-packages so there would be a
C:\Python27\lib\site-packages\django directory. Is it there?

On Sun, Sep 9, 2012 at 3:41 PM, Shayan Afridi wrote:

> Interesting. I'm doing it on my PC now, and still getting the same problem.
>
> Then I saw your email:
>
> Here's what I get when I print sys.path. (django's not there)
>
> >>> print sys.path
> ['', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs',
> 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C
> :\\Python27\\lib\\lib-tk', 'C:\\Python27',
> 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages']
>
> the ln line doesn't work for me
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: bar charts

2011-11-07 Thread Brad Montgomery
+1 for Google Charts.


For small stuff (1 chart), I just render JavaScript in the  of my 
html templates. For more complex stuff, you could write a view that *just* 
renders JavaScript and include it via a script tag. Just make sure to serve 
it with MIME type "application/javascript"


Here's more info on generating Non-HTML content:
http://djangobook.com/en/2.0/chapter13/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/M_rJLephha4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django hosting

2011-07-25 Thread Brad Montgomery
I've been using rackspace's Cloud servers.  They give you a nice platform 
and charge only for what you use (so low-traffic sites end up being very 
affordable). 

However, you should play close attention to a service 
like https://gondor.io/ - it's an extremely easy-to-use service that makes 
hosting django projects almost trivial.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ycS1BKP7FJIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: [ask for help] how to solve this issue: "DatabaseError at /admin/myapp, no such column: myapp.myvar"

2011-05-21 Thread brad
It sounds like you may have created your Models, run "mange.py syncdb", then 
added another field to your Model.

Remember, syncdb doesn't add new columns in your table when you add a new 
field to an existing model.  If this app is still in development, you can 
drop the whole table corresponding to that model and run syncdb again.

You should also consider looking at south (http://south.aeracode.org/). It 
provides migration tools that let you add columns to existing models via a 
managment command.

- Brad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: cx_Oracle error: ImproperlyConfigured

2011-04-21 Thread brad
This may be related to Oracle's shared libraries not being in the path 
recognized by your web server. I created hard links to the Oracle shared 
libraries in /user/local/lib to get cx_oracle working.

I have a blog post that outlines what I did, here:
http://bradmontgomery.net/blog/gahhh-django-virtualenv-and-cx_oracle/

The comment by Graham Dumpleton is worth reading, as he mentions a few other 
techniques to make this work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Donations App

2011-02-25 Thread Brad Reardon
Heya django-users,

I have been working on a website for a client, and they are in need of
an app that is for donations. Being no PayPal IPN-processing expert, I
unfortunately do not know how to program an app that would display the
names and amounts of the donations received. I have checked out django-
donation, found on Launchpad, but it doesn't seem to perform the way I
would like.

If you would, could you guys provide me with a link to an app that
does the functions I require? If not, documentation on the PayPal API
would be nice, so that I could process the requests.

One more thing; instead of the name of the person that had donated
that PayPal provides, I would like for them to be able to input an
alias.

Thanks!
Brad Reardon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: default_if_none as settings (??)

2010-12-13 Thread Brad Reardon
If I understand correctly, then the solution would be to do something of
this sort: (pardon the formatting)

if value:
{{value}}
else:
{{default_value}}

Something of that sort *should* work, although I am not entirely sure.

On Mon, Dec 13, 2010 at 4:00 AM, PyMan  wrote:

> Maybe I'm wrong but I remember about a setting whose I don't remember
> the name...acting like a default for default_if_none where
> default_if_none was not used.
>
> Example:
> {{ value }}  <-- I forgot about using the "default_if_none" filter
>
> If the setting I'm talking about is defined then its value is used
> instead of "None" as string, if value is None.
>
> I haven't found any information about that setting in the current
> documentation. If I really used that setting in the past, it was in
> the 0.95/0.96 version.
>
> Thank you for your help.
>
> P.S. If the setting doesn't exist, how can I achive the same result
> without using "default_if_none" everywhere?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-admin.py startproject not working

2010-12-12 Thread Brad Reardon
Another tip is to add *.py to the PATHEXT variable or the like. That will allow 
the script to be found on the path. I'm not sure if that's the right variable 
name, but check it out. 

On Dec 12, 2010, at 10:13 PM, codegal <nosmalldre...@gmail.com> wrote:

> Thanks.  Good pointer for running python scripts in the future - will
> follow as a matter of practice.
> 
> As it turned out in this case, I just wasn't providing the full path.
> I had set up a .pth file, and had tried copying django-admin.py into
> the main Python directory, but it turned out that directory is not
> assumed, and neither the PYTHONPATH nor the environmental variables
> path gets checked when Python runs the command, so this (full path to
> django-admin.py) is what finally worked for me:
> 
> python C:/Python27/Scripts/django-admin.py startproject mysite
> 
> 
> On Dec 12, 8:06 pm, Brad Reardon <bradsq...@gmail.com> wrote:
>> Vista is very picky about permissions. Try running the command prompt as an
>> administrator.
>> 
>> 
>> 
>> On Sun, Dec 12, 2010 at 8:06 PM, codegal <nosmalldre...@gmail.com> wrote:
>>> I'm trying to create my first Django project, and I must be missing
>>> something really basic. I'm using Windows Vista, and have installed
>>> Python 2.7 and Django 1.2.3, put the location of django-admin.py into
>>> my PATH variable, and navigated via command line to the location where
>>> I want to create a project. I'm entering:
>> 
>>> django-admin.py startproject cms
>> 
>>> at the command line. I don't get an error, but I also don't get any
>>> processing back - just a new prompt, and no project created in the
>>> directory. Can't find any posts on the web regarding this issue...
>> 
>>> Thanks!
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google­groups.com>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>> 
>> - Show quoted text -
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-admin.py startproject not working

2010-12-12 Thread Brad Reardon
Vista is very picky about permissions. Try running the command prompt as an
administrator.

On Sun, Dec 12, 2010 at 8:06 PM, codegal  wrote:

> I'm trying to create my first Django project, and I must be missing
> something really basic. I'm using Windows Vista, and have installed
> Python 2.7 and Django 1.2.3, put the location of django-admin.py into
> my PATH variable, and navigated via command line to the location where
> I want to create a project. I'm entering:
>
> django-admin.py startproject cms
>
> at the command line. I don't get an error, but I also don't get any
> processing back - just a new prompt, and no project created in the
> directory. Can't find any posts on the web regarding this issue...
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Updating a video rating using AJAX

2010-10-20 Thread brad
Also, if you DO choose to pass JSON back to your client, you should
serialize it first.  See this:

http://docs.djangoproject.com/en/dev/topics/serialization/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Updating a video rating using AJAX

2010-10-20 Thread brad

> I would like to do this without using a view or doing a form POST or GET of
> any kind. Any pointers?

Why?  If you're building a web app, you should use HTTP to for the
client to communicate with the app (AJAX is just another form of that
communication).

You're almost there, though, because your function is pretty close to
a view:

def save_rating(request, video_id, rating):
if request.is_ajax():
# the rest of your code...

json_content = '{"rating":"%s"}' % video.rating
return HttpResponse(json_content, mimetype='application/json')

Just be sure to return some sort of data that your client-side
javascript can interpret, such as JSON (of which I've given you an
untested example).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: problem reversing namespaced URL (application instance not recognized?)

2010-10-17 Thread Brad Buran
Problem solved.  I misunderstood the Django docs on URL namespacing and was
trying to take a shortcut by passing a 3-tuple rather than explicitly naming
the arguments to include.  Instead of include('test.wiki.urls', 'wiki',
'help') I should have been doing include('test.wiki.urls', app_name='wiki',
namespace='help').

Sorry for the trouble,
Brad

On Sun, Oct 17, 2010 at 6:14 PM, Brad Buran <bbu...@alum.mit.edu> wrote:

> I'm trying to reuse a wiki app twice in my project; however, whenever I
> call the reverse function, it returns the URL of the first instance defined
> in my urls.conf.  I have attempted specifying the view name as
> app_instance:view_name, app_name:view_name as well as using the current_app
> keyword of the reverse function.  I have not had any luck so far and was
> hoping for suggestions on what I'm doing wrong.  I've only posted the
> relevant parts of the code.
>
> Per the Django documentation on namespacing, I have set up my top-level
> URLs conf as:
>
> ...
> (r'help/', include('test.wiki.urls', 'wiki', 'help'), {'wiki': 'help'}),
> (r'learn/wiki/', include('test.wiki.urls', 'wiki', 'learn'), {'wiki':
> 'learn'}),
> ...
>
> In my wiki app, the urls.conf has
>
> url(r'^(?P[-\w]+)/$', 'test.wiki.views.display',
> name='wiki_page_detail'),
> url(r'^(?P[-\w]+)/404$', direct_to_template, {'template':
> 'wiki/page_404.html'}, name='wiki_page_404')
>
> Finally, in my display view function (note that this uses the wiki keyword
> defined in the top-level urls.conf to know which :
>
> def display(request, wiki, slug):
> try:
> wiki = models.Wiki.objects.get_or_create(wiki)
> page = models.Page.objects.get(wiki=wiki, slug=slug)
> except models.Page.DoesNotExist:
> url = reverse('%s:wiki_page_404' % wiki.title, kwargs={'slug':
> slug}, current_app=wiki.title)
> return HttpResponseRedirect(url)
>
>
> Thanks,
> Brad
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



problem reversing namespaced URL (application instance not recognized?)

2010-10-17 Thread Brad Buran
I'm trying to reuse a wiki app twice in my project; however, whenever I call
the reverse function, it returns the URL of the first instance defined in my
urls.conf.  I have attempted specifying the view name as
app_instance:view_name, app_name:view_name as well as using the current_app
keyword of the reverse function.  I have not had any luck so far and was
hoping for suggestions on what I'm doing wrong.  I've only posted the
relevant parts of the code.

Per the Django documentation on namespacing, I have set up my top-level URLs
conf as:

...
(r'help/', include('test.wiki.urls', 'wiki', 'help'), {'wiki': 'help'}),
(r'learn/wiki/', include('test.wiki.urls', 'wiki', 'learn'), {'wiki':
'learn'}),
...

In my wiki app, the urls.conf has

url(r'^(?P[-\w]+)/$', 'test.wiki.views.display',
name='wiki_page_detail'),
url(r'^(?P[-\w]+)/404$', direct_to_template, {'template':
'wiki/page_404.html'}, name='wiki_page_404')

Finally, in my display view function (note that this uses the wiki keyword
defined in the top-level urls.conf to know which :

def display(request, wiki, slug):
try:
wiki = models.Wiki.objects.get_or_create(wiki)
page = models.Page.objects.get(wiki=wiki, slug=slug)
except models.Page.DoesNotExist:
url = reverse('%s:wiki_page_404' % wiki.title, kwargs={'slug':
slug}, current_app=wiki.title)
return HttpResponseRedirect(url)


Thanks,
Brad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Sorting related model

2010-09-11 Thread Brad Buran
Given the following two models forming the base of a wiki-style app:

class Page(models.Model):
current_revision = models.IntegerField()

class PageContent(models.Model):
page = models.ForeignKey(Page)
revision = models.IntegerField()
created = models.DateTimeField()

Here, we have a canonical Page object with a current_revision that always
points to the most current revision, stored in PageContent.  How can I
construct a Page queryset, ordered by the Pages that have the most
recently-created PageContent?

Currently, what I am doing is:

qs =
PageContent.objects.filter(revision=F('page__current_revision')).order_by('created').select_related()
pages = [content.page for content in qs]

This works fine, but is there a more straightforward way to do this?

Thanks,
Brad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: best practice for widget that edits multiple model fields

2010-07-21 Thread Brad Buran
<<Sorry, last post was incomplete.  Accidentally hit send while composing.>>

Hi Scott:

Thank you for the suggestion.  I reviewed the docs, and it appears like it
could work but would restrict the functionality.  For example, I would have
to somehow serialize two datetime types plus a boolean type into a single
database column.  This would take away a lot of advantages (such as being
able to filter based on only one of the datetimes).

One other option I am exploring is simply doing:

class DateRange(Model):
start = DateTimeField()
end = DateTimeField()
all_day = BooleanField()

# subclass DateRange so we can reuse it in various models
class EventDateRange(DateRange):
date = ForeignKey(Event)

class Event(Model):
#various other fields required for event

Does this seem like it would make more sense?

Thanks,
Brad


On Wed, Jul 21, 2010 at 8:03 AM, Scott Gould <zinck...@gmail.com> wrote:

> My immediate thought upon reading your post was that you should build
> an accompanying custom model field. Having said that, I haven't had
> cause to do one that involved (only extend -- simply -- the stock
> fields) so can't provide any specifics.
>
>
> http://docs.djangoproject.com/en/1.2/howto/custom-model-fields/#howto-custom-model-fields
>
> On Jul 20, 10:00 pm, Brad Buran <bbu...@alum.mit.edu> wrote:
> > I have a group of fields (date_start, date_end, all_day) that I would
> like
> > to reuse in several models.  I've defined a MultiWidget that displays two
> > split datetime fields plus a checkbox (for the all_day toggle).  However,
> > I'm not sure how to get the MultiWidget to set the value of these three
> > fields in the model.  If I understand correctly, a MultiWidget can only
> set
> > the value of a single model field.  Hence, I would need to create some
> sort
> > of field (e.g. "combined_date_info") that MultiWidget saves the
> serialized
> > data from these three form fields.  Once I have done this, then I would
> use
> > model.save() to deserialize the data in the combined_date_info field and
> > save it to the appropriate model fields.
> >
> > This solution seems a bit hackish and not very DRY.  Are there better
> > approaches?
> >
> > Brad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: best practice for widget that edits multiple model fields

2010-07-21 Thread Brad Buran
Hi Scott:

Thank you for the suggestion.  I reviewed the docs, and it appears like it
could work but would restrict the functionality.  For example, I would have
to somehow serialize two datetime types plus a boolean type into a single
database column.  This would take away a lot of advantages (such as being
able to filter based on only one of the datetimes).

One other option I am exploring is simply doing:

class DateRange(Model):
start = DateTimeField()
end = DateTimeField()



On Wed, Jul 21, 2010 at 8:03 AM, Scott Gould <zinck...@gmail.com> wrote:

> My immediate thought upon reading your post was that you should build
> an accompanying custom model field. Having said that, I haven't had
> cause to do one that involved (only extend -- simply -- the stock
> fields) so can't provide any specifics.
>
>
> http://docs.djangoproject.com/en/1.2/howto/custom-model-fields/#howto-custom-model-fields
>
> On Jul 20, 10:00 pm, Brad Buran <bbu...@alum.mit.edu> wrote:
> > I have a group of fields (date_start, date_end, all_day) that I would
> like
> > to reuse in several models.  I've defined a MultiWidget that displays two
> > split datetime fields plus a checkbox (for the all_day toggle).  However,
> > I'm not sure how to get the MultiWidget to set the value of these three
> > fields in the model.  If I understand correctly, a MultiWidget can only
> set
> > the value of a single model field.  Hence, I would need to create some
> sort
> > of field (e.g. "combined_date_info") that MultiWidget saves the
> serialized
> > data from these three form fields.  Once I have done this, then I would
> use
> > model.save() to deserialize the data in the combined_date_info field and
> > save it to the appropriate model fields.
> >
> > This solution seems a bit hackish and not very DRY.  Are there better
> > approaches?
> >
> > Brad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



best practice for widget that edits multiple model fields

2010-07-20 Thread Brad Buran
I have a group of fields (date_start, date_end, all_day) that I would like
to reuse in several models.  I've defined a MultiWidget that displays two
split datetime fields plus a checkbox (for the all_day toggle).  However,
I'm not sure how to get the MultiWidget to set the value of these three
fields in the model.  If I understand correctly, a MultiWidget can only set
the value of a single model field.  Hence, I would need to create some sort
of field (e.g. "combined_date_info") that MultiWidget saves the serialized
data from these three form fields.  Once I have done this, then I would use
model.save() to deserialize the data in the combined_date_info field and
save it to the appropriate model fields.

This solution seems a bit hackish and not very DRY.  Are there better
approaches?

Brad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: File Upload with Progress Bar

2010-06-03 Thread Brad Pitcher
Some versions of flash have a bug that causes the entire browser to
freeze while uploading.  I am afflicted by the bug, running Flash 10.0
r45 on Ubuntu 10.04.  It seems that there is no good solution at the
moment.  My host is Webfaction and I just discovered that they have a
non-configurable nginx server in front of everything that caches
uploads before sending them on to apache/django making it impossible
to do upload progress bars at the moment.  They are aware of the
problem, but who knows when it will be fixed.

On Jun 3, 8:31 am, Venkatraman S <venka...@gmail.com> wrote:
> Oh yes! I was referring to a stand alone app. I heard someone complain
> #django that filebrowser aint working right after uploadify was introduced.
> Is that True?
>
> On Thu, Jun 3, 2010 at 8:11 PM, patrickk <sehmasch...@gmail.com> wrote:
> >http://code.google.com/p/django-filebrowser/
>
> > cheers,
> > patrick
>
> > On 3 Jun., 16:10, Venkatraman S <venka...@gmail.com> wrote:
> > > Hi Patrick,
>
> > > Can you share a simple django app which uses Uploadify?  Did you use
> > vanilla
> > > Uploadify or 
> > > django-uploadify(github.com/tstone/django-uploadify*)*<http://github.com/tstone/django-uploadify*%29*>
> > ?
> > > I have been simply unable to make it run.  I also tried a
> > django-uploadify,
> > > but no results! Frustrating it is.
>
> > > If you can share the code, i would rather use it along with some other
> > > experiments that I have been doing and publish it in the public domain.
>
> > > Regards.
>
> > > On Thu, Jun 3, 2010 at 5:39 PM, patrickk <sehmasch...@gmail.com> wrote:
> > > > you could use uploadify, seehttp://www.uploadify.com/.
>
> > > > of course, it´s not an ideal solution since its flash-based.
> > > > we´ve been using uploadify with django and the filebrowser for about a
> > > > year now and it works quite well.
>
> > > > regards,
> > > > patrick
>
> > > > On 3 Jun., 06:32, Venkatraman S <venka...@gmail.com> wrote:
> > > > > Tell me about it! Its quite insane that there is no single-standard
> > > > solution
> > > > > for this.
> > > > > I have been hanging around in #django for sometime and there is still
> > > > > opposition to flash based solution. Also, i have not been to get it
> > > > working
> > > > > inspite of it being not an ideal solution.
> > > > > I hear that there are some issues with filebrowser since it uses
> > > > Uploadify.
> > > > > Also, i dont see any solution which works in both dev server and also
> > in
> > > > the
> > > > > production using httpd/apache.
>
> > > > > Going insane! Let me know if you get anything working.
>
> > > > > PS: As i said, html5 is cool and works, but the client does not want
> > to
> > > > use
> > > > > it!
>
> > > > > -V-http://twitter.com/venkasub
>
> > > > > On Thu, Jun 3, 2010 at 9:54 AM, Brad Pitcher <bradpitc...@gmail.com>
> > > > wrote:
> > > > > > Sort of, that's what the default is in the demo, but now I've
> > noticed I
> > > > > > have the same problem with apache progress reporting as I did using
> > > > django
> > > > > > progress reporting.  It's behaving like it's not multi-threaded or
> > > > > > something.  It seems like I don't get any progress reports until
> > the
> > > > file
> > > > > > has finished uploading.  It's actually driving me a bit crazy so
> > I'm
> > > > going
> > > > > > to have to move on to something else for a while.
>
> > > > > > On Wed, Jun 2, 2010 at 9:16 PM, Venkatraman S <venka...@gmail.com>
> > > > wrote:
>
> > > > > >> Does this work with the Django development server?
>
> > > > > >> On Thu, Jun 3, 2010 at 8:13 AM, Brad Pitcher <
> > bradpitc...@gmail.com
> > > > >wrote:
>
> > > > > >>> Since I just spent much longer than it should have taken figuring
> > > > this
> > > > > >>> out, I will try and help you out.  I followed the instructions at
> > the
> > > > > >>> provided link and it sort of worked.  Not quite as well as I
> > liked.
> > > >  I
> > > > > >>> used Apache for the progress reporting, which the author doesn

Re: File Upload with Progress Bar

2010-06-03 Thread Brad Pitcher
Whoops!  Just read that the django dev server is not multithreaded so
it will not work.  But you should be able to use any web server along
with an upload_progress view as long as your web server streams the
upload in progress to django.  I think my troubles may be because the
web server isn't streaming the file upload to django, I'm currently
investigating that.

On Jun 2, 9:24 pm, Brad Pitcher <bradpitc...@gmail.com> wrote:
> Sort of, that's what the default is in the demo, but now I've noticed I have
> the same problem with apache progress reporting as I did using django
> progress reporting.  It's behaving like it's not multi-threaded or
> something.  It seems like I don't get any progress reports until the file
> has finished uploading.  It's actually driving me a bit crazy so I'm going
> to have to move on to something else for a while.
>
> On Wed, Jun 2, 2010 at 9:16 PM, Venkatraman S <venka...@gmail.com> wrote:
> > Does this work with the Django development server?
>
> > On Thu, Jun 3, 2010 at 8:13 AM, Brad Pitcher <bradpitc...@gmail.com>wrote:
>
> >> Since I just spent much longer than it should have taken figuring this
> >> out, I will try and help you out.  I followed the instructions at the
> >> provided link and it sort of worked.  Not quite as well as I liked.  I
> >> used Apache for the progress reporting, which the author doesn't
> >> mention in the article but it is discussed here:
>
> >>http://piotrsarnacki.com/2008/06/18/upload-progress-bar-with-mod_pass...
> >> (it involves compiling and installing an apache module).
> >> The author also doesn't mention changes needed in settings.py:
> >> from django.conf import global_settings
>
> >> FILE_UPLOAD_HANDLERS = ('path.to.UploadProgressCachedHandler', ) +
> >> \    <-- change path here
> >>    global_settings.FILE_UPLOAD_HANDLERS
>
> >> If you are using nginx or apache for the server side instead of
> >> django, you will need to modify progressUrl to point to whatever url
> >> you set up for accessing progress reports.
>
> >> If you are looking for a demo, there is one linked in the article
> >> creecode posted.
> >> -Brad
>
> >> On May 30, 12:23 pm, Venkatraman S <venka...@gmail.com> wrote:
> >> > HI creecode,
>
> >> > Can you share the project please? I can probably work on it and see what
> >> is
> >> > happening.
> >> > Till now, i havent even been able to get this working.
>
> >> > -V
>
> >> > On Sun, May 30, 2010 at 10:45 PM, creecode <creec...@gmail.com> wrote:
> >> > > Hello V,
>
> >> > > On May 29, 11:00 pm, Venkatraman S <venka...@gmail.com> wrote:
>
> >> > > > I have been trying to build a simple file upload with progress bar.
>
> >> > > AFAIK there isn't a simple solution.  Perhaps this info <
>
> >> > >http://www.fairviewcomputing.com/blog/2008/10/21/ajax-upload-progress.
> >> ..
> >> > > > will point you in the right direction.
>
> >> > > I've experimented with a solution based tthe above but I wasn't
> >> > > entirely satisfied with my implementation.  I'm having a problem with
> >> > > the progress bar not reaching 100% many times and some problems with
> >> > > the percentage complete number.
>
> >> > > I've put my project on the back burner for now but if anyone has any
> >> > > examples they'd like to share I'd be interested in seeing them.
>
> >> > > Toodle-looo...
> >> > > creecode
>
> >> > > --
> >> > > You received this message because you are subscribed to the Google
> >> Groups
> >> > > "Django users" group.
> >> > > To post to this group, send email to django-us...@googlegroups.com.
> >> > > To unsubscribe from this group, send email to
> >> > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> >> <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@googlegroups.com>
>
> >> > > .
> >> > > For more options, visit this group at
> >> > >http://groups.google.com/group/django-users?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group

  1   2   >