Re: Django 2.2 and custom media in the admin

2019-04-10 Thread Thorsten Sanders

Hello,

thanks did overread that twice then, once when reading changes, once 
when trying to figure out if there was a change due not working.

Then i searched for it and came to:

https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#jquery

Maybe not bad idea to mention it there too.

Regards,
Thorsten

Am 09.04.19 um 23:14 schrieb Simon Charette:

Hello Thorsten, this is a change document in the 2.2 release notes[0].

There's even a resolution example for a django.jQuery dependency like 
you have


> For example, widgets depending on django.jQuery must specify
> js=['admin/js/jquery.init.js', ...] when declaring form media 
assets. [1]


Cheers,
Simon

[0] 
https://docs.djangoproject.com/en/2.2/releases/2.2/#merging-of-form-media-assets
[1] 
https://docs.djangoproject.com/en/2.2/topics/forms/media/#assets-as-a-static-definition


Le mardi 9 avril 2019 11:02:35 UTC-4, Thorsten Sanders a écrit :

Hello,

I insert a custom javascript inside the admin and do use the
"django.jquery" this worked fine until updating to Django 2.2.

With 2.2 the order in which the javascripts are loaded changed and
the jquery.init.js is now loaded after my custom javascript, is
that considered a bug or a change?

Regards,
Thorsten

--
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/scJvRttmQZY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
django-users+unsubscr...@googlegroups.com 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/018ab123-2b22-4425-bb6d-efeb1c4f12cf%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/018ab123-2b22-4425-bb6d-efeb1c4f12cf%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c675404c-fff5-1d8c-8927-4fa3cc84df31%40softint.de.
For more options, visit https://groups.google.com/d/optout.


Django 2.2 and custom media in the admin

2019-04-09 Thread Thorsten Sanders
Hello,

I insert a custom javascript inside the admin and do use the 
"django.jquery" this worked fine until updating to Django 2.2.

With 2.2 the order in which the javascripts are loaded changed and the 
jquery.init.js is now loaded after my custom javascript, is that considered 
a bug or a change?

Regards,
Thorsten

-- 
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/0265b762-fc32-4e5a-beb2-efa98b3d02c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom user model password is not hashed

2015-11-12 Thread Thorsten Sanders

If you wanna set the password yourself you need to generate it:

https://docs.djangoproject.com/en/1.8/topics/auth/passwords/

scroll down to the bottom and have a lookt at make_password



Am 12.11.2015 um 16:11 schrieb Benjamin Smith:

I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name,
username, date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when 
I try to login I can't. So I checked the user's email and password to 
confirm. Then I noticed that the password is displayed as plain text 
(eg. *strongpassword)*, and when changed the admin form to get the 
hashed password using *ReadOnlyPasswordHashField()* I get an error 
inside the password field, even though I used *set_password()* for the 
Manger inside the *create_user()* function.


/Invalid password format or unknown hashing algorithm/


However, if I manually do *set_password('strongpassword')* for that 
user inside the console, then only the password is hashed. Could you 
please help me solve this problem. 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 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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%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/5644AF6C.1090304%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Google indexing issue

2015-09-01 Thread Thorsten Sanders

Considering a:
https://www.google.de/search?q=site:http://www.schoolofdevelopers.in
shows more results than in the sitemap.xml are, this feels a bit like a 
hidden advertising.


Am 01.09.2015 um 20:04 schrieb James Schneider:
The front landing page does not have any links leading to the 
internals of the website, which may be a big problem when it comes to 
web crawlers. However, I've never done/cared about SEO, so the sitemap 
you submitted may be enough for Google to get around it. Regardless, I 
would still recommend having a hard link on the landing page that 
allows users to continue to the actual site without the need for JS.


You also have no robots.txt file in the root, which may be helpful for 
crawlers and your SEO score.


I just attempted a naive crawl of your site using wget, and confirmed 
the above.


There should be dozens of SEO checklists on the Internet, make sure 
you do the research and validate that your site is SEO ready. Of 
course there are also companies dedicated to such practices for hire.


-James

On Tue, Sep 1, 2015 at 10:51 AM, Arindam sarkar > wrote:


Guys I have submitted to google webmaster couple of days ago but
only 1 (one page is indexed so far). I am using django's sitemap
app for creating my site map. Any Idea what may be the reason for
not getting indexed by google .
My website link : www.schoolofdevelopers.in



-- 
Regards,


Arindam

Contact no. 08732822385


-- 
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/CAGnF%2BrDtuAgo-vM99qT-BPuKOkXq7dbj0MnFsy8mkyhHHyDynA%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/CA%2Be%2BciUdNx53uvyqurp-2%3DsVUDT9BBmcFNCD%2BRFOL983D-%3DUnQ%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/55E5E9CC.6000705%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Logout user on tab closing

2015-05-19 Thread Thorsten Sanders
I wouldnt do that at all, lets take ebay as an example when I use that I 
have several tabs at the same time open and it would be really annoying 
if I get a logout if I close one of those tabs and the same is true for 
many other sites.


Same is true for my bank too, they just do a logout if I dont do any 
action for 12m thats the better way if security matters and if on tab 
close, there should be maybe some sort of popup asking if you want to 
logout.


Am 19.05.2015 15:54, schrieb Javier Guerra Giraldez:

On Tue, May 19, 2015 at 8:23 AM, Miloš Milovanović
 wrote:

I want to logout a user from application when the application tab is closed.


the browser doesn't notify the server when the tab (or window) is closed.

remember that the original web architecture was simply about
downloading HTML documents and showing to the user.  Once the download
has happened, we're done with the server.

