another CSRF question -- and django hitcount

2014-12-06 Thread Eric Abrahamsen
I have a question about the django-hitcount app that I think is likely
csrf-related.

I recently upgraded a site from Django 1.4 all the way to 1.7. I've got
most everything working fine, except that the hitcount app I've been
using[1], stopped recording hits.

Nevermind the actual app, it works by making an ajax call to a certain
URL when a page is opened. Right now, the rendered javascript looks like
this:



Since I upgraded, no hits have been recorded. I can't say for sure it's
csrf-related, but I've been looking at the docs[2], and suspect that's
the problem.

The string "csrf_token" is produced as a hardcoded string, not a
variable or anything -- that seems awfully wrong to me.

After looking at the docs, and installing the cookie plugin, and
scratching my head, this is what I've come up with:

var csrftoken = $.cookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(document).ready(function() {
$.post( '/ajax/hit/',
{ hitcount_pk : '{{ object.pk }}'},
function(data, status) {
if (data.status == 'error') {
// do something for error?
}
},
'json');
});

("object" is the variable )

Does this seem right? Will the ajaxSetup apply to my post, even though I
haven't said anything explicitly to that effect?

I apologize for such a brainless set of questions -- I don't know JS
very well, and don't know how to debug it. How could I even tell if this
was working?

Eric


[1]: https://github.com/scottwrobinson/django-hitcount/
[2]: https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax

-- 
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/87oarh5h57.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Connect django project with sharepoint 2013

2014-12-06 Thread Hossein Rashnoo
I need to connect my project to sharepoint. So i installed "sharepoint 
0.4.1" package and then use this code in my view :

from sharepoint import SharePointSite, basic_auth_opener

def userloginres(request):
server_url = "http://portal:8080/";
site_url = server_url + "rashno/"
opener = basic_auth_opener(server_url, "my username", "my password")
site = SharePointSite(site_url, opener)

htt=r"Sharepoint lists"
for sp_list in site.lists:
htt = htt + r" %s . %s " % (sp_list.id,sp_list.meta['Title'])
htt = htt + r""

t = get_template('userlogin/userloginres.html')
html= t.render(Context({"htt":htt}))
return HttpResponse(html)

But now when i open that url this error appear:

URLError at /test/login/



-- 
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/a982dfcf-6824-441a-ab5f-f68907e1f0d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Connect django project with sharepoint 2013

2014-12-06 Thread François Schiettecatte
Ok, but I am not sure what this has to do with Django ? Maybe you should ask on 
a SharePoint mailing list ? And did you try running the code in a script on the 
command line ?

François

> On Dec 6, 2014, at 7:10 AM, Hossein Rashnoo  wrote:
> 
> I need to connect my project to sharepoint. So i installed "sharepoint 0.4.1" 
> package and then use this code in my view :
> 
> from sharepoint import SharePointSite, basic_auth_opener
> 
> def userloginres(request):
>   server_url = "http://portal:8080/";
>   site_url = server_url + "rashno/"
>   opener = basic_auth_opener(server_url, "my username", "my password")
>   site = SharePointSite(site_url, opener)
> 
>   htt=r"Sharepoint lists"
>   for sp_list in site.lists:
>   htt = htt + r" %s . %s " % 
> (sp_list.id,sp_list.meta['Title'])
>   htt = htt + r""
> 
>   t = get_template('userlogin/userloginres.html')
>   html= t.render(Context({"htt":htt}))
>   return HttpResponse(html)
> 
> But now when i open that url this error appear:
> 
> URLError at /test/login/
> 
> 
> 
> -- 
> 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/a982dfcf-6824-441a-ab5f-f68907e1f0d7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C2CC4E3F-9E56-47E2-AF74-459007BF7FC7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add another link missing in Chrome

2014-12-06 Thread Timothy Good
Here is the heart of my question:  Is basic Django code (like in the poll 
tutoiral) supposed to render the same in different browsers? If the answer 
is 'Yes' this looks like a bug.  Thoughts?  

On Friday, December 5, 2014 11:19:37 AM UTC-5, Timothy Good wrote:
>
> Django Users,
>
> I am working through polls tutorial part 2 that enhances the admin page. 
>  Note that I did search for a solution in the recommended places but while 
> I saw similar complaints, none seemed to match exactly.
>  
> In poll tutorial 2 it says "At the end of the three current slots you 
> will find an “Add another Choice” link."  But this is not the case in 
> Chrome.
>
> If I view source in Chrome I see this function but the addText does not 
> appear.  (I am on the latest Chrome: Version 39.0.2171.71 (64-bit))  This 
> is in the source:
>
> 
>
> (function($) {
> $("#choice_set-group .tabular.inline-related tbody tr").tabularFormset({
> prefix: "choice_set",
> adminStaticPrefix: '/static/admin/',
> addText: "Add another Choice",
> deleteText: "Remove"
> });
> })(django.jQuery);
> 
>
>
>
>
> For the heck of it I gave it a try in Safari and it rendered just fine.
>
> Here is my code in admin.py:
>
> from django.contrib import admin
> from polls.models import Question, Choice
>
> class ChoiceInline(admin.TabularInline):
> model = Choice
> extra = 3
>
> class QuestionAdmin(admin.ModelAdmin):
> fieldsets = [
> (None,   {'fields': ['question_text']}),
> ('Date information', {'fields': ['pub_date'], 'classes': 
> ['collapse']}),
> ]
> inlines = [ChoiceInline]
>
> admin.site.register(Question, QuestionAdmin)
>
> Any thoughts or is this a known issue?
>
> Thanks,
> Tim
>
>
>
>
>
>
>  
>

-- 
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/e00baaef-353a-4226-9a43-e574d8c07622%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Web and mobile app with Django? Kivy? sth else?

2014-12-06 Thread Russell Keith-Magee
Hi Mariusz,

It depends how many sharp edges you're willing to live with. I've been
working on a project to allow users to develop native mobile apps in Python:

http://pybee.org/toga/

It's *very* early stage though - nothing close to production ready. There
isn't even really a tutorial for mobile development.

I hesitate mentioning it at all, other than to point out that it is
*possible*, and I'm looking into the space at the moment.

Yours,
Russ Magee %-)

On Fri, Dec 5, 2014 at 10:03 PM, Mariusz Wilk  wrote:

