error using django-admin with django-mssql - django

I am using django 1.6 with django-mssql
My django admin site works perfectly except for one part.
Whenever I click an "add user" link or otherwise navigate to /admin/auth/user/add I get the following error
(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Cannot issue SAVE TRANSACTION when there is no active transaction.', None, 0, -2147467259), None)
Command:
SAVE TRANSACTION [s3612_x1]
Parameters:
[]
I've tried various seetings in my database config such as "use_mars": true but there has been no change.
I am able to create users in code by using the User model without issue.
I have not encountered this error anywhere else.

Fixed by setting 'ATOMIC_REQUESTS': True for my db connection, which I should have been doing anyway.

Related

Handling Django Registrations for Duplicate Entries

Question PART 1:
Project => App => forms.py
![User Creation Form using default Django Structure]
Project => App => urls.py
![URL Routes defined in urls.py of Django App]
Project => App => views.py
![User Authentication using default Django Structure]
Instead of using SQLite, I am using MongoDB Database and the entries are being stored in the auth_user table but I wanna get rid of duplicate entries (i.e. same username/email). If the user enters a same username/email, the page gives a DatabaseError Exception which I believe is handled by Django itself.
Question PART 2:
Project => settings.py
![Have included MessageTags into settings.py]
Also how to give specific redirect locations to messages in Django !? Once the user completes registration, the success message is displayed and he is redirected to the login page to access the dashboard and other features. But when the user logs in successfully, he is redirected to the dashboard but the Success Message is being displayed when he logs out (in the logout page).
Approach PART 1:
Can I, using try catch, handle the exception and allow the user to change the entered values to something unique and get his details saved into the database !?
Approach PART 2:
Sometimes the messages are appearing onto different pages than specified pages while using render/redirect for views.py functions(i.e routes). I tried redirecting each message to specific routes but I guess it overwrites to the last render/redirect route.
Regards,
Joe.

Odoo website, Creating a signup page for external users

How can I create a signup page in odoo website. The auth_signup module seems to do the job (according to their description). I don't know how to utilize it.
In the signup page there shouldn't be database selector
Where should I store the user data(including password); res.users or res.partner
you can turn off db listing w/ some params in in odoo.cfg conf
db_name = mydb
list_db = False
dbfilter = mydb
auth_signup takes care of the registration, you don't need to do anything. A res.user will be created as well as a partner related to it.
The pwd is stored in the user.
User Signup is a standard feature provided by Odoo, and it seems that you already found it.
The database selector shows because you have several PostgresSSQL databases.
The easiest way is to set a filter that limits it to the one you want:
start the server with the option --dbfilter=^MYDB$, where MYDBis the database name.
User data is stored both in res.userand res.partner: the user specific data, such as login and password, are stored in res.user. Other data, such as the Name is stored in a related res.partner record.

Django-CMS 2.4 pages with SITE_ID 2 only found if you're logged in

I have two sites using Django-CMS. They use the same code and the same database, with the SITE_ID distinguishing them.
On the site with SITE_ID = 1, all is fine.
On the site with SITE_ID = 2, some pages that I publish (using the admin panel) can only be seen on the site if you are logged in. Otherwise they give me a 404 Error with a message like
CMS: Page not found for "test"
Other pages are ok - specifically the home page, and pages with apphooks.
If I set DEBUG = False, I get 404 errors on all my site's pages!
This is happening both in prod and on my dev server. In fact it happens even on a completely vanilla test site that I have just created too.
I did not chose "login required" for any of the pages.
How can I make the pages visible to all?
Version info: I am using Django-CMS 2.4.1 and Django 1.5.1. I also upgraded them to mptt 0.5.5, although Django-CMS specifically only installs mptt 0.5.2 (see this post for why). However, when I re-installed mptt 0.5.2 on my dev server the problem remained.
I raised this as an issue and now have the answer - it is the 'public': False line in this code:
CMS_LANGUAGES = {
1: [
{
'code': 'en',
'name': gettext('English'),
'public': True,
},
],
'default': {
'fallbacks': ['en',],
'public': False,
}
}
The key "1" is the SITE_ID, so the above says to hide all sites after number 1 from the public.
So the solution is to add an entry keyed off SITE_ID 2 in the CMS_LANGUAGES setting.
I think you need to first have a look at the ALLOWED_HOSTS setting (https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts). This is very likely the reason you get errors when you turn off DEBUG. (although, I thought not having a legit ALLOWED_HOSTS would produce 500 errors, not 404s.).

django socialauth twitter , google oauth , facebook does not work

This is my first post, and I have a problem I could not make it work django OMAB socialauth of three things I just need to google, facebook, and twitter, google works well with open id, but not much twitter and I put in my
settings. py:
TWITTER_CONSUMER_KEY = '00' this is no real
TWITTER_CONSUMER_SECRET = '00' this is no real
FACEBOOK_APP_ID = '' ihave no key
FACEBOOK_API_SECRET = ''
LINKEDIN_CONSUMER_KEY = ''
LINKEDIN_CONSUMER_SECRET = ''
ORKUT_CONSUMER_KEY = ''
ORKUT_CONSUMER_SECRET = ''ihave no key
GOOGLE_OAUTH2_CLIENT_ID = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''
SOCIAL_AUTH_CREATE_USERS = True
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
SOCIAL_AUTH_DEFAULT_USERNAME = 'socialauth_user'
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
LOGIN_ERROR_URL = '/login/error/'
#SOCIAL_AUTH_USER_MODEL = 'app.CustomUser'
SOCIAL_AUTH_ERROR_KEY = 'socialauth_error'
GITHUB_APP_ID = ''
GITHUB_API_SECRET = ''
FOURSQUARE_CONSUMER_KEY = ''
FOURSQUARE_CONSUMER_SECRET = ''
LOGIN_URL = '/login-form/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/login-error/'
I am using the example that comes in the zip of OMAB socialauth django , but not working.
When I created my twitter app, I wrote my domain www.sisvei.com , I am testing locally socialauth django ie 127.0.0.1:8000, then sign in with twitter sends me to this url:
http://127.0.0.1:8000/login/error/ and a message saying is the Incorrect authentication service
this happens with facebook and google oauth and oauth2
I'm new to django and I this much work comprising this part of django socialath hopefully help me, thank you very much.
You need to be more specific on "why it doesn't work". Where are you getting the errors?
When debugging a third-party oauth/openid app in Django, generally it boils down to:
configuration & keys - did you make sure to obtain all of the necessary API keys for the services you will be using, and to add them to your configuration?
urls - did you remember to add the necessary urlpatterns to your base urls.py file?
authentication setup on the server - often, you'll need to have a file available or respond with a specific header when the authentication service hits your server. Have you checked to make sure that is set up?
databases - have you run syncdb after installing the app? Are all the tables set up?
templates - if the third party app requires you to set up templates, do you have them set up?
custom views - are you using custom views? If so, try using the built-in views that came with the third party app first, to see if they work
After those are confirmed, you're going to want to be able to see what requests are taking place. Use the debugger included in Chrome/Safari, or get the web developer add-on for Firefox, and look at the network requests as they happen. Do you see HTTP responses other than 200 (say, 404, 500, 403, etc?) those mean that the services aren't responding correctly.
From your error, it looks like you have not correctly set up your callback URL on Twitter. It should be sending you to www.sisvei.com, not 127.0.0.1. Alternatively, check the URL when you get to the Twitter login page -- is the callback URL in the URL, and is it pointing to 127.0.0.1? Then Django is sending it the wrong callback URL.
Finally this:
I wrote my domain www.sisvei.com python does not support this
Is unclear. As far as I know, Python doesn't care what the domain is.
WAIT A MINUTE ...
Are you using runserver? Are you getting the following error?
Error: "www.sisvei.com" is not a valid port number or address:port pair.
If so, there is an easy fix! Just run it like so:
python manage.py runserver www.sisvei.com:80
That should resolve your error if that's what's happening. You're probably running it as
python manage.py runserver 127.0.0.1
127.0.0.1 is a reserved IP address that points back to localhost, your own computer. As a result, it is not possible to use it for authentication or any other purpose outside of programs running on your own machine. See this article for more info.
I'm not sure, but I might be having similar problems, oscar. For me, SocialAuth was generating an AuthenticationURL for facebook, foursquare and hotmail, but not for google, twitter or any of the other address it supports. I think it may be something wrong with the API, so I posted an issue on the social-auth google group...you may want to check there to see if anyone updates!!
https://code.google.com/p/socialauth/issues/detail?id=282&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary%20Modified

Admin login stopped functioning Django

I was working on my project for a while and recently noticed that when i try to go to localhost/admin/ it gives out an error :
DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: C:\Python27\lib\site-packages\django\db\models\query.py in get, line 349
Usually when i go there it makes me login first and then redirects me, but now it just errors unless i am already logged in
I can only enter my admin after login in as admin in the localhost login functionality i created for users and then going to that page. Also the logout from the admin page stoped working giving the same error.
I was working on adding a new field to the user module and displaying new user creation form when this happened.
anyone had similar problem? Or maybe someone knows what causing this?
Check out this thread, it seems relevant.
From the last post:
Since the exception said " 'Site' matching query does not exist", and the docs said something about the SITE_ID describing the site in the django_site database table, I went ahead and took a look at my (sqlite) database. The django_site table was empty, so I added a row with id==1 (the same that I have in settings.py) and then it worked.
If you don't mind loosing your data, you can try to run 'sql appname', as this table was supposed to be built automatically.
Try commenting or deleting 'django.contrib.sites' from the INSTALLED_APPS setting on your settings.py, that should solve the problem.
You can also check your sites table:
python manage.py shell
from django.contrib.sites.models import Site
Site.objects.all()
And if there is no site defined for localhost, you can create it or re-create it:
Site.objects.create(pk=1, domain='127.0.0.1:8000', name='localhost')
That worked for me.
For anyone trying to install django-allauth for django 1.8 or above and getting this error after following the instructions here:
http://django-allauth.readthedocs.org/en/latest/installation.html
Just add the following line to urls.py:
from django.contrib.sites.models import Site
Hope this saves someone time.
INSTALLED_APPS = [
....
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
....bla bla bla
]
SITE_ID = 1
try add SITE_ID=1
..it worked for me