the whole concept of "web application" is javascript running in the
context of a web page, so you need the application itself (not the
browser) to notify the server.  You can use the "on-unload" event; for
example with jQuery's .unload() event hook.  Note that this event
fires every time the page is unloaded, not only when the window or tab
is closed, but also if the user navigates to another page (either via
the URL bar or by clicking any link), uses the 'back' or 'forward'
buttons, or even when reloading.

that's why most web applications rely on timeout and not on trying to
detect the user leaving the application.



--
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/555B8475.30105%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Thorsten Sanders

Am 07.05.2015 17:37, schrieb Tim Chase:

On 2015-05-07 13:56, palansh agarwal wrote:

processing of json is slow. It takes considerable amount of time to
process data after calling the API.

You seem fairly confident in this.  Do you have the timing
statistics?  Can you provide sample JSON data that others can use
for testing?  Which version of Python are you using and which Python
JSON library are you using?

-tkc



The version of python can make quite a big difference, years ago with 
python 2.6 I had the problem that decoding several megabyte of json data 
took over 1 minute with the integrated one, simplejson fixed that (only 
took a few hundred ms) and since 2.7 it works fine with the integrated 
one as well.


--
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/554BCBCB.2000703%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Namespace url lookup inside template of an app

2015-01-30 Thread Thorsten Sanders

Answering my own question, for the case someone else need it:

I am used to use render_to_response it not working with it, with using 
render it works with applying current_app, like this:


return render(request, 'myaddons/index.html', 
{'addons':addons,'game':game,},current_app=request.resolver_match.namespace)


Am 29.01.2015 um 21:24 schrieb Thorsten Sanders:

Hello,

writing currently an app which should show different things based on 
namespace which is working already, but I do have problems with 
generating the right url inside the templates of that app.

I tried to use:
{% url 'myaddons:index' %}
but that always shows the same namespace url the last one attached.

Currently have defined inside that app:
urlpatterns = patterns('',
url(r'^$', 'myaddons.views.index', name='index'),
)

Then have 2 other apps in one I define:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', 
namespace='wow-myaddons', app_name='myaddons')),

)

in the other one:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', namespace='ws-myaddons', 
app_name='myaddons')),

)

The base one is:

url(r'^wow/', include('warcraft.urls')),
url(r'^ws/', include('wildstar.urls')),

With what I tried it always resolve to:
/ws/addons/

I want it to resolve to:
/wow/addons/ if called with /wow/
and
/ws/addons/ if called with /ws/

Greetings,
Thorsten



--
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/54CB8061.4060904%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Namespace url lookup inside template of an app

2015-01-29 Thread Thorsten Sanders

Hello,

writing currently an app which should show different things based on 
namespace which is working already, but I do have problems with 
generating the right url inside the templates of that app.

I tried to use:
{% url 'myaddons:index' %}
but that always shows the same namespace url the last one attached.

Currently have defined inside that app:
urlpatterns = patterns('',
url(r'^$', 'myaddons.views.index', name='index'),
)

Then have 2 other apps in one I define:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', 
namespace='wow-myaddons', app_name='myaddons')),

)

in the other one:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', namespace='ws-myaddons', 
app_name='myaddons')),

)

The base one is:

url(r'^wow/', include('warcraft.urls')),
url(r'^ws/', include('wildstar.urls')),

With what I tried it always resolve to:
/ws/addons/

I want it to resolve to:
/wow/addons/ if called with /wow/
and
/ws/addons/ if called with /ws/

Greetings,
Thorsten

--
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/54CA96FC.8040305%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with raw query and using in

2013-11-17 Thread Thorsten Sanders
Thanks, I tried that, it makes the query right, but when I access the 
result in a for loop it gives now:


'Cursor' object has no attribute '_last_executed'

Think for now I just stay with using 2 variables, that works fine for 
the moment.



Am 17.11.2013 00:38, schrieb Dennis Lee Bieber:

On Sat, 16 Nov 2013 22:39:09 +0100, Thorsten Sanders
<thorsten.sand...@gmx.net> declaimed the following:


I am using mysql and when I write it like (1) then I get int is not
iterable on the first one, but the raw works, if I do it like (1,) the
first one works, but the raw one gets again the comma at the end, tried
several ways always one of both not working, for me it looks kinda there
is some magic happening and with only 1 value the comma is not removed,
but is removed with several values.

For now I just use 2 variables one for the raw queries and one for the
other, not the best solution, but works for now.


Am 16.11.2013 16:01, schrieb Javier Guerra Giraldez:

On Sat, Nov 16, 2013 at 7:40 AM, Thorsten Sanders
<thorsten.sand...@gmx.net> wrote:

realms=[1]
data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms)
data2 = AuctionData.objects.raw('SELECT * FROM auctiondata_auctiondata WHERE
itemid_id=%s AND realm_id in %s ',[itemid,realms])

not sure if it's related. but most SQL adaptors use a tuple for the
IN(...) parameters, not a list.

check http://initd.org/psycopg/docs/usage.html#tuples-adaptation


I suspect the main problem is that you need to set up the realms
parameter differently -- along with the query string.

MySQL, and most other SQL systems, as I recall, expect to see

... needle in (first, second, ..., last)

MySQLdb sanitizes parameters by converting them to a string
representation, escaping any special characters, and wrapping it is '
marks.

In the raw query, unless Django has an SQL parser, the above is
generating

select * from auctiondata_auctiondata where itemid_id = 'something' and
realm_id in '[1]'

when what you need to generate is

select * from auctiondata_auctiondata where itemid_id = 'something' and
realm_id in ('1')

(MySQLdb doesn't know what datatype to put in at each %s -- it has first
converted all inputs into safe strings; that's why it uses %s for the
placeholder).

If using a list of values, you'll have to create an SQL format with a
%s for EACH value, not the list

SQL = " ...%%s and stuff in (%s)" % ", ".join("%s" for x in realms)
(if realms is [1, 3, 99] this creates   
SQL ="... %s stuff in (%s, %s, %s")

You then need to flatten the parameters

parms=[itemid].extend(realms)



--
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/5288A08E.4090605%40gmx.net.
For more options, visit https://groups.google.com/groups/opt_out.


Problem with raw query and using in

2013-11-16 Thread Thorsten Sanders

Hello,

wondering if I am doing something wrong or it is a bug, using django 
1.5.5, but also tried with 1.6 resulting in the same problem.


When I do the following:

realms=[1]
data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms)
data2 = AuctionData.objects.raw('SELECT * FROM auctiondata_auctiondata 
WHERE itemid_id=%s AND realm_id in %s ',[itemid,realms])


The first query works as expected, but the 2nd one fails, because the 
query ends up as:


SELECT * FROM auctiondata_auctiondata WHERE itemid_id='43552' AND 
realm_id in ('1',)


The last comma shouldnt be there, if I use more than 1 value with the 
realms variable it works and the last comma isn't there.


Greetings,
Thorsten

--
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/528767D4.8080709%40gmx.net.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Associating Form Data with Users

2012-02-20 Thread Thorsten Sanders

You could do for example:

exclude the user field from the form and in your view something like this:

form = YourModelForm(request.POST)  #fill the modelform with the data
if form.is_valid(): # check if valid
mynewobject = form.save(commit=False) #save it to create 
the object but dont send to database

mynewobject.user = request.user # attach the user to it
mynewobject.save() # now do the real save and send it to 
the database


Am 20.02.2012 22:59, schrieb ds39:

I hate to keep bringing this issue up, but I'm still not entirely sure
how to implement this. I've tried a number of different ways to
connect some kind of user ID with form data without much success. Is
the idea that after authenticating the user in the view, request.user
be set to some variable that allows the user ID to be added to the
model or ModelForm ? Would this make the user object associated with
the form or model object accessible by filtering in the API ?

Thanks again


On Feb 19, 9:48 pm, Shawn Milochik  wrote:

On 02/19/2012 09:29 PM, ds39 wrote:


Thanks for your response. But, would you mind expanding on it a little
bit ?

How about you give it a try and see what you can figure out? In your
view, request.user will return the currently logged-in user (or an
AnonymousUser if they're not logged in). Since you said your view
requires login, you'll have a User object all ready to go.

Shawn


--
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: what is the best IDE to use for Python / Django

2012-02-15 Thread Thorsten Sanders

Why this kind of stuff never ends?;(

The best IDE is simply the one you can work best with, YOURSELF!

On 15.02.2012 16:13, Vikas Ruhil wrote:
Vim is best IDE for Python/Django ! look here the link 
http://learnhackstuff.blogspot.in/2012/02/vim-as-universal-idepart-1.html


On Wed, Feb 15, 2012 at 8:16 PM, Bastian Ballmann 
> wrote:


Hey thats a cool list and I feel like I must answer on it :)


Am 01.02.2012 17:43, schrieb Masklinn:

On 2012-02-01, at 17:00 , Bastian Ballmann wrote:

And what exact feature makes PyCharm an IDE that emacs hasnt?

* Semantics navigation (not via tags, it knows to find a class
when you want a class)

I heard ECB can do this, but I dont use it


* Better static analysis and language knowledge (the type
inference is still pretty limited, but if you instantiate an
object and call a method on it it knows and only proposes the
available methods)
  - virtualenv-aware, knows to restrict its libraries search
to the project's virtualenv

You can do this with setenv or virtualenv.el too


  - errors and warnings are faster to display than via flymake
in my experience

For me flymake is faster *g*

  - also intentions and quickfixes, PyCharm can improve or
simplify code for known bad or sub-par patterns, and can fix a
limited number of errors (PyCharm will suggest importing a
module you reference without you having to go to the module
top and doing so manually)


Autoimport can be done with rope-auto-import


  - finds all references to an object


And this one with rope-find-occurrences


* Much, much better (faster, more expansive and with less
bullet holes) refactoring support than Rope&  ropemacs (I use
both)
* Good support of various template languages (Django, Jinja2
and Mako as of 2.0) with autocompletion, basic static
analysis, syntax highlighting, etc…

Yeah that's something I miss, but auto-completion for Django
template code is available in django-mode


* Semantic knowledge of Django projects
  - jumping between a view and its template


This can also be done with django-mode


* Much better debugging story
  - Pretty good visual debugger with watches and conditional
breakpoints
  - Remote debugger (via a specific agent)


Therefore I use pddb outside of Emacs

  - Django templates debugging

Yep that's also something I miss. Can partly be done with Werkzeug
in the browser

For me Emacs has the far better editing features than the Eclipse
editor with stuff like rectangle edit,
macros and the like and it's very good extensible and therefore
can perfectly adapted to one's needs.
Greets

Basti

-- 
Bastian Ballmann / Web Developer

Notch Interactive GmbH / Badenerstrasse 571 / 8048 Zürich
Phone +41 43 818 20 91 / www.notch-interactive.com


-- 
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.


--
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: Translation inside the database

2012-02-08 Thread Thorsten Sanders

Am 08.02.2012 21:35, schrieb akaariai:

On Feb 8, 9:33 pm, Thorsten Sanders<thorsten.sand...@gmx.net>  wrote:

Hello,

I have tables having translation like this:

name_en,name_de,name_fr...

With google I found 2 solutions which support that, but they dont allow
to use those fields then with order,filter, values etc...so its kinda
useless.

With some trying arround, I came up with the following:

from django.db import models
from django.utils.translation import get_language

class TransCharField(models.CharField):

  def __getattribute__(self,value):
  if value == 'column':
  return '%s_%s' % (super(TransCharField,
self).__getattribute__(value),get_language())
  else:
  return super(TransCharField, self).__getattribute__(value)

Inside model then for example:

name = TransCharField(max_length=255)

I did some testing and it seems to work proper as I want it, I can just
use the orm normal and using name and inside the query the field get
translated to the right name.

My question is if that solution can have any side effects or if there is
a better way to do that, I will btw only do read operations on those
tables, there will never be write/updates to it via django.

syncdb etc woud break for sure, but it seems that will not be a
problem for you. Serialization will give you only one language. I
can't think of anything else that will break for sure. On the other
hand, it wouldn't be surprising if the list of things that do not work
would be a lot longer. If it works, use it. But it will not work 100%.
Yep I know syncdb breaks and that is not a big problem for me, 
serialization if used should only give 1 language as well and prolly it 
will be used and exactly the "it wouldn't be surprising if the list of 
things that do not work would be a lot longer" is why I am asking, I had 
it before that something works nice 99% of the time but the other 1% it 
dont, in a upcoming project I plan to use that approach for a lot of 
queries and would be quite bad if some side effects will appear, because 
it would be prolly a lot of work to change it.


A safer way would be to do something like:
SomeModel.objects.filter(t('some_column')=someval).order_by(t('some_column'))

def t(col):
 return '%s_%s', (col, get_language())

  - Anssi



--
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.



Translation inside the database

2012-02-08 Thread Thorsten Sanders

Hello,

I have tables having translation like this:

name_en,name_de,name_fr...

With google I found 2 solutions which support that, but they dont allow 
to use those fields then with order,filter, values etc...so its kinda 
useless.


With some trying arround, I came up with the following:

from django.db import models
from django.utils.translation import get_language

class TransCharField(models.CharField):

def __getattribute__(self,value):
if value == 'column':
return '%s_%s' % (super(TransCharField, 
self).__getattribute__(value),get_language())

else:
return super(TransCharField, self).__getattribute__(value)

Inside model then for example:

name = TransCharField(max_length=255)

I did some testing and it seems to work proper as I want it, I can just 
use the orm normal and using name and inside the query the field get 
translated to the right name.


My question is if that solution can have any side effects or if there is 
a better way to do that, I will btw only do read operations on those 
tables, there will never be write/updates to it via django.


Greetings,
Thorsten

--
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: Django Tutorial Part 3 Decoupling the URLconfs

2012-02-06 Thread Thorsten Sanders
You are using the tutorial of the development version which is 1.4 
alpha, but using yourself version 1.3.1, so you need to use


django.conf.urls.defaults instead of django.conf.urls

Better use the 1.3 tutorial instead of the development one to not run into such 
troubles.


Am 06.02.2012 23:23, schrieb John Paton:

Thanks for the help.

Here's what it says: from django.conf.urls import patterns, include,
url

and then it says unresolved import: url, include, patterns.

Can you tell me what is going wrong here.

Thanks!



On Feb 6, 12:02 pm, Pavlo Kapyshin  wrote:

As this exception says, you have an error on first line of urls.py.
Double-check that line.


--
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: import error

2012-02-03 Thread Thorsten Sanders
Did you try to add a $ after the last slash for the login, may that 
makes a difference for the url resolver, but dunno, just a wild guess.



Am 03.02.2012 18:39, schrieb Miten:

hi guys,
I am doing simple app for learning.  I created page and then auth
protected but as I added register link to login page it errors out on
import error.  I think its some thing to do with setup since created
new app for registration.  I have shown my setup and setting and
traceback at
http://dpaste.com/697051/
http://dpaste.com/697053/
http://dpaste.com/697144/

please take a look and advice.  I am able to import login from django
shell fine.

Regards,

Miten.



--
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: Help Me With omab/django-socialauth

2012-02-02 Thread Thorsten Sanders
I took your config and its working fine, maybe your twitter api key is 
wrong?


On 02.02.2012 11:22, coded kid wrote:

I'm getting a redirect loop error. Whats the probs?

On Feb 1, 1:22 pm, Thorsten Sanders<thorsten.sand...@gmx.net>  wrote:

Some sort of error traceback/description would be helpful, from a quick
look it seems all right.

On 01.02.2012 13:23, coded kid wrote:




Hey guys, I'm facing a huge  problem with omab/django/socialauth.
After setting all the necessary settings, I clicked on the Enter
using Twitter link on my homepage, it couldn t redirect me to where I
will enter my twitter username and password. Below are my settings.
In settings.py
INSTALLED_APPS = (
'social_auth',
}
TEMPLATE_CONTEXT_PROCESSORS = (
 "django.core.context_processors.auth",
 "django.core.context_processors.debug",
 "django.core.context_processors.i18n",
 "django.core.context_processors.media",
 "django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
 social_auth.context_processors.social_auth_by_type_backends ,
)
AUTHENTICATION_BACKENDS = (
 'social_auth.backends.twitter.TwitterBackend',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter')
TWITTER_CONSUMER_KEY = '0hdgdhsnmzHDGDK'
TWITTER_CONSUMER_SECRET  = 'YyNngsgw[1jw lcllcleleedfejewjuw'
LOGIN_URL = '/accounts/login/' #login form for users to log in with
their username and password!
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/homi/'  #page after user get
authenticated
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/homi/'   '  #page after
user get authenticated
SOCIAL_AUTH_ERROR_KEY='social_errors'
SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
from django.template.defaultfilters import slugify
SOCIAL_AUTH_USERNAME_FIXER = lambda u: slugify(u)
SOCIAL_AUTH_UUID_LENGTH = 16
SOCIAL_AUTH_EXTRA_DATA = False
In urls.py
url(r'', include('social_auth.urls')),
In my template:

   Enter using Twitter
   

What do you think I m doing wrong? Hope to hear from you soon. Thanks
so much!
N:B : I m coding on windows machine. And in the development
environment using localhost:8000.


--
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: create users from /etc/passwd?

2012-02-02 Thread Thorsten Sanders

https://bitbucket.org/maze/django-pam/

maybe that helps?

On 02.02.2012 16:47, Tim wrote:

I'm running Django 1.3.1 on FreeBSD + Apache2.2 inside an intranet.

I do not grok authentication, so here is my problem and a question 
about how I can solve it (maybe).
What I need is the name of the user who hits the application. I don't 
care about the password, I just need to know who they are. I've been 
unable to get the REMOTE_USER from Apache, mainly because I think 
Apache doesn't know it either (no authentication is used on the 
httpd.conf).


I thought (here's my maybe solution) I might create a bunch of users 
in Django by parsing the /etc/passwd database. Then at least each user 
would have the same username/password they use to login to the network.


Is that possible? Is there a better way to get the username?
thanks,
--Tim

--
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/-/qO-mxTOE0joJ.

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: Help Me With omab/django-socialauth

2012-02-01 Thread Thorsten Sanders
Some sort of error traceback/description would be helpful, from a quick 
look it seems all right.


On 01.02.2012 13:23, coded kid wrote:

Hey guys, I'm facing a huge  problem with omab/django/socialauth.

After setting all the necessary settings, I clicked on the “Enter
using Twitter” link on my homepage, it couldn’t redirect me to where I
will enter my twitter username and password. Below are my settings.
In settings.py

INSTALLED_APPS = (
'social_auth',
}

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
   "django.contrib.messages.context_processors.messages",
   "django.core.context_processors.request",
   “social_auth.context_processors.social_auth_by_type_backends”,

)
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
   'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter')

TWITTER_CONSUMER_KEY = '0hdgdhsnmzHDGDK'
TWITTER_CONSUMER_SECRET  = 'YyNngsgw[1jw lcllcleleedfejewjuw'

LOGIN_URL = '/accounts/login/' #login form for users to log in with
their username and password!
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/homi/'  #page after user get
authenticated
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/homi/'   '  #page after
user get authenticated
SOCIAL_AUTH_ERROR_KEY='social_errors'

SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'

from django.template.defaultfilters import slugify
SOCIAL_AUTH_USERNAME_FIXER = lambda u: slugify(u)
SOCIAL_AUTH_UUID_LENGTH = 16
SOCIAL_AUTH_EXTRA_DATA = False

In urls.py
url(r'', include('social_auth.urls')),

In my template:

  Enter using Twitter
  

What do you think I’m doing wrong? Hope to hear from you soon. Thanks
so much!
N:B : I’m coding on windows machine. And in the development
environment using localhost:8000.

   


--
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 do you pass dissimilar data from view to template?

2012-01-27 Thread Thorsten Sanders
If the data is presented as table, datatables is a really nice jquery 
plugin for such stuff:


http://datatables.net/

On 27.01.2012 17:31, BillB1951 wrote:

Thanks for the additional thought on this.  It is a much appreciated
confirmation to me.  Last night I was torturing my brain over the
logistics of what I had conceived, and by this morning I had pretty
much concluded that I would have to go the route you are suggesting.
Now I just have to find an existing solution ... or learn Javascript.
--Bill

On Jan 27, 11:19 am, Dennis Lee Bieber  wrote:
   

On Thu, 26 Jan 2012 14:01:50 -0800 (PST), BillB1951
wrote:

 

Brett, Thanks.  That is what I needed.  BillB1951
   

 Just an aside: seems like a convoluted plan to keep round-tripping
to the server/database each time you refine the filter.

 I'm presuming the initial data set being sent is the "full" list. If
so, might it not be useful to somehow (Caveat: I'm /not/ skilled at
this, only toyed with Javascript too many years ago) embed a Javascript
action to count the categories, render the filter selections and, when
one is picked, have the Javascript modify the page in-place to display
only the filtered data?

 Granted, adding another language on top of Python, Django, and the
template language, may be more than desirable.
--
 Wulfraed Dennis Lee Bieber AF6VN
 wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
 
   


--
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.



Caching and excluding in a template

2012-01-25 Thread Thorsten Sanders

Hello,

wondering if there is any easy way to exclude a little part from a 
template to be cached, on every site there is a the usual register/login 
or you are logged in with a user menu, back in php+smarty times it was 
easy solved using a dynamic tag to easily exclude a small part from 
being cached.


So far I only saw you could turn off caching for logged-in users or fine 
grade what is being cached, the first I dont want (only caching stuff 
which looks same for all users except the user menu) and the latter 
seems to be quite some work compared to just exclude a litte part in the 
base template.


Greetings,
Thorsten

--
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: django-localeurl and SEO

2012-01-20 Thread Thorsten Sanders
You could add sitemaps in the google webmaster tools or make a sitemap 
in the root dir which contains links to the other sitemaps.


On 19.01.2012 17:59, ionic drive wrote:

Hello django friends,

I have installed "django-localeurl" successfully. After some 
redirecting troubles... don't worry ;-)

it works fine, but...

The Problem:
-
How is django-localeurl performe concerning SEO?
The "problem" is, if the browsers main language is "en" the 
sitemap.xml links are created with 
http://example.com/EN/websitename/foo.html
 if the browsers main language is "de" the 
sitemap.xml links are created with 
http://example.com/DE/websitename/foo.html 

 if the browsers main language is "it" the 
sitemap.xml links are created with 
http://example.com/IT/websitename/foo.html 

 if the browsers main language is "fr" the 
sitemap.xml links are created with 
http://example.com/FR/websitename/foo.html


Question:

So it again depends on the google-bot settings (language settings) 
which urls are sent to google webindex.
Does google know, it should search with different bot settings, to 
realize that there are multiple languages?


If NOT, than the solution without django-localeurl as we had it before 
was far better.


Awaiting your professional SEO answers.
Thank you very much for helping me on that topic!
ionic --
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: Having Headache With LoginForm

2012-01-17 Thread Thorsten Sanders

With using

@login_required decorator the user needs to be logged in to allow execution, 
don't makes much sense for a login :P



Am 17.01.2012 22:23, schrieb coded kid:

Hi guys, I’m having problem with my login form. The login form will
redirect me to the next page even if I didn’t input anything in the
username and password field. Also it can’t get the username of the
registered users to verify if the user data is wrong or right. How can
I get rid of this problem?
Below are my code:
In views.py
from django.db import models
from mymeek.meekme.models import RegisterForm
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required

@login_required
def mylogin(request):
 if request.method=='POST':
 username= request.POST['username']
 password= request.POST['password']
 user=authenticate (username=username, password=password)
 if user is not None:
 if user.is_active:
 login(request, user)
 return HttpResponseRedirect('/logpage/')
 else:
 return direct_to_template(request,'q_error.html')
 else:
 return render_to_response('mainpage.html')
In my template:




   {{form.username.label_tag}}
   {{form.username}}


   {{form.password.label_tag}}
   {{form.password}}





Please help me out! 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-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: Primary key for read-only models

2012-01-12 Thread Thorsten Sanders
Had recently kinda the same just that I have 2 tables without a primary 
key at all and I just declared one of the fields as primary key and 
works fine.


On 12.01.2012 16:03, Demetrio Girardi wrote:

I need to read data from an "external" database table from my django
project. I am not interested in modifying the data, only reading it.
Of course I would like to create a django model for the table, because
it makes life so much more easier.

I have already done this previously, however in this case the table
has a multiple field primary key, unsupported by Django. There is no
other field which is guaranteed to be unique that I can use as primary
key in the Django model.

Do I need to worry about this? or can I just slap the primary_key flag
on any of the fields, since I will never be inserting or updating in
that table?

   


--
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: Replicate admin format in django template

2012-01-12 Thread Thorsten Sanders
You need to convert the new lines to html code there are 2 templatetags 
for doing so:


https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#linebreaks


On 12.01.2012 09:54, Nikhil Verma wrote:

Hi

I have a column which is a TextField. When we look at django admin it 
appears as a box.


models.py
add_detail = models.TextField()

Let say you write the following text in that  add_detail textbox in 
django admin :-


 Mission Impossible 4
 Actor : Tom cruise

I am displaying this add_detail in template in the following way:-


{{add_detial}}


I have to display it in a box with proper alignment so i am using it 
in a table format.


Now when you look at the template It will appear like this:-

 Mission Impossible 4 Actor : Tom cruise

What i want is the way it is saved in admin add_detail field in 
whatever manner whether he gave whitespaces,breaks,press return

it should appear exactly the same in html. How can i achieve this ?


Regards
Nikhil Verma

--
Regards
Nikhil Verma
+91-958-273-3156

--
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: Django orm and no primary key

2012-01-10 Thread Thorsten Sanders

Am 10.01.2012 20:46, schrieb Ian Clelland:


This is possible -- there was some discussion on this list about it 
just a few days ago. If you tell Django that another field is the 
actual primary key, then it will not assume that there is an 'id' 
column (which is good, because otherwise it will try to include that 
in any SELECT statements that it issues).
Seems I should read more often the list, then I wouldnt have missed that 
one.




As long as you consider this table to be essentially read-only, and 
you don't try to use the ORM to create any records in it, then you 
shouldn't have any problems with this. As specific measures:


- Don't try to create records with Model.objects.create() or 
Model.objects.get_or_create()
- If you have to retrieve records, use filter() rather than get, if 
you can't ever assume uniqueness
- Similarly, if you have to update records, use update() rather than 
save().


It sounds like you want to use aggregate queries on this table anyway, 
so you (hopefully) shouldn't run into any issues.
Yep that fits from the orm side it is only reading to aggregate 
statistics from a table holding history data, I like the orm style way 
easier to write/manage than raw queries hence my question, the 
inserts/deletes are handled lowlevel without django.


And cheers for the answer gave me the motivation to try it out in the 
near future, currently I only still got that "primary key" to not break 
the orm, removing it would free up quite some not needed space if it works.


Oh, and don't register this model with the admin; most of that 
framework is built around the idea of rows uniquely addressable by 
their primary key.


--
Regards,
Ian Clelland
>
--
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.



Django orm and no primary key

2012-01-09 Thread Thorsten Sanders

Hello,

I am wondering if it is possible to still use the django orm without 
having a primary key at all, I currently got a table holding 61 million 
entries soon gonna expand to hold 600 million entries, that table never 
need to identify one entry alone its only to pull off statistics based 
on other fields, so far I  dropped the primary key index in the database 
and all works fine, but I know the orm always want a primary key, would 
it still work if I for example claim one of the fields which aren't 
unique as the primary key?


Or is the only way to do it, use the cursor or even mysqldb directly?

Greetings,
Thorsten


--
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: This Week In History

2012-01-05 Thread Thorsten Sanders

You dont mention the database you use if mysql you could do

SELECT * FROM  WHERE DATE_FORMAT(, "%u") = 
DATE_FORMAT(curdate(), "%u")


dont know if there is a django orm way to do it, but could always use a 
raw query.


Am 05.01.2012 21:14, schrieb Tim Sawyer:

Hi Folks,

Does anyone have a strategy for selecting from a database where the 
date is this week, but a random year in the past?


I have ~100 years of events in a database, each with a datefield - I 
would like to do a "this week in history" box that lists one or two on 
the homepage, randomly taken from the set.


Ideas/pointers appreciated.

Cheers,

Tim.



--
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: Checkboxes for a list of items like in Django admin interface

2012-01-04 Thread Thorsten Sanders
I missunderstood due "and in a view loop through somename list" thought 
you mean you delete them 1 by 1 :P


And the orm itself tries to convert the value to an int and throws an 
ValueError if it fails, so find it a bit double to check myself and let 
the orm do it again.


On 04.01.2012 13:43, Martin Tiršel wrote:
Yes, this is the technique I described but I was asking if there is a 
Django way to do this.


You can't forgot to sanitize the input in this case:

id_list = request.GET.getlist('id_notification_list')
id_list = [int(i) for i in id_list if i.isdigit()]
notifications = Notification.objects.filter(
id__in=id_list,
)

Martin

On Wed, 04 Jan 2012 12:11:11 +0100, Thorsten Sanders 
<thorsten.sand...@gmx.net> wrote:



I do it this way:



and in the view:

todel = request.POST.getlist('todelete')
ItemWatchList.objects.filter(user=request.user,id__in=todel).delete()


On 04.01.2012 11:33, Martin Tiršel wrote:

Hello,

I have a list of items (from a model) I want to display with 
checkboxes (for deleting multiple objects at once). The same 
behaviour like in django admin (change list). I can do such thing in 
templates:


{% for item in item_list %}


{{ item }}

{% endfor %}

and in a view loop through somename list I get from POST and delete 
items. Is there a better Django way I should do it or this approach 
I wrote is correct? Is there a way I could use Django forms for 
processing the POST data and delete items in a form's method (so I 
can use it from multiple views)?