> Thanks for your advice!
> PhoneGap uses JS, HTML and CSS. Is there any way I could do this in Python
> or would it be unneccessarily complicated since maybe there's no
> PhoneGap-type-of-framework for Python?
>
>
> W dniu środa, 3 grudnia 2014 00:56:17 UTC użytkownik Cal Leeming napisał:
>>
>> Hi Mariusz,
>>
>> Short answer - Hack something together in the fastest way possible, don't
>> worry about it being clean, tidy or even tested. Because if you do, you'll
>> still be working on this project in 2 years time... Look at using something
>> like PhoneGap [8], just enjoy the experience and ship it :)
>>
>> If you genuinely want to start learning this stuff, you need to ask
>> yourself what it is you want to work on? Do you want to do backend (e.g.
>> all the server stuff, nothing visual), or do you want to do frontend (all
>> the visual/pretty stuff the user sees), or both? Are you doing this for
>> immediate financial gain [7], or a spiritual journey of self discovery and
>> learning [6]? The world of web dev is changing almost every couple of
>> months, stay on top of your game by reading blog articles from other
>> developers and keeping on top of tech new. Personally I use Feedly [9] to
>> aggregate these feeds into one place. Consider getting an internship
>> somewhere with other good programmers, learning from inspirational people
>> will speed up your personal development massively (I wish someone had told
>> me this 8 years ago).
>>
>> Long answer;
>>
>> Responsive/adaptive design does not necessarily make a good mobile
>> experience, and rarely will you find a mobile app which has the same
>> workflow as the website. Ideally you need to storyboard each experience and
>> wireframe the UX accordingly. Likewise with the UI, colors and sizes which
>> work well on desktop often won't work very well on mobile/tablet
>> (especially if you are designing your desktop site mostly towards PC users,
>> due to the variations in color display).
>>
>> There are tools out there now which allow you to package up your
>> HTML/JS/CSS/images into a native application bundle, meaning you don't have
>> to learn how to write native applications. There are a whole bunch of these
>> products out there [1], but most of them suck, here's why. Building a
>> client side JS application is *hard*, you have to understand the different
>> JS design patterns in order to write clean and stable code, whilst
>> understanding the importance of unit testing [3] and real browser testing
>> [4]. You also have to understand the impact of latency, if you don't
>> compile your assets into a local bundle (instead opting to just wrap a
>> browser window in an IOS app), then your app experience will lag between
>> clicks (because each click is a page load). To get around this you need to
>> build your client side app to be completely independent of the server side,
>> which includes maintaining a view state (e.g. changing/rendering the
>> display upon changes being made). Other libraries exist for doing this such
>> as Ember [5] and others, but they are still quite alpha and have
>> performance concerns too. Also in regards to bundling, there are very few
>> tools out there which will automate this entire process, for example
>> creating a spritesheet of UI images so you don't have to make multiple HTTP
>> asset requests, or embedding the images as base64 in your stylesheet
>> (although that has render performance concerns).
>>
>> Then you also have the API, building a clean RESTful api is difficult and
>> in actual fact may be the wrong approach for your mobile app.. why? Because
>> each API call has a lot of overhead, and this usually results in UI latency
>> if the user has poor signal. There is some work being done to use
>> websockets instead of ajax calls, but this starts to get into quite deep
>> territory.
>>
>> Gonna cut this short, as I try to limit myself to 30 minutes on any given
>> reply. Again don't worry too much about what I've put in the long answer,
>> that's just there to give you some insight into the things you'll start
>> thinking about as you get deeper into your journey.
>>
>> Hope this helps dude
>>
>> Cal
>>
>> [1] Google search for "app maker iphone"
>> [2] http://addyosmani.com/resources/essentialjsdesignpatterns/book/
>> [3] http://qunitjs.com/
>> [4] http://www.seleniumhq.org/
>> [5] http://emberjs.com/
>> [6] http://www.amazon.co.uk/The-Clean-Coder-Professional-
>> Programmers/dp/0137081073
>> [7] http

TypeError: unbound method save() must be called with NagiosLog instance as first argument (got nothing instead)

2014-12-06 Thread Phil F
Hi,

I am attempting to write a python script that will populate the Django db 
from data stored in a dictionary.

I'm currently getting the error :"TypeError: unbound method save() must be 
called with NagiosLog instance as first argument (got nothing instead)"

from incidents.models import NagiosLog
import django
xcount = 0

for k,v in myDic.items():
iincidentnumber = k
itime =v[0]
idevice =v[2]
iservice =v[3]
iseverity =v[4]
imessage =v[5]
print "%r %r %r %r %r" % (itime,idevice,iservice,iseverity,imessage,) 
 ## prints successfully, code working until here
xcount= xcount+1
if xcount == 1:   # count to run django setup a single time
django.setup()
k = NagiosLog(
incident = iincidentnumber,
time = itime,
device = idevice,
service = iservice,
severity = iseverity,
message = imessage,)
NagiosLog.save()
else:
k = NagiosLog(
incident = iincidentnumber,
time = itime,
device = idevice,
service = iservice,
severity = iseverity,
message = imessage,)
NagiosLog.save()

This is my models file:

from django.db import models

from django.utils import timezone
import datetime

class NagiosLog(models.Model):
incident= models.CharField(primary_key=True, max_length=80)
time= models.CharField(max_length=80, blank=True, null=True)
device  = models.CharField(max_length=80, blank=True, null=True)
service = models.CharField(max_length=80, blank=True, null=True)
severity= models.CharField(max_length=20, blank=True, null=True)
message = models.CharField(max_length=250, blank=True, 
null=True)

Any help appreciated !

Thanks, Phil.

-- 
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/1cc3eda3-d180-430e-8e41-866dceb0bca2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Web and mobile app with Django? Kivy? sth else?

2014-12-06 Thread graeme
If you want to do everything in Python (which I like to) my choices would 
be Django for the backend, Kivy for the mobile apps, and Django Rest 
Framework to provide APIs for the mobile apps.

If you want to keep it simpler maybe a responsive web design will be 
enough, so you only need Django, HTML, CSS and JS.

Using a JS framework on the front end (e.g. JQuery) also makes your life 
simpler.

I can understand Django looking scary at the start, but remember that there 
is a lot of documentation because Django does a LOT, and that makes your 
life easier. Learning Django may look difficult, but it is less effort than 
all the work it saves you.



On Friday, November 21, 2014 8:26:38 PM UTC+5:30, Mariusz Wilk wrote:
>
> I'm new to programming. Eventually, I'd like to make a website and an 
> android/ios app that would work together and display pretty much the same 
> content on a mobile as on the the web. Each client would log in (via mobile 
> or desktop) and continue solving some exercises from the place he 
> previously finished at. I have a potential client for this app, I don't 
> have any deadline and if it works fine I shouldn't have any problems 
> selling it to him and getting some commercial experience! So my question 
> is: *what should I be learning to eventually reach this goal?* I've done 
> a few Python tutorials/courses online, I played around with HTML, CSS and 
> JS, right now I'm learning Kivy. Django scared me a lot, but maybe I should 
> give it another try.
>

-- 
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/55e47bcc-ace1-448d-b938-9289c3e1a9f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set choice limit of given number on ModelMultipleChoiceField in Django?

2014-12-06 Thread Collin Anderson
Hi,

Are you saying you have a ForeignKey choice field on the same form (above 
the ManyToMany), and when you change the choice field it should change the 
available values in the ManyToMany?

Collin

