Re: How to hide the "save and add another" button in admin page?

2014-01-19 Thread parnigot

Il 19/01/14 02:38, RLF_UNIQUE ha scritto:
I have been trying all day. What I am doing is trying to have a model 
for an "about" page, which I want to limit to 1 item. It doesn't 
really make sense to have multiple "abouts". I've done everything 
described here


http://stackoverflow.com/questions/13101281/in-django-admin-how-can-i-hide-save-and-continue-and-save-and-add-another-butto

but can't get it to work, it works if in the ctx update I set 
show_save_and_add_another to false, but then the "save and add 
another" button doesn't show up for any model.


Please help.
You should override in your ModelAdmin the method has_add_permissions 
(docs here 
).
When it returns False, all the add buttons in the admin will be disabled 
for that particular Model.


--
e.p.

--
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/52DB9BE1.1070009%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Connecting to a MS SQL server from django

2014-01-19 Thread Fred Stluka

Larry,

+1 for Pycharm (JetBrains).

I use their DB tools to explore both MS SQL and MySQL DBs.  If
you like, I can dig up my notes on exactly how I made the
connection from PyCharm to MS SQL Server.

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


On 1/15/14 11:51 AM, Avraham Serour wrote:

pycharm and jetbrains tools come with a db explorer

with a simple google search I found this [0] and [1] which have some 
references, you could also try [2] with wine


[0] http://stackoverflow.com/questions/399505/sql-server-gui-for-linux

[1] 
http://stackoverflow.com/questions/721852/developer-tools-to-directly-access-databases


[2] http://www.microsoft.com/en-us/download/details.aspx?id=8961

good luck


On Wed, Jan 15, 2014 at 6:42 PM, Adnan Sadzak > wrote:


Maybe Your  MSSQL server is listening only on loopback interface.
Telnet from linux box to windows server on port 1433 and check if
port is open.
You can see also this few pages, just depends on Your server version.:

http://blogs.msdn.com/b/sqlblog/archive/2009/07/17/how-to-configure-sql-server-to-listen-on-different-ports-on-different-ip-addresses.aspx

http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx

Check also FreeTDS project: http://www.freetds.org/

Cheers,
Adnan


On Wed, Jan 15, 2014 at 5:19 PM, Larry Martell
mailto:larry.mart...@gmail.com>> wrote:

On Wed, Jan 15, 2014 at 12:09 AM, Avraham Serour
mailto:tovm...@gmail.com>> wrote:
> I would try using some kind of DB explorer first, to make
sure I have the
> ip, port and auth right, once you are able using some other
tool you can
> just use the same settings in your code

Do you know of any such beast for Linux?

> On Wed, Jan 15, 2014 at 6:46 AM, Larry Martell
mailto:larry.mart...@gmail.com>>
> wrote:
>>
>> On Tuesday, January 14, 2014, Mark Moss wrote:
>>>
>>> The default port for MySQL is 3306. Have you tried that one?
>>
>>
>>
>> I'm not trying to connect to MySQL - I'm trying to connect
to Microsoft
>> SQL server.
>>
>> --
>> 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/CACwCsY5qidVz3PcCxnCfSpJx134hL68cicMaZUCmRKRpLJ6%3DWQ%40mail.gmail.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/CAFWa6tKSNGb6PLenqH3h9FHxMpp%3De%2Bv_W686Aq71HnjsGL-%2B%2Bw%40mail.gmail.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/CACwCsY4dstOYsGYZ8coq9CX2883w%2BW35YZrzduz3URieAN%3DELw%40mail.gm

Re: Connecting to a MS SQL server from django

2014-01-19 Thread Fred Stluka

Larry,

We tried django-mssql and gave up.  Much better luck with
django-pyodbc.  We use the avidal version of it, along with pyodbc,
FreeTDS, and unixODBC.  Works perfectly.  If you like, I can dig up
my notes on exactly how we made the connection from Django to
MS SQL Server.

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


On 1/14/14 6:15 PM, Larry Martell wrote:

I am trying to connect to a MS SQL server from django on Linux using
Vernon Cole's django-mssql package
(https://bitbucket.org/vernondcole/django-mssql-ado-merge/src).

When I first tried to connect it failed with:

Exception Type: DatabaseError at /report/CDSEM/EventsTable/
Exception Value: Cannot create connection
to=PYRO:ado.connect...@xx.xx.xx.xx:9099

I traced it through
/usr/lib/python2.6/site-packages/adodbapi/remote.py and I see it tries
to access os.environ['PROXY_PORT'], which is not defined and then it
defaults to 9099 - Is that the correct port or should I set
os.environ['PROXY_PORT']? How can I tell what port MS SQL db is
listening on? I googled this and it said the default MS SQL port is
1433. I set os.environ['PROXY_PORT'] to that and now I don't get that
error but it times out:


/usr/lib/python2.6/site-packages/Pyro4-4.22-py2.6.egg/Pyro4/core.py(160)__call__()

->  return self.__send(self.__name, args, kwargs)
(Pdb) n
TimeoutError: TimeoutE...imeout',)

I tried opening port 1433 with iptables, but still no joy.

I can connect to the MS SQL db locally from the host it's running so I
know it's up and my credentials are correct, and I can ping the
Windows box from the Linux host I am running on, so I know there is
connectivity to it from there.

Anyone here ever get this working? Anyone have any ideas as to what my
problem is or how I can debug this further?

Thanks!
-larry



--
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/52DBDAAD.7040202%40bristle.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to hide the "save and add another" button in admin page?

2014-01-19 Thread RLF_UNIQUE
Ah I see, give a user change permission but not add or remove? Then just use 
superaccount to make initial entry?

-- 
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/f2b936f2-7107-4dad-bd3a-364cae68cb37%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Django ModelForm individual fields not validated when overriding clean() on Model

2014-01-19 Thread faph
 

I am using standard Django Models and ModelForms. 

On the Model, I am overriding the clean() method to check that 2 fields in 
combination are valid. I am having validators[], not nulls etc defined on 
other fields.

In the ModelForm, I am not modifying anything. I only set the corresponding 
Model in the ModelForm's Meta class.

When I try to create a new object through the form, the *individual* fields 
in the ModelForm/Model *are not validated* when I call form.is_valid() in 
the View. According to the docs (
https://docs.djangoproject.com/en/1.6/ref/models/instances/#validating-objects) 
the is_valid() method on the Form should call the Model's clean_fields()method 
(first). 

This doesn't seem to work when you submit a form without a Model instance 
(or a new instance not in the db). When I'm editing an existing object, all 
is well. It nicely triggers invalid values in individual fields before 
calling the Model's clean() method.

*When I remove the overridden clean() method from my Model, all is 
well.*Individual fields are validated both when creating new objects and 
editing 
existing ones.

I have also tested this with the admin module's forms. It has exactly the 
same behaviour.

So the question is, why does overriding the clean() method on my Model 
prevent the ModelForm validating the individual fields before calling the 
clean() method to test additional cross-field stuff???

Note that I am not validating the ModelForm. All validation is on the Model 
itself.

Model:

class Survey(models.Model):
from_date = models.DateField(null=False, blank=False, validators=[...])
to_date = models.DateField(null=False, blank=False, validators=[...])
(...)
def clean(self):
errors = []
# At this point I expect self.to_date already to be validated for not 
null etc.
# It isn't for new Model instances, only when editing an existing one
if self.to_date < self.from_date:
errors.append(ValidationError("..."))

ModelForm:

class TestForm(ModelForm):
class Meta:
model = Survey

View (to render blank form for new Model data entry):

(...)if request.method == "POST":
survey_form = TestForm(request.POST)
if '_save' in request.POST:
if survey_form.is_valid():
survey_form.save()
return HttpResponseRedirect(next_url)
else:
return HttpResponseRedirect(next_url)else:
survey_form = TestForm()

context = {'form': survey_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/9242e49b-ce4d-4e51-b063-8331c06acbe9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Connecting to a MS SQL server from django

2014-01-19 Thread Larry Martell
Fred-

This project has been put on the back burner for a few weeks, but I
will be getting back to it. If you could dig up your notes on this,
that would be really great.

Thanks very much!
-larry

On Sun, Jan 19, 2014 at 7:01 AM, Fred Stluka  wrote:
> Larry,
>
> We tried django-mssql and gave up.  Much better luck with
> django-pyodbc.  We use the avidal version of it, along with pyodbc,
> FreeTDS, and unixODBC.  Works perfectly.  If you like, I can dig up
> my notes on exactly how we made the connection from Django to
> MS SQL Server.
>
> --Fred
> 
> Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
> Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
> Open Source: Without walls and fences, we need no Windows or Gates.
> 
>
> On 1/14/14 6:15 PM, Larry Martell wrote:
>
> I am trying to connect to a MS SQL server from django on Linux using
> Vernon Cole's django-mssql package
> (https://bitbucket.org/vernondcole/django-mssql-ado-merge/src).
>
> When I first tried to connect it failed with:
>
> Exception Type: DatabaseError at /report/CDSEM/EventsTable/
> Exception Value: Cannot create connection
> to=PYRO:ado.connect...@xx.xx.xx.xx:9099
>
> I traced it through
> /usr/lib/python2.6/site-packages/adodbapi/remote.py and I see it tries
> to access os.environ['PROXY_PORT'], which is not defined and then it
> defaults to 9099 - Is that the correct port or should I set
> os.environ['PROXY_PORT']? How can I tell what port MS SQL db is
> listening on? I googled this and it said the default MS SQL port is
> 1433. I set os.environ['PROXY_PORT'] to that and now I don't get that
> error but it times out:
>
> /usr/lib/python2.6/site-packages/Pyro4-4.22-py2.6.egg/Pyro4/core.py(160)__call__()
>
> -> return self.__send(self.__name, args, kwargs)
> (Pdb) n
> TimeoutError: TimeoutE...imeout',)
>
> I tried opening port 1433 with iptables, but still no joy.
>
> I can connect to the MS SQL db locally from the host it's running so I
> know it's up and my credentials are correct, and I can ping the
> Windows box from the Linux host I am running on, so I know there is
> connectivity to it from there.
>
> Anyone here ever get this working? Anyone have any ideas as to what my
> problem is or how I can debug this further?
>
> Thanks!
> -larry

-- 
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/CACwCsY46pZJ--KV0wbaGADUpkQBYbhYvusxmQyn8ZyS0PYSqjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


rendering HTML as a select item

2014-01-19 Thread Larry Martell
I am trying to 'fake out' a model form and display data from 2 columns
in one field. I can do this by returning the 2 columns in the model's
__unicode__ method, but I want to apply styling to the data - I want
one column's data left justified and the other column's data right
justified. When I return this in the __unicode__ method:

return mark_safe('%s%s' % (self.name, self.group_by))

The HTML gets stripped out and I end up with just the data, e.g.:

12S target

If I return the markup without the mark_safe, the HTML generated looks
like this:

12S
target
But what is displayed in the select box on the browser is: 12Starget Does anyone know how I can do 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/CACwCsY7uh%2BWruXhaD5h8cxpfzHxGghEpFdxwyAahW%2Ba2qHEfjg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.

Re: Connecting to a MS SQL server from django

2014-01-19 Thread Fred Stluka

Larry,

I did it a long complicated way, but we recently had 2 new people
join our team, and refined the process for them, and it seemed to
go smoothly, so here's what they did.

Some sections differ for Mac vs Linux, and some even for different
Linux distros, but it should all work.  I'm including all of it, even
the part about how to install Python, Django, virtualenv, etc., which
you probably already have, and MySQL, which you are not using so
you can skip.

The following document is in Markdown format.

HHL is the name of our project.  Change it to your own project name.

Let me know how it works!



# Setting up your development environment.

## Install Python 2.7, if it's not already on your system.

### Mac

The Mac comes preinstalled with a 2.7 version of Python. Double-check the
version as shown:

$ /usr/bin/python --version
Python 2.7.5

If you don't get a 2.7 version of Python, or if you get a
"No such file or directory" error, install your own version of Python via
the [Homebrew][] package manager:

$ brew install python

### Linux

If your Linux system doesn't already have a version of Python, install
one with the package manager.

For Ubuntu and Debian:

$ sudo apt-get install python

On CentOS (and, presumably, Fedora and RedHat), see
.

## Install `virtualenv`

Mac:

The version of Python that comes pre-installed on the Mac comes with
`easy_install`, so you can use that to install `virtualenv`:

$ sudo /usr/bin/easy_install virtualenv

Linux:

You can either use your system's package manager (e.g.,
`sudo apt-get install python-virtualenv` on Ubuntu and Debian), or you can
install `virtualenv` manually, as described at
.

## Create and activate a virtual environment

Where you put the environment is up to you; the following is just an
example:

$ virtualenv ~/pythons/hhl

Confirm that you did, indeed, create a Python 2.7 virtual environment:

$ ~/pythons/hhl/bin/python
Python 2.7.5 (default, Nov 19 2013, 10:30:44)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Activate that environment:

$ source ~/pythons/hhl/bin/activate

## Install MySQL

Mac:

Again, it's easiest to use [Homebrew][]:

$ brew install mysql

After installing MySQL, homebrew will display suggestions on how to get 
MySQL

set up. Follow those instructions.

Linux:

You'll need both MySQL and the MySQL development files. Without the latter,
you won't be able to build the MySQL Python driver.

For Ubuntu and Debian:

$ sudo apt-get install mysql-server libmysqlclient-dev

On CentOS (and, presumably, Fedora and RedHat):

$ sudo yum -y install mysql-devel

## Install the Python MySQL driver

$ pip install MySQL-python

## Install non-Python ODBC libraries and tools

### Install unixODBC

Mac:

$ brew install unixodbc

The `odbcinst.ini` file ends up in `/usr/local/etc/`.

Linux:

$ sudo apt-get install unixodbc-dev  # Ubuntu and Debian
$ sudo yum -y install unixODBC-devel # CentOS, RedHat, and Fedora

The `odbcinst.ini` file ends up in `/etc/`.

### Install FreeTDS

Mac:

$ brew install freetds --with-unixodbc

Note that the `freetds.conf` file ends up in `/usr/local/etc/freetds.conf`.
Installing this Homebrew package also provides the `tsql` command, which
can be useful for testing.

Linux:

This package is typically available via the Linux package manager.

For Ubuntu and Debian:

$ sudo apt-get install freetds-dev tdsodbc

The `freetds.conf` file ends up in `/etc/freetds/`. If you need the
`tsql` program (useful for testing), you also need the `freetds-bin` 
package:


$ sudo apt-get install freetds-bin

On CentOS (and, presumably, Fedora and RedHat):

$ sudo yum -y install freetds-devel

The `freetds.conf` file ends up in `/etc/`.

### Configure unixODBC and FreeTDS

This blog post provides a good overview of the process:


(NOTE: Those instructions talk about setting up a `$HOME/.odbcinst.ini`.
That file does not appear to be necessary.)

Find your `odbcinst.ini` file (see the section, above, on installing
`unixODBC`), and make its contents look like this.

[FreeTDS]
Description = FreeTDS MSSQL
# If you're on Linux, uncomment the following settings.
#Driver  = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
#Driver64= /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
#Setup   = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
#Setup64 = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
# Mac settings
Driver  = /usr/local/lib/libtdsodbc.so
Driver64= /usr/local/lib/libtdsodbc.so
UsageCount  = 2
CPTimeout   =
CPTimeToLive

Questions about how Django handles user authentication.

2014-01-19 Thread Chen Xu
Hi Everyone,
I am wondering how request.User get set during the authentication, do we
have to do anything like:

request.User = User() or it will have value by itself?


Thanks in advance.
-- 
⚡ Chen Xu ⚡

-- 
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/CACac-qZDa9GrT1wjbBxBsSR%2BGmotScqS76VrTCVw-8TJRioa7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.