Thanks,
Martin





--
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: Checkboxes for a list of items like in Django admin interface

2012-01-04 Thread Thorsten Sanders

I do it this way:



and in the view:

todel = request.POST.getlist('todelete')
ItemWatchList.objects.filter(user=request.user,id__in=todel).delete()


On 04.01.2012 11:33, Martin Tiršel wrote:

Hello,

I have a list of items (from a model) I want to display with 
checkboxes (for deleting multiple objects at once). The same behaviour 
like in django admin (change list). I can do such thing in templates:


{% for item in item_list %}


{{ item }}

{% endfor %}

and in a view loop through somename list I get from POST and delete 
items. Is there a better Django way I should do it or this approach I 
wrote is correct? Is there a way I could use Django forms for 
processing the POST data and delete items in a form's method (so I can 
use it from multiple views)?


Thanks,
Martin



--
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: error attempting to populate field

2012-01-03 Thread Thorsten Sanders
Because its a foreign field either get an instance of Listings with that 
id like:


listening = Listings.objects.get(id=15)

CanoeKayak.listings = listening

or to add directly a value:

CanoeKayak.listings_id = 15



Am 04.01.2012 04:46, schrieb BillB1951:

I am trying to add the interger value 15 to a table field
CanoeKayak.listings, which is a Foreignkey field that is related to
the "Listings.id" field in another table --- a listings.id=15 exists.