On Thursday, December 4, 2014 7:20:13 PM UTC-5, inoyon artlover KLANGRAUSCH 
wrote:
>
> Very cool! :) Many thanks, once more! :) Could be off-topic, but there is 
> somethin more tricky:
> Before a ManyToManyField there is one ForeignKeyField which has few of the 
> same values. 
> So the ForeignKey-value has to be excluded from the ManyToMany choices. 
> For example 
> the ForeignKey selection (labeld as: additional values) could trigger on 
> submit a queryset and 
> a view colud display the filterd ManyToManyField... (btw. I am very new to 
> python/django so..
> try'n error is the tedious way to go since two month... )
>
>
> Am Freitag, 5. Dezember 2014 00:52:18 UTC+1 schrieb larry@gmail.com:
>>
>> On Thu, Dec 4, 2014 at 6:46 PM, inoyon artlover KLANGRAUSCH 
>>  wrote: 
>> > Great, it works with one form but not with an another... 
>> > Btw. how is it possible to overwrite the 'this field is required' error 
>> > message? 
>>
>> You can provide your custom set of default errors to the form field 
>> definition, e.g.: 
>>
>> my_default_errors = { 
>> 'required': 'You better enter this field!', 
>> 'invalid': 'You can do better than that!' 
>> } 
>>
>> class MyForm(forms.Form): 
>> some_field = forms.CharField(error_messages=my_default_errors) 
>>
>>
>> > 
>> > Many thanks and best regards! :) 
>> > 
>> > Am Donnerstag, 4. Dezember 2014 23:01:15 UTC+1 schrieb 
>> larry@gmail.com: 
>> >> 
>> >> On Thu, Dec 4, 2014 at 4:54 PM, inoyon artlover KLANGRAUSCH 
>> >>  wrote: 
>> >> > Hi there, I got a following Form-Class: 
>> >> > 
>> >> > 
>> >> > class CustomUserprofileInterestsForm(forms.ModelForm): 
>> >> > 
>> >> > interests = forms.ModelMultipleChoiceField( 
>> >> > queryset=Interests.objects.all(), 
>> >> > widget=forms.CheckboxSelectMultiple) 
>> >> > 
>> >> > 
>> >> > I want to limit the choices for example to 6 of all displayed. 
>> >> > Is it possible with some optional arguments I don't know somehow? 
>> >> > 
>> >> 
>> >> You can write your own clean method on the form, e.g.: 
>> >> 
>> >> def clean_interests(self): 
>> >> value = self.cleaned_data['interests'] 
>> >> if len(value) > 6: 
>> >> raise forms.ValidationError("You can't select more than 6 
>> items.") 
>> >> return value 
>>
>

-- 
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/81e82dad-a704-4008-b25f-207f5a5f3de4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem Making New Django project - please help

2014-12-06 Thread Collin Anderson
Hi,

Is your DJANGO_SETTINGS_MODULE set in your environment? You may need to 
clear that out before running django-admin.py

Something like one of these:

unset DJANGO_SETTINGS_MODULE
DJANGO_SETTINGS_MODULE= django-admin.py startproject
env -u DJANGO_SETTINGS_MODULE django-admin.py startproject

Collin


On Friday, December 5, 2014 1:56:34 AM UTC-5, Shashwat singh wrote:
>
> No , it used to work perfectly on osx mavericks, then i did some stuff 
> with opencv and since then i'm getting that error. I've tried each n every 
> solution available on internet but nothing seems to solve that problem :/
>

-- 
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/88684107-aa88-4ab1-ab32-58416cb05f7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django development server crash on syntactic or indent error after check

2014-12-06 Thread Collin Anderson
Hi,

Yes, this happens to me frequently. It happens when editing models.py or 
something imported by a models.py. It's on my mental dream list of things 
to fix, but feel free to open a ticket about it if there's not one open 
already.

Collin

On Friday, December 5, 2014 2:00:01 AM UTC-5, Mario De Frutos Dieguez wrote:
>
> If i understand you correctly, when an error occur the server should not 
> stop, instead of that it will print the error trace to let you correct the 
> problem but in my case when an error occur the server show the trace and 
> stop working or at least it returns to the shell. :S
>
> What i understand reading the official docuementation is that the expected 
> behavior is not to exit instead of that the server should show the error 
> trace to let you fix it
>
> Am i right?
>

-- 
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/d1c07e3b-f84e-497d-86ba-919dadeb9052%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django development server crash on syntactic or indent error after check

2014-12-06 Thread Collin Anderson
It happens if there's a SyntaxError in a models.py file.

On Saturday, December 6, 2014 12:32:17 PM UTC-5, Collin Anderson wrote:
>
> Hi,
>
> Yes, this happens to me frequently. It happens when editing models.py or 
> something imported by a models.py. It's on my mental dream list of things 
> to fix, but feel free to open a ticket about it if there's not one open 
> already.
>
> Collin
>
> On Friday, December 5, 2014 2:00:01 AM UTC-5, Mario De Frutos Dieguez 
> wrote:
>>
>> If i understand you correctly, when an error occur the server should not 
>> stop, instead of that it will print the error trace to let you correct the 
>> problem but in my case when an error occur the server show the trace and 
>> stop working or at least it returns to the shell. :S
>>
>> What i understand reading the official docuementation is that the 
>> expected behavior is not to exit instead of that the server should show the 
>> error trace to let you fix it
>>
>> Am i right?
>>
>

-- 
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/19594cbd-3a93-4208-9d24-bf1575c12136%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error: 'NoneType' object has no attribute 'strip'

2014-12-06 Thread Collin Anderson
Hi,

Does this work? (What you've already tried, but not using autoslug at all.)

from django.utils.text import slugify

slug = models.SlugField(null=True, blank=True)
def save(self, *args, **kwargs):
self.slug = slugify(self.name or '')
super(Shop, self).save(*args, **kwargs)

If you have a "pretty" django traceback, you can click to expand where it 
says "▶ Local vars".

Collin


On Friday, December 5, 2014 8:55:06 AM UTC-5, Danish Ali wrote:
>
> If I remove slug code, then everything works fine. 
> And can you tell me how can I expand the variables?
>
> Thanks 
>
> On Fri, Dec 5, 2014 at 6:51 PM, Collin Anderson  > wrote:
>
>> Hi,
>>
>> If you remove all the slug code do you still get this error? If so, then 
>> the error has nothing to do with automatically creating a slug.
>>
>> Try expanding Local vars to see what "params" and "sql are.
>> File "e:\python\lib\site-packages\django\db\models\sql\compiler.py" in 
>> execute_sql
>>   920. cursor.execute(sql, params)
>> File "e:\python\lib\site-packages\django\db\backends\utils.py" in execute
>>   85. sql = self.db.ops.last_executed_query(self.cursor, sql, 
>> params)
>>
>> This does seem like a bug in mysql-connector. You may want to bring it up 
>> on the mysql-connector list. http://forums.mysql.com/list.php?50
>>
>> You could also try using mysqlclient instead to see if you still have the 
>> problem. That's django's recommended connector.
>> https://pypi.python.org/pypi/mysqlclient
>> https://docs.djangoproject.com/en/dev/ref/databases/#mysql-db-api-drivers
>>
>> Collin
>>
>> On Wednesday, December 3, 2014 3:33:48 PM UTC-5, Danish Ali wrote:
>>>
>>> so is there anyway to create slug automatically other than this ?
>>>
>>> On Thu, Dec 4, 2014 at 1:29 AM, donarb  wrote:
>>>
 On Wednesday, December 3, 2014 11:59:42 AM UTC-8, Danish Ali wrote:
>
> this is stacktrace when I use: slug = AutoSlugField(populate_from='name') 
> in my model 
>
>
> Environment:
>
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/admin/product/shop/add/
>
> Django Version: 1.7.1
> Python Version: 3.4.2
> Installed Applications:
> ('django.contrib.admin',
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'product')
> Installed Middleware:
> ('django.contrib.sessions.middleware.SessionMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
>  'django.middleware.clickjacking.XFrameOptionsMiddleware')
>
>
> Traceback:
> File "e:\python\lib\site-packages\django\core\handlers\base.py" in 
> get_response
>   111. response = wrapped_callback(request, 
> *callback_args, **callback_kwargs)
> File "e:\python\lib\site-packages\django\contrib\admin\options.py" in 
> wrapper
>   584. return self.admin_site.admin_view(view)(*args, 
> **kwargs)
> File "e:\python\lib\site-packages\django\utils\decorators.py" in 
> _wrapped_view
>   105. response = view_func(request, *args, 
> **kwargs)
> File "e:\python\lib\site-packages\django\views\decorators\cache.py" 
> in _wrapped_view_func
>   52. response = view_func(request, *args, **kwargs)
> File "e:\python\lib\site-packages\django\contrib\admin\sites.py" in 
> inner
>   204. return view(request, *args, **kwargs)
> File "e:\python\lib\site-packages\django\contrib\admin\options.py" in 
> add_view
>   1454. return self.changeform_view(request, None, form_url, 
> extra_context)
> File "e:\python\lib\site-packages\django\utils\decorators.py" in 
> _wrapper
>   29. return bound_func(*args, **kwargs)
> File "e:\python\lib\site-packages\django\utils\decorators.py" in 
> _wrapped_view
>   105. response = view_func(request, *args, 
> **kwargs)
> File "e:\python\lib\site-packages\django\utils\decorators.py" in 
> bound_func
>   25. return func.__get__(self, type(self))(*args2, 
> **kwargs2)
> File "e:\python\lib\site-packages\django\db\transaction.py" in inner
>   394. return func(*args, **kwargs)
> File "e:\python\lib\site-packages\django\contrib\admin\options.py" in 
> changeform_view
>   1405. self.save_model(request, new_object, form, not 
> add)
> File "e:\python\lib\site-packages\django\contrib\admin\options.py" in 
> save_model
>   1046. obj.save()
> File "e:\python\lib\site-packages

Re: ManyToManyField with rating using 'through' on each ManyToMany relation in Django

2014-12-06 Thread Collin Anderson
Hi,

To limit the number or rows in an inline, max_num is usually the way to go.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.max_num

As far as having the list of all possibilities available as options goes, 
it gets a little more complicated and I don't think it's something the 
admin really handles out of the box. You're starting to get to a 
complicated enough case where it might make sense to roll your view and 
form code.

It might be possible to do it with a custom form and the proper "initial" 
argument to your formset.

Collin

On Friday, December 5, 2014 9:41:46 AM UTC-5, inoyon artlover KLANGRAUSCH 
wrote:
>
> Did it in this fashion:
>
> models.py
>
> class Interests(models.Model): 
>
> ORDER = [(y, y) for y in range(10, 200, 10)] interest = models.CharField( 
> verbose_name='Interesse', max_length=40) interest_order = 
> models.SmallIntegerField(default=None, choices=ORDER) interest_active = 
> models.BooleanField(default=False)
>
>  class Meta:
> verbose_name_plural = 'Interessen'
> ordering = ['interest']
>
>  def __str__(self):
> return self.interest
>
> class Sports(models.Model): ORDER = [(y, y) for y in range(10, 200, 10)] 
> sport = models.CharField(verbose_name='Sportart', max_length=40) 
> sport_order = models.SmallIntegerField(default=None, choices=ORDER) 
> sport_active = models.BooleanField(default=False)
>
> class Meta:
> verbose_name_plural = 'Sportarten'
> ordering = ['sport']
>
> def __str__(self):
> return self.sport
>
> class CustomUserprofileInterests(models.Model): user = 
> models.OneToOneField(User) interests = models.ManyToManyField( Interests, 
> through='CustomInterests', through_fields=('custominterest', 'interest'), 
> verbose_name='Interessen', null=True, blank=True)
>
> sports = models.ManyToManyField( Sports, through='CustomSports', 
> verbose_name='Sportarten', null=True, blank=True)
>
> class Meta: verbose_name_plural = 'Interessensprofil'
>
> def get_full_name(self):
> return self.user
>
> def get_short_name(self):
> return self.user
>
> def __str__(self):
> return '{0} | {1}'.format(self.user, 'Interessensprofil')
>
> class CustomInterests(models.Model):
>
> WEIGHT = [(y, y) for y in range(1, 7)]
>
> interest = models.ForeignKey(Interests)
> custominterest = models.ForeignKey(CustomUserprofileInterests)
> # interested = models.BooleanField(default=False)
> rating = models.SmallIntegerField(choices=WEIGHT)
>
> class CustomSports(models.Model):
>
> WEIGHT = [(y, y) for y in range(0, 7)]
>
> sport = models.ForeignKey(Sports)
> custominterest = models.ForeignKey(CustomUserprofileInterests)
> # interested = models.BooleanField(default=False)
> rating = models.SmallIntegerField(choices=WEIGHT)
>
> AND THE admin.py
>
> class CustomProfile(admin.StackedInline): model = models.CustomUserprofile 
> can_delete = False verbose_name_plural = 'Nutzerprofile'
>
> class CustomUserAdmin(UserAdmin): inlines = (CustomProfile,)
>
> class CustomInterestsInline(admin.TabularInline): model = 
> models.CustomInterests extra = 9
>
> class CustomSportsInlilne(admin.TabularInline): model = 
> models.CustomSports extra = 9
>
> admin.site.register(models.Interests) admin.site.register(models.Sports) 
> admin.site.register(models.CustomUserprofileInterests) 
> admin.site.register(models.CustomInterests) 
> admin.site.register(models.CustomSports) 
> admin.site.register(models.CustomUserprofileInterests, 
> CustomUserprofileAdmin)
>
> The nexts steps I want to accomplish:
>
> A form for users, they can create/edit the profile. The 'interests' and 
> 'sports' columns have to be prepopulated with all available (declared by 
> 'active' with a Boolean) entries in the interests/sports table. If a user 
> has an 'interest' or 'sports', he/she selects it (checkbox) and rates the 
> entry.
>
> Also the amount of entries to be selected by the user is limited to a 
> defined amount (i.e. 6 or 10) (here would be form validation best practice?)
>
>
> Am Freitag, 5. Dezember 2014 15:00:01 UTC+1 schrieb Collin Anderson:
>>
>> Hi,
>>
>> Create an admin Inline like this:
>>
>> class CustomInterestsInline(admin.TabularInline):
>> model = CustomInterests
>>
>> class CustomUserprofileInterests(admin.ModelsAdmin):
>> inlines = [CustomInterestsInline]
>>
>> Collin
>>
>>
>> On Thursday, December 4, 2014 5:58:31 AM UTC-5, inoyon artlover 
>> KLANGRAUSCH wrote:
>>>
>>> I am very beginner in the programming world, so please forgive my lack 
>>> of understanding...
>>> There is a CustomUserprofile in my models.py.. nothin very special about 
>>> this... 
>>>
>>> class Interests(models.Model):
>>>
>>> RATING = [(y, y) for y in range(1, 7)]
>>>
>>> interest = models.CharField(max_length=40)
>>> interest_rating = models.SmallIntegerField(choices=WEIGHT)
>>>
>>>
>>> class CustomUserprofileInterests(models.Model):
>>>
>>> user = models.OneToOneField(User)
>>> interests = models.ManyToManyField(
>>>

Re: post_save strange behavior (at least to me!)

2014-12-06 Thread Collin Anderson
Hi Vittorio,

ManyToMany fields are technically stored in a separate table in the 
database and are technically a separate "record" from the parent model. The 
parent model needs to be saved first (firing the post_save signal), and 
only then can the ManyToMany values be updated.

I'd override the save_model() or save_related() methods of ItemOptions.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_related

Collin


On Friday, December 5, 2014 11:01:26 AM UTC-5, vittorio wrote:
>
> Django 1.7.1 and Apache2 in a production context. 
>  I have the following situation 
> = 
> models.py 
>
> class Items(models.Model): 
> code = 
> models.CharField(primary_key=True,db_index=True,unique=True,max_length=20,db_column='code')
>  
>
> description = models.CharField(max_length=255) 
> supplier=models.ManyToManyField(Suppliers) 
> class Meta: 
> db_table = u'items' 
> post_save.connect(ItemSaveInAnotherDB, sender=Items, 
> dispatch_uid="save_in_another_db") 
>
> class Suppliers(models.Model): 
> name = models.CharField(max_length=150, db_column='name', 
> db_index=True) 
> address = models.CharField(max_length=255, db_column='address', 
> blank=True,null=True) 
> class Meta: 
> db_table = u'suppliers' 
> = 
> admin.py 
>
> class ItemsOption(admin.ModelAdmin): 
> search_fields=[('code','description', ('supplier')] 
> fields=('code','description') 
> filter_horizontal = ['supplier', ] 
> = 
> signals.py 
>
> def ItemSaveInAnotherDB(sender, instance, **kwargs): 
>  
>  
> sup = instance.supplier.all() 
> print 'SUPPLIERS LIST' 
> for s in sup: 
> print s.name 
>  
>  
> return 
> = 
>
>
> Let's suppose that I have an item with one supplier only: Donald Duck. 
> 1) Now in the admin change form I add another supplier to the 
> ManyToManyField, say 'Goofy',  to the same item and click on save. 
> Well the  ItemSaveInAnotherDB post_save signal shows the previous 
> situation only 
>
> SUPPLIERS LIST 
> Donald Duck 
>
> 2) But if in the change form, containing as before Donald Duck and Goofy, 
> I click again on save (without changing anything, I mean) 
> the  ItemSaveInAnotherDB signals shows correctly 
>
> SUPPLIERS LIST 
> Donald Duck 
> Goofy 
>
> I thought that the post_save signal in case 1) acted on the already saved 
> record therefore in my poor opinion it should have shown both Donald Duck 
> and Goofy. 
> Instead only re-saving the record the post_save signal as in case 2) 
> it works correctly. 
>
> How can I avoid this and have the more updated list available at first 
> shot? 
>
> Ciao 
> Vittorio 
>
>
>
>
>
>
>
>

-- 
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/6184a3f1-0fa8-464f-929e-a15afbfbc5d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Does ticket 19866 apply to Django 1.4

2014-12-06 Thread Collin Anderson
Hi Brian,

If you're behind nginx, you can filter the hostname there before it hits 
django. I usually add an empty server {} block at the beginning of my conf 
to act as the default and catch server host names that are not defined so 
they don't hit django.

Collin

On Friday, December 5, 2014 12:15:41 AM UTC-5, yakka...@gmail.com wrote:
>
> Does ticket 19866  apply to 
> Django 1.4? Reading through the notes, it seems it does but I'm still 
> getting a 500 error. If not, is there a way to keep Django from returning a 
> 500 error.  I've found other people filtering these out.  I don't want to 
> filter them out. 
>
>
>  I've got some hackers trying to exploit the wordpress /xmlrpc.php on my 
> Django site. Most of the time they are coming back 404 but there are times 
> I'm getting exceptions like:
>
> ---Traceback (most recent call last):
>
>   File 
> "/usr/local/python2p7/lib/python2.7/site-packages/django/core/handlers/base.py",
>  line 87, in get_response
> response = middleware_method(request)
>
>   File 
> "/usr/local/python2p7/lib/python2.7/site-packages/django/middleware/common.py",
>  line 55, in process_request
> host = request.get_host()
>
>   File 
> "*/usr/local/python2p7/lib/python2.7/site-packages/django/http/*__init__.py", 
> line 223, in get_host
> "Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
>
> SuspiciousOperation: Invalid HTTP_HOST header (you may need to set 
> ALLOWED_HOSTS) path:/wp/xmlrpc.php,
> ...
>  'HTTP_USER_AGENT': 'LWP::Simple/6.00 libwww-perl/6.04',
>
> ...
>
>
>  'REQUEST_URI': '/wp/xmlrpc.php',
>
>
>  ---
>
>
>  Brian
>