What is happening?

see error below:

ValueError at /bsmain/canoekayak/add/15/

Cannot assign "[15]":"CanoeKayak.listings" must be a "Listings"
instance.

Request Method: POST
Request URL:http://127.0.0.1:8000/bsmain/canoekayak/add/15/
Django Version: 1.3.1
Exception Type: ValueError
Exception Value:

Cannot assign "[15]": "CanoeKayak.listings" must be a "Listings"
instance.

Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/
models/fields/related.py in __set__, line 331
Python Executable:  /usr/bin/python
Python Version: 2.6.5
Python Path:

['/home/bill/workspace/boatsite',
  '/usr/lib/python2.6',
  '/usr/lib/python2.6/plat-linux2',
  '/usr/lib/python2.6/lib-tk',
  '/usr/lib/python2.6/lib-old',
  '/usr/lib/python2.6/lib-dynload',
  '/usr/lib/python2.6/dist-packages',
  '/usr/lib/python2.6/dist-packages/PIL',
  '/usr/lib/python2.6/dist-packages/gst-0.10',
  '/usr/lib/pymodules/python2.6',
  '/usr/lib/python2.6/dist-packages/gtk-2.0',
  '/usr/lib/pymodules/python2.6/gtk-2.0',
  '/usr/local/lib/python2.6/dist-packages']

Server time:Tue, 3 Jan 2012 21:33:38 -0600



--
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: mysql installation error

2011-09-21 Thread Thorsten Sanders
When I first installed django, that made me going crazy to try to 
install that library, in the end I just went with a pre-compiled from


http://www.lfd.uci.edu/~gohlke/pythonlibs/

On 21.09.2011 04:59, PremAnand Lakshmanan wrote:

Hi,
When I try to install mysql I get the following error,
Pls provide your inputs.

C:\MYSQL\MySQL-python-1.2.3\MySQL-python-1.2.3>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 15, in 
metadata, options = get_config()
  File 
"C:\MYSQL\MySQL-python-1.2.3\MySQL-python-1.2.3\setup_windows.py", line 7

, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 
options['registry_ke

y'])
WindowsError: [Error 2] The system cannot find the file specified
--
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: Create socket server in django

2011-09-20 Thread Thorsten Sanders

import sys,os

sys.path.append('/path/to/your/django_project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_settings_file'

This works fine for a cronjob I created

On 20.09.2011 10:48, Thomas Orozco wrote:


You just have to run your server as a daemon and use Django's 
setup_environment so you can use the ORM to interact with your Django DB.


I can try and find the lines you need to do that if you can't find them.

Le 20 sept. 2011 09:08, "Micke" > a écrit :

--
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: Trouble expressing a query in the ORM

2011-09-09 Thread Thorsten Sanders

On 09.09.2011 17:36, Daniel Gagnon wrote:



On Fri, Sep 9, 2011 at 9:28 AM, Pewpewarrows > wrote:


Tim Shaffer's response would have you doing N+1 queries, and
having to loop through all of your Target objects in-memory.
Technically it would work, but as soon as you have a decently
sized amount of data in there it'd slow to a crawl.


Indeed and I have to sort and pick a subset of the sort after that. I 
can't run a loop through thousands and thousands of items to only 
select a hundred.


The best way I can see to do this straight with the Django ORM is:

prop_dates =

Target.objects.annotate(latest_property=Max('property__export_date')).values_list('latest_property',
flat=True)
properties = Property.objects.filter(export_date__in=prop_dates)


Let say I have two targets which I'll call target1 and target2.

Target1 have a property for yesterday and one for today. Target2 only 
have a property for yesterday. Both yesterday and today will be 
included in prop_dates since they are the latest for at least one 
target. And then Target1 will have two entries in properties while it 
should only have one for today.



Which comes out to two queries. If you absolutely had to, you
could execute some raw SQL to narrow it down to one query. Please
note that there is a (very) small possibility that the second
query might return extra Properties for a given Target. Because
it's operating based on date-timestamps, there could be two
Properties that happen to have the exact same export_date, one of
which happens to be the most recent for a given Target.
Eliminating those duplicates, if you want to account for that
scenario, can be done in-memory or I believe through some
adjustments to the second line above.


I just designed a SQL query, I am wondering if I couldn't translate 
the logic to the ORM. It looks like this:


select * from Target_Mgmt_target as t
inner join (select *,max(export_date) as max_export_date from 
Target_Mgmt_property group by target_id) as p on p.target_id = t.id 
 and p.export_date = p.max_export_date;

--

from django.db.models import Max
Target_Mgmt_target.objects.annotate(export_date=Max('Target_Mgmt_property__export_date')).values(you want>)


This should 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.



Re: Delegating a async job from a django view

2011-08-25 Thread Thorsten Sanders

https://github.com/ask/django-celery

Take a look at that, it should be able to do what you want, though never 
used it myself yet.



On 25.08.2011 09:24, Amit Sethi wrote:

What is the best solution for delegating a long time taking job from a
django view. Basically i wish to query a few web api , analyze and
then create a report . The report is not to be created in a sync
manner and can be sent at a later time . But it will have a web
interface to decide a few factors . I somehow think that twisted can
be used for this but I am not sure how one can use twisted with django
. Are there any other solutions that i can use for this problem .

Thanks
Amit



--
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: Django Development environment

2011-08-23 Thread Thorsten Sanders

IDE:
PyCharm (its for python with django support,not free but love it and not 
to expensive)


Database:
mysql/postgresql

Standard apps:
south (really a must have to apply database changes easy)
debug_toolbar

Am 23.08.2011 14:47, schrieb Yas,ar Arabac?:

Development setup (when on my own comp.):
arch linux, vim or leafpad, sqlite, django development server

Development setup (when on my brothers comp):
cygwin, notepad++, sqlite, django development server (both inside and 
outside of cygwin to make sure everything is same.)


Deployment:
ubuntu (cloud), nginx with uwsgi, supervisord, postgresql, south

MUST HAVES (on all platforms): git!

2011/8/23 Raul Alejandro Ascencio Trejo >


Emacs (https://code.djangoproject.com/wiki/Emacs), Postgre... :|


2011/8/22 Mario Gudelj >

Mac, sqlite, Eclipse with Pydev or AquaMacs, apache


On 23 August 2011 13:06, Jani Tiainen > wrote:

Ubuntu or windows, eclipse with pydev, apache, nginx,
virtualenv and Oracle.

Stephen Jackson > kirjoitti 23.8.2011
kello 1.07:


I am new to the world of Django. I would like to hear
from other django developers describe their dev
environment (tools, os, editors, etc.).
-- 
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/-/Fq-jCVxrK7AJ.

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.


-- 
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.




-- 
r-ascencio 




-- 
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.




--
http://yasar.serveblog.net/

--
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.