-- 
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/f66401b5-5f94-4d5d-be77-88ac89eb8890%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django-ckeditor noop?

2014-12-06 Thread Collin Anderson
Hi,

That should work.

Did you restart the server?

Are you using CKEDITOR_RESTRICT_BY_USER?

Is "ckeditor" in the source of the page at all?

Are there errors on the javascript console?

What does your admin.py look like?

Collin


On Friday, December 5, 2014 1:09:59 PM UTC-5, Jonathan Hayward wrote:
>
> At 
> http://stackoverflow.com/questions/27321396/how-can-i-get-my-django-ckeditor-installation-to-recognize
>  
> I asked what I could do to get a RichTextField() to be displayed with a 
> CKeditor widget.
>
> Any advice for what I should change?
>
> Thanks,
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eff72a7b-fc25-49fd-abba-2a175259b1f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking for advise on usage MySQL together with MongoDB

2014-12-06 Thread Collin Anderson
Hi,

What do you mean by "parsing with updating of products"?

I'd personally store everything in authoritatively in that 1 generalized 
table and get rid of the 10 smaller tables. Have a "manufacturer" CharField 
or ForeignKey to determine what fields are available and other custom 
logic. As you mention, the one table is very helpful for search especially. 
You don't need to copy data between tables.

But I totally agree with Russ:
If performance is your goal, check out PostgreSQL.
If schema-less is what you are hoping for, try PostgreSQL hstore.

I also have tried mongodb with django many years ago and it didn't work 
well, but we're working on making django play better with non-sql databases.

Collin

On Friday, December 5, 2014 7:56:57 AM UTC-5, Artie wrote:
>
> Good day, Community,
>
> I'm looking for advise on MySQL & MongoDB usage so please let me take your 
> time to describe the situation.
>
> I came to work on e-commerce shop of electrical components with about 10 
> millions of products. Now all of it stored in awful structure of tables in 
> MySQL. Products stored in 10 small tables, each of them represents 
> individual manufacturer of products and 1 generalized table, where all 10 
> millions of goods is stored. Those big table serves Sphinx search to 
> implement search on site.
> All these products being crawled from several APIs and sites on web, so 
> this shop is kind of authorized reseller in our region.
>
> The case is that we have to update all products daily and  parsing with 
> updating of products takes very long time.
>
> I have an idea to start using MongoDB to update and store products and as 
> I think it might take less time than same in MySQL. First question: Am I 
> correct with this statement?
>
> Browsing web I've found that some recommend using pymongo, avoiding django 
> rather than mongodb for django. So for your opinion is this statement 
> correct?
>
> Also it will be highly highly appreciated if you can share your personal 
> use experience with MongoDB and any information you think be useful.
>
> Thank you in advance
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a16cc8c6-e6e3-4fb4-96b2-3636239bf5bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error: 'NoneType' object has no attribute 'strip'

2014-12-06 Thread Danish Ali
No. It also did not work. It was also giving similar error.

On Saturday, December 6, 2014, Collin Anderson  wrote:

> Hi,
>
> Does this work? (What you've already tried, but not using autoslug at all.)
>
> from django.utils.text import slugify
>
> slug = models.SlugField(null=True, blank=True)
> def save(self, *args, **kwargs):
> self.slug = slugify(self.name or '')
> super(Shop, self).save(*args, **kwargs)
>
> If you have a "pretty" django traceback, you can click to expand where it
> says "▶ Local vars".
>
> Collin
>
>
> On Friday, December 5, 2014 8:55:06 AM UTC-5, Danish Ali wrote:
>>
>> If I remove slug code, then everything works fine.
>> And can you tell me how can I expand the variables?
>>
>> Thanks
>>
>> On Fri, Dec 5, 2014 at 6:51 PM, Collin Anderson 
>> wrote:
>>
>>> Hi,
>>>
>>> If you remove all the slug code do you still get this error? If so, then
>>> the error has nothing to do with automatically creating a slug.
>>>
>>> Try expanding Local vars to see what "params" and "sql are.
>>> File "e:\python\lib\site-packages\django\db\models\sql\compiler.py" in
>>> execute_sql
>>>   920. cursor.execute(sql, params)
>>> File "e:\python\lib\site-packages\django\db\backends\utils.py" in
>>> execute
>>>   85. sql = self.db.ops.last_executed_query(self.cursor, sql
>>> , params)
>>>
>>> This does seem like a bug in mysql-connector. You may want to bring it
>>> up on the mysql-connector list. http://forums.mysql.com/list.php?50
>>>
>>> You could also try using mysqlclient instead to see if you still have
>>> the problem. That's django's recommended connector.
>>> https://pypi.python.org/pypi/mysqlclient
>>> https://docs.djangoproject.com/en/dev/ref/databases/#
>>> mysql-db-api-drivers
>>>
>>> Collin
>>>
>>> On Wednesday, December 3, 2014 3:33:48 PM UTC-5, Danish Ali wrote:

 so is there anyway to create slug automatically other than this ?

 On Thu, Dec 4, 2014 at 1:29 AM, donarb  wrote:

> On Wednesday, December 3, 2014 11:59:42 AM UTC-8, Danish Ali wrote:
>>
>> this is stacktrace when I use: slug = AutoSlugField(populate_from='name')
>> in my model
>>
>>
>> Environment:
>>
>>
>> Request Method: POST
>> Request URL: http://127.0.0.1:8000/admin/product/shop/add/
>>
>> Django Version: 1.7.1
>> Python Version: 3.4.2
>> Installed Applications:
>> ('django.contrib.admin',
>>  'django.contrib.auth',
>>  'django.contrib.contenttypes',
>>  'django.contrib.sessions',
>>  'django.contrib.messages',
>>  'django.contrib.staticfiles',
>>  'product')
>> Installed Middleware:
>> ('django.contrib.sessions.middleware.SessionMiddleware',
>>  'django.middleware.common.CommonMiddleware',
>>  'django.middleware.csrf.CsrfViewMiddleware',
>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>  'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
>>  'django.contrib.messages.middleware.MessageMiddleware',
>>  'django.middleware.clickjacking.XFrameOptionsMiddleware')
>>
>>
>> Traceback:
>> File "e:\python\lib\site-packages\django\core\handlers\base.py" in
>> get_response
>>   111. response = wrapped_callback(request,
>> *callback_args, **callback_kwargs)
>> File "e:\python\lib\site-packages\django\contrib\admin\options.py"
>> in wrapper
>>   584. return self.admin_site.admin_view(view)(*args,
>> **kwargs)
>> File "e:\python\lib\site-packages\django\utils\decorators.py" in
>> _wrapped_view
>>   105. response = view_func(request, *args,
>> **kwargs)
>> File "e:\python\lib\site-packages\django\views\decorators\cache.py"
>> in _wrapped_view_func
>>   52. response = view_func(request, *args, **kwargs)
>> File "e:\python\lib\site-packages\django\contrib\admin\sites.py" in
>> inner
>>   204. return view(request, *args, **kwargs)
>> File "e:\python\lib\site-packages\django\contrib\admin\options.py"
>> in add_view
>>   1454. return self.changeform_view(request, None, form_url,
>> extra_context)
>> File "e:\python\lib\site-packages\django\utils\decorators.py" in
>> _wrapper
>>   29. return bound_func(*args, **kwargs)
>> File "e:\python\lib\site-packages\django\utils\decorators.py" in
>> _wrapped_view
>>   105. response = view_func(request, *args,
>> **kwargs)
>> File "e:\python\lib\site-packages\django\utils\decorators.py" in
>> bound_func
>>   25. return func.__get__(self, type(self))(*args2,
>> **kwargs2)
>> File "e:\python\lib\site-packages\django\db\transaction.py" in inner
>>   394. return func(*args, **kwargs)
>> File "e:\python\lib\site-packages\django\contrib\admin\options.py"
>> in changeform_view
>>   1405.   

Bug in staticfiles' HashedFileMixin?

2014-12-06 Thread Bernhard Mäder
Hey guys,

HashedFileMixin's pattern variable looks like it could be extended for 
other file types:

class HashedFilesMixin(object):
default_template = """url("%s")"""
patterns = (
("*.css", (
r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""",
(r"""(@import\s*["']\s*(.*?)["'])""", """@import url("%s")"""),
)),
)


But - if I read the code right - it can't. Because in post_process, the 
patterns are applied to all files matched by any of the extensions. 

What I like to be able to achieve is get cache busting in some of my js 
files as well. I marked all static file references in my code with a 
'staticFile()' call and then tried to customize django's 
CachedStaticFilesStorage like this:

class MyCachedStaticFilesStorage(django.contrib.staticfiles.storage.
CachedStaticFilesStorage):
patterns = django.contrib.staticfiles.storage.HashedFilesMixin.patterns 
+ (
(u'*.js', [
(r"""(staticFile\(['"]{0,1}\s*(.*?)["']{0,1}\))""", r
"""staticFile("%s")""", )
]),
)


As of today, that won't work, since all CSS rules are applied to my JS, 
too, which causes some stuff to be replaced that shouldn't.

Is this a bug, and should I file a bug report? Is it worth fixing? How else 
can I get cache busting into JS files?

Thanks,
Bernhard
 

-- 
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/2e94c2f3-5c91-4bb7-80fb-c40bdbb3b636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking for advise on usage MySQL together with MongoDB

2014-12-06 Thread Cal Leeming
Hi Artie,

First, I would strongly recommend reading some of the work by David Mytton
at Server Density, he and his team have been using MongoDB extensively for
many years and they have shared a lot of their insight [1]. It's also worth
mentioning that Postgres has support for JSON field type [2] which
satisfies many of the use cases for document store, though I haven't
finished my own experiments yet so can't comment on comparative
performance/functionality.

It's industry knowledge that MySQL is bleeding out, rapidly [3] [4]. At
this point, I introduce you to Monty and his creation MariaDB [5]. Although
I would agree with Russell on many of the points he's made about MySQL,
it's hard not to have respect for the work that Monty and his team have
done previously on MySQL, and the vision that is now MariaDB. I would
strongly recommend you spend some time looking into this yourself, read as
many comparison articles as your eyes will allow, and come to your own
conclusions.

I have built numerous "large scale" systems with a variety of
technologies.. Sphinx, ElasticSearch, MongoDB, MySQL, CouchBase, Redis.
I've also spent many years battling with MongoEngine and have learnt to
hate it, as much as I now hate the Django ORM. So, unless you are edging
towards terabytes of data, assuming you are using SSDs and high memory
nodes, then the impact of your choice will probably be negligible. And if
you are using the Django ORM, then you are even less likely to reap any of
these benefits out of the box [6] There are many different reasons for
choosing one over the over, and you should assess this based on your own
use case/needs/skills, rather than religious bias.

Determine your use case and test all viable options, otherwise you could be
avoiding something for the wrong reasons. You can build *beautiful* things
with all these different technologies, and it's actually the mindset which
matters the most [7]. Don't just settle for what others are telling you,
try for yourself and come to your own conclusions, only then can you be
sure. It's also a good way to gain in-depth knowledge about how these
technologies work, which can be invaluable.

Cal


[1] https://blog.serverdensity.com/mongodb/
[2] http://www.postgresql.org/docs/9.3/static/datatype-json.html
[3] http://www.theregister.co.uk/2012/11/29/monty_oracle_eu_promises/
[4]
http://www.computing.co.uk/ctg/news/2271011/mysql-creator-monty-widenius-wants-it-to-disappear-from-the-earth
[5] http://www.themukt.com/2014/09/11/reason-use-mysql-michael-widenius/
[6] https://news.ycombinator.com/item?id=4076834
[7]
http://www.amazon.co.uk/The-Clean-Coder-Professional-Programmers/dp/0137081073



On Sat, Dec 6, 2014 at 12:26 AM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

>
> On Fri, Dec 5, 2014 at 8:56 PM, Artie  wrote:
>
>> Good day, Community,
>>
>> I'm looking for advise on MySQL & MongoDB usage so please let me take
>> your time to describe the situation.
>>
>> I came to work on e-commerce shop of electrical components with about 10
>> millions of products. Now all of it stored in awful structure of tables in
>> MySQL. Products stored in 10 small tables, each of them represents
>> individual manufacturer of products and 1 generalized table, where all 10
>> millions of goods is stored. Those big table serves Sphinx search to
>> implement search on site.
>> All these products being crawled from several APIs and sites on web, so
>> this shop is kind of authorized reseller in our region.
>>
>> The case is that we have to update all products daily and  parsing with
>> updating of products takes very long time.
>>
>> I have an idea to start using MongoDB to update and store products and as
>> I think it might take less time than same in MySQL. First question: Am I
>> correct with this statement?
>>
>> Browsing web I've found that some recommend using pymongo, avoiding
>> django rather than mongodb for django. So for your opinion is this
>> statement correct?
>>
>> Also it will be highly highly appreciated if you can share your personal
>> use experience with MongoDB and any information you think be useful.
>>
>
> Hi Artie,
>
> Can I make an alternate suggestion? Get a real database.
>
> In all honesty, I've never heard anyone in the Django community express a
> deep love of MySQL or MongoDB. I know people who use MySQL, but when they
> admit that, they say "Yeah, I know, but the customer required it" or "Yeah,
> I know, but at the time we started it was the only thing Amazon supported".
> As for MongoDB, the sentiment is usually "... and that was our first
> mistake.".
>
> Personally - I have very little time for MySQL. It gets a number of key
> design decisions wrong (for example, InnoDB's implementation of row
> referential integrity is *demonstrably* incorrect). It has some default
> behaviours that beggar belief (e.g., on MyISAM, by default, a row with a
> "WHERE field IS NULL" clause that matches no results, and the previous
> statement was an insert, the query

Re: TypeError: unbound method save() must be called with NagiosLog instance as first argument (got nothing instead)

2014-12-06 Thread Vijay Khemlani
Call

k.save()

instad of

NagiosLog.save()



On Sat, Dec 6, 2014 at 8:26 AM, Phil F  wrote:

> Hi,
>
> I am attempting to write a python script that will populate the Django db
> from data stored in a dictionary.
>
> I'm currently getting the error :"TypeError: unbound method save() must be
> called with NagiosLog instance as first argument (got nothing instead)"
>
> from incidents.models import NagiosLog
> import django
> xcount = 0
>
> for k,v in myDic.items():
> iincidentnumber = k
> itime =v[0]
> idevice =v[2]
> iservice =v[3]
> iseverity =v[4]
> imessage =v[5]
> print "%r %r %r %r %r" % (itime,idevice,iservice,iseverity,imessage,)
>  ## prints successfully, code working until here
> xcount= xcount+1
> if xcount == 1:   # count to run django setup a single time
> django.setup()
> k = NagiosLog(
> incident = iincidentnumber,
> time = itime,
> device = idevice,
> service = iservice,
> severity = iseverity,
> message = imessage,)
> NagiosLog.save()
> else:
> k = NagiosLog(
> incident = iincidentnumber,
> time = itime,
> device = idevice,
> service = iservice,
> severity = iseverity,
> message = imessage,)
> NagiosLog.save()
>
> This is my models file:
>
> from django.db import models
>
> from django.utils import timezone
> import datetime
>
> class NagiosLog(models.Model):
> incident= models.CharField(primary_key=True, max_length=80)
> time= models.CharField(max_length=80, blank=True,
> null=True)
> device  = models.CharField(max_length=80, blank=True,
> null=True)
> service = models.CharField(max_length=80, blank=True,
> null=True)
> severity= models.CharField(max_length=20, blank=True,
> null=True)
> message = models.CharField(max_length=250, blank=True,
> null=True)
>
> Any help appreciated !
>
> Thanks, Phil.
>
> --
> 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/1cc3eda3-d180-430e-8e41-866dceb0bca2%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1x51MjhDZCXJPT59kRJLpSGoq6B2Du5xxBggDq1uvRuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError: unbound method save() must be called with NagiosLog instance as first argument (got nothing instead)

2014-12-06 Thread monoBOT
Short answer is Vijay's ... long answer is you have to save() the instanced
object of the class not the class itself.

2014-12-06 22:14 GMT+00:00 Vijay Khemlani :

> Call
>
> k.save()
>
> instad of
>
> NagiosLog.save()
>
>
>
> On Sat, Dec 6, 2014 at 8:26 AM, Phil F  wrote:
>
>> Hi,
>>
>> I am attempting to write a python script that will populate the Django db
>> from data stored in a dictionary.
>>
>> I'm currently getting the error :"TypeError: unbound method save() must
>> be called with NagiosLog instance as first argument (got nothing instead)"
>>
>> from incidents.models import NagiosLog
>> import django
>> xcount = 0
>>
>> for k,v in myDic.items():
>> iincidentnumber = k
>> itime =v[0]
>> idevice =v[2]
>> iservice =v[3]
>> iseverity =v[4]
>> imessage =v[5]
>> print "%r %r %r %r %r" % (itime,idevice,iservice,iseverity,imessage,)
>>  ## prints successfully, code working until here
>> xcount= xcount+1
>> if xcount == 1:   # count to run django setup a single time
>> django.setup()
>> k = NagiosLog(
>> incident = iincidentnumber,
>> time = itime,
>> device = idevice,
>> service = iservice,
>> severity = iseverity,
>> message = imessage,)
>> NagiosLog.save()
>> else:
>> k = NagiosLog(
>> incident = iincidentnumber,
>> time = itime,
>> device = idevice,
>> service = iservice,
>> severity = iseverity,
>> message = imessage,)
>> NagiosLog.save()
>>
>> This is my models file:
>>
>> from django.db import models
>>
>> from django.utils import timezone
>> import datetime
>>
>> class NagiosLog(models.Model):
>> incident= models.CharField(primary_key=True, max_length=80)
>> time= models.CharField(max_length=80, blank=True,
>> null=True)
>> device  = models.CharField(max_length=80, blank=True,
>> null=True)
>> service = models.CharField(max_length=80, blank=True,
>> null=True)
>> severity= models.CharField(max_length=20, blank=True,
>> null=True)
>> message = models.CharField(max_length=250, blank=True,
>> null=True)
>>
>> Any help appreciated !
>>
>> Thanks, Phil.
>>
>> --
>> 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/1cc3eda3-d180-430e-8e41-866dceb0bca2%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALn3ei1x51MjhDZCXJPT59kRJLpSGoq6B2Du5xxBggDq1uvRuA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

-- 
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%2BxOsGAqeK%3D9XKwK9XdEi9_0xYrC%3D-n%2BVNetcFJXJ4ts7bVZBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add another link missing in Chrome

2014-12-06 Thread Russell Keith-Magee
Hi Timothy,

No two browsers will ever render things *identically*, but it should
certainly be functionally equivalent, and at least bear a striking
resemblance to each other. There certainly shouldn't be a missing button or
anything like that.

My immediate reaction is that you've probably got something cached in your
browser - Chrome caches very aggressively, and sometimes needs to be
politely kicked to get it to refresh some resources. However, if you can
reproduce this problem if you start from scratch, it's definitely worth a
bug report.

Yours,
Russ Magee %-)

On Sat, Dec 6, 2014 at 8:51 PM, Timothy Good  wrote:

> Here is the heart of my question:  Is basic Django code (like in the poll
> tutoiral) supposed to render the same in different browsers? If the answer
> is 'Yes' this looks like a bug.  Thoughts?
>
>
> On Friday, December 5, 2014 11:19:37 AM UTC-5, Timothy Good wrote:
>>
>> Django Users,
>>
>> I am working through polls tutorial part 2 that enhances the admin page.
>> Note that I did search for a solution in the recommended places but while I
>> saw similar complaints, none seemed to match exactly.
>>
>> In poll tutorial 2 it says "At the end of the three current slots you
>> will find an “Add another Choice” link."  But this is not the case in
>> Chrome.
>>
>> If I view source in Chrome I see this function but the addText does not
>> appear.  (I am on the latest Chrome: Version 39.0.2171.71 (64-bit))
>>  This is in the source:
>>
>> 
>>
>> (function($) {
>> $("#choice_set-group .tabular.inline-related tbody tr").tabularFormset({
>> prefix: "choice_set",
>> adminStaticPrefix: '/static/admin/',
>> addText: "Add another Choice",
>> deleteText: "Remove"
>> });
>> })(django.jQuery);
>> 
>>
>>
>>
>>
>> For the heck of it I gave it a try in Safari and it rendered just fine.
>>
>> Here is my code in admin.py:
>>
>> from django.contrib import admin
>> from polls.models import Question, Choice
>>
>> class ChoiceInline(admin.TabularInline):
>> model = Choice
>> extra = 3
>>
>> class QuestionAdmin(admin.ModelAdmin):
>> fieldsets = [
>> (None,   {'fields': ['question_text']}),
>> ('Date information', {'fields': ['pub_date'], 'classes':
>> ['collapse']}),
>> ]
>> inlines = [ChoiceInline]
>>
>> admin.site.register(Question, QuestionAdmin)
>>
>> Any thoughts or is this a known issue?
>>
>> Thanks,
>> Tim
>>
>>
>>
>>
>>
>>
>>
>>
>  --
> 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/e00baaef-353a-4226-9a43-e574d8c07622%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849M7UF6RJF%3D6sH-aXrjShrPJcV3Z2c_kdFxej3c0LYTzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking for advise on usage MySQL together with MongoDB

2014-12-06 Thread Mario Gudelj
Django ORM is the best thing since sliced bread!
On 07/12/2014 8:17 am, "Cal Leeming"  wrote:

> Hi Artie,
>
> First, I would strongly recommend reading some of the work by David Mytton
> at Server Density, he and his team have been using MongoDB extensively for
> many years and they have shared a lot of their insight [1]. It's also worth
> mentioning that Postgres has support for JSON field type [2] which
> satisfies many of the use cases for document store, though I haven't
> finished my own experiments yet so can't comment on comparative
> performance/functionality.
>
> It's industry knowledge that MySQL is bleeding out, rapidly [3] [4]. At
> this point, I introduce you to Monty and his creation MariaDB [5]. Although
> I would agree with Russell on many of the points he's made about MySQL,
> it's hard not to have respect for the work that Monty and his team have
> done previously on MySQL, and the vision that is now MariaDB. I would
> strongly recommend you spend some time looking into this yourself, read as
> many comparison articles as your eyes will allow, and come to your own
> conclusions.
>
> I have built numerous "large scale" systems with a variety of
> technologies.. Sphinx, ElasticSearch, MongoDB, MySQL, CouchBase, Redis.
> I've also spent many years battling with MongoEngine and have learnt to
> hate it, as much as I now hate the Django ORM. So, unless you are edging
> towards terabytes of data, assuming you are using SSDs and high memory
> nodes, then the impact of your choice will probably be negligible. And if
> you are using the Django ORM, then you are even less likely to reap any of
> these benefits out of the box [6] There are many different reasons for
> choosing one over the over, and you should assess this based on your own
> use case/needs/skills, rather than religious bias.
>
> Determine your use case and test all viable options, otherwise you could
> be avoiding something for the wrong reasons. You can build *beautiful*
> things with all these different technologies, and it's actually the mindset
> which matters the most [7]. Don't just settle for what others are telling
> you, try for yourself and come to your own conclusions, only then can you
> be sure. It's also a good way to gain in-depth knowledge about how these
> technologies work, which can be invaluable.
>
> Cal
>
>
> [1] https://blog.serverdensity.com/mongodb/
> [2] http://www.postgresql.org/docs/9.3/static/datatype-json.html
> [3] http://www.theregister.co.uk/2012/11/29/monty_oracle_eu_promises/
> [4]
> http://www.computing.co.uk/ctg/news/2271011/mysql-creator-monty-widenius-wants-it-to-disappear-from-the-earth
> [5] http://www.themukt.com/2014/09/11/reason-use-mysql-michael-widenius/
> [6] https://news.ycombinator.com/item?id=4076834
> [7]
> http://www.amazon.co.uk/The-Clean-Coder-Professional-Programmers/dp/0137081073
>
>
>
> On Sat, Dec 6, 2014 at 12:26 AM, Russell Keith-Magee <
> russ...@keith-magee.com> wrote:
>
>>
>> On Fri, Dec 5, 2014 at 8:56 PM, Artie  wrote:
>>
>>> Good day, Community,
>>>
>>> I'm looking for advise on MySQL & MongoDB usage so please let me take
>>> your time to describe the situation.
>>>
>>> I came to work on e-commerce shop of electrical components with about 10
>>> millions of products. Now all of it stored in awful structure of tables in
>>> MySQL. Products stored in 10 small tables, each of them represents
>>> individual manufacturer of products and 1 generalized table, where all 10
>>> millions of goods is stored. Those big table serves Sphinx search to
>>> implement search on site.
>>> All these products being crawled from several APIs and sites on web, so
>>> this shop is kind of authorized reseller in our region.
>>>
>>> The case is that we have to update all products daily and  parsing with
>>> updating of products takes very long time.
>>>
>>> I have an idea to start using MongoDB to update and store products and
>>> as I think it might take less time than same in MySQL. First question: Am I
>>> correct with this statement?
>>>
>>> Browsing web I've found that some recommend using pymongo, avoiding
>>> django rather than mongodb for django. So for your opinion is this
>>> statement correct?
>>>
>>> Also it will be highly highly appreciated if you can share your personal
>>> use experience with MongoDB and any information you think be useful.
>>>
>>
>> Hi Artie,
>>
>> Can I make an alternate suggestion? Get a real database.
>>
>> In all honesty, I've never heard anyone in the Django community express a
>> deep love of MySQL or MongoDB. I know people who use MySQL, but when they
>> admit that, they say "Yeah, I know, but the customer required it" or "Yeah,
>> I know, but at the time we started it was the only thing Amazon supported".
>> As for MongoDB, the sentiment is usually "... and that was our first
>> mistake.".
>>
>> Personally - I have very little time for MySQL. It gets a number of key
>> design decisions wrong (for example, InnoDB's implementation of row
>> referential in

Re: another CSRF question -- and django hitcount

2014-12-06 Thread Eric Abrahamsen
Eric Abrahamsen  writes:

Apologies for the very stupid posting below! I did my homework, and
actually used the JQuery ajax function, like I was supposed to.

Incidentally, I also had the "async" keyword on the  tag in the
head that loaded jquery, and that apparently killed the document.ready
function altogether. Learned something new.

> I have a question about the django-hitcount app that I think is likely
> csrf-related.
>
> I recently upgraded a site from Django 1.4 all the way to 1.7. I've got
> most everything working fine, except that the hitcount app I've been
> using[1], stopped recording hits.
>
> Nevermind the actual app, it works by making an ajax call to a certain
> URL when a page is opened. Right now, the rendered javascript looks like
> this:
>
>