django tests and namespaced reversed urls

2011-07-05 Thread Mateusz Harasymczuk
I have a problem with tests and namespaced reversed urls.
It fails tests.
However when running a server they works properly.
I have tried

#urls.py
url(r'^', include('ns.urls', namespace="ns"), name="ns"),

#ns/urls.py
url(r'name/$', NameView.as_view(), name='home'),

#template.html

{% url ns:home %}

and

{% load url from future %}
{% url "ns:home" %}




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



dajngo TabularInline fixed objects

2011-07-01 Thread Mateusz Harasymczuk
Is there a way to declare a set of fixed objects in TabularInline?

I have:

Contract object (with user data, user address and stuff) and tabular inline 
added months.

months names are fixed, and there is some data to change for each month

I have done this with JavaScript, setting value of each field (month name), 
on document ready, and then disabling a select list
is there a way to do so via django?

acting like readonly_field with default value set, but not one static value, 
but variable depending on row num. 


--
Matt Harasymczuk
http://www.matt.harasymczuk.pl

-- 
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/-/1gcQQsNjB4cJ.
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: db shardning

2011-07-01 Thread Mateusz Harasymczuk
anyone?

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



db shardning

2011-06-30 Thread Mateusz Harasymczuk
Hi,
I have recently came to the point when I need to use more then one DB in my 
usecase.
I had to deal with storing and getting data from multiple DB, based on how 
old the data is.
I have an archive database to store all logs and data from models to which 
access will be occasionally.

My application has a customer and contract list, which one per year became 
obsolete, because of season ends.
Then I move those data to an archive db. However once a while I need to get 
those data.

Usecase:
DB shardnig would be a great use for me, to save models to DB based on 
season selected from list (I have a model for that).
If contract belongs to season 2010-2011, save to contracts_2010-2011, else 
save to contracts_2011-2012.
There is a large number of those contracts (and some of them will not be 
needed, in next year), therefore having those in one db (counting logs, 
payments, and django_admin actions and history) is a bad idea.

logs, actions and contracts could be stored in db, based on selection of 
season.


I hope this description would direct you on what I mean by this question.
Could MultiDB https://docs.djangoproject.com/en/dev/topics/db/multi-db/ an 
answer to my question?

--
Matt Harasymczuk
http://www.matt.harasymczuk.pl

-- 
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/-/VAUGN1Ix1okJ.
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 Model Designer - UML

2011-06-26 Thread Mateusz Harasymczuk
I found perfect tool for mac
SQLeditor + Django plugin

works perfect!

http://www.malcolmhardie.com/sqleditor/django/index.html


--
Matt Harasymczuk
http://www.matt.harasymczuk.pl

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



Odp: Re: Odp: Re: signals pre_save vs model's save()

2011-06-02 Thread Mateusz Harasymczuk
That was a very good and convincing post :}
I am testing a solution with .clean(), which IMHO is a better place to clean 
data before save()


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



Odp: Re: signals pre_save vs model's save()

2011-05-29 Thread Mateusz Harasymczuk
W dniu niedziela, 29 maja 2011, 15:36:13 UTC+2 użytkownik Malcolm Box 
napisał:
>
> On 28 May 2011 11:05, Mateusz Harasymczuk <mat...@harasymczuk.pl> wrote:
>
>> I am thinking about splitting my model's save() method over few signals.
>>
>> For example, stripping spaces and making string capitalized.
>>
>>
> Why would you want to do that?
>

Because I am writing CRM, and my end users are non-technical ladies :}
And each one of them inputs data in different format (id numbers, phone 
numbers, dates, names [upper cased, capitalized, lower cased])
Therefore I have to normalize an input to store, and then print contract 
agreements in normalized way.
You may say normalize via template tags at rendering level.
Yes, but I use those data for example to calculate date ranges and text 
search.
If someone has an resignation addendum I have to make some other changes to 
model.
It is easier to normalize them in pre_save or at the save() method
 

>  
>
>> I have even more sophisticated problems such as making an object field 
>> active set to False basing on various parameters from other fields, such as 
>> expiration date, or good or bad karma points.
>>
>> What do you think, it is generally good idea, to keep models file clean 
>> out of heavily overloaded save() methods?
>>
>>
> If this logic is tied to your model, what is the advantage of moving it out 
> of the save() method in your model definition?  
> You would more usefully serve the same purpose by decomposing the save() 
> method into several functions e.g.:
>

my largest model is about 20 fields length.
where save methods are about at least 50 lines long.

it gives me a mess.

and then there are list_display functions (each is 1 to 3 lines long) which 
almost doubles fields length and gives me a 150-200 lines length model file, 
with only 20 fileds

and I have not included comments and docstrings...



> Clean, simple and makes it very obvious what you're doing in the save() 
> method. Compare that with the signals version, which will give someone 
> reading the code no clue at all that when they call save() the values of the 
> fields will change.
>

I can provide a comment in a model file, that normalize functions are stored 
in signals file.

 

> How about making more than one signal pre_save to the same model?
>>
>> It will work, but it's the wrong approach.
>

I am not saying this is a good approach,
I am thinking this might be a good solution in my case.

Looking forward to hearing some more opinions.
I might reconsider, if someone points me a better solution, than I am 
thinking of.


--
Matt Harasymczuk
http://www.matt.harasymczuk.pl

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



Odp: Re: signals pre_save vs model's save()

2011-05-28 Thread Mateusz Harasymczuk
So it should works.
Great.

my save() methods are much longer than models declaration, and I find it 
quite a bit confusing to maintain.
and for sure, to tell how it works :}

from PEP 20 -- The Zen of Python:

"

Simple is better than complex.

...

If the implementation is hard to explain, it's a bad idea.

"

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



signals pre_save vs model's save()

2011-05-28 Thread Mateusz Harasymczuk
I am thinking about splitting my model's save() method over few signals.

For example, stripping spaces and making string capitalized.

I have even more sophisticated problems such as making an object field 
active set to False basing on various parameters from other fields, such as 
expiration date, or good or bad karma points.

What do you think, it is generally good idea, to keep models file clean out 
of heavily overloaded save() methods?

How about making more than one signal pre_save to the same model?


@receiver(pre_save, sender=X)
def strip_chars(sender, **kwargs):
pass

@receiver(pre_save, sender=X)
def capitalize_name(sender, **kwargs):
pass

@receiver(pre_save, sender=X)
def make_inactive(sender, **kwargs):
pass

Will it work?

I want to put those in signals/X.py
where X is my model name

Where to import them? in my model file?
or it will happen "automagicly" like with admin.py file?
(I think that python's explicit rule forbids that way, therefore where to 
import those signals, avoiding recurring imports [signal.py import model.py 
and model imports signals])?

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



Odp: Re: Django Model Designer - UML

2011-05-28 Thread Mateusz Harasymczuk
This is a very good hint.
Somehow I had to skipped the inspectdb command.

There is humongous number of the DB designing tools.

Thank you.

-- 
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 Model Designer - UML

2011-05-27 Thread Mateusz Harasymczuk
I am looking for a GUI tool for modeling Django model classes.

I have a pretty large app and I need to refactor it.
I used django-extensions and *graph_models* to dump the schema to the 
GraphViz dot file.
And I am stuck here :}

I would like to import either GraphViz dot file, or models source files, 
make changes and generate output Python+Django code.

Has anyone did something like that?

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



Odp: Looking for Class Base Views intro (not Generic Class Base Views!)

2011-05-26 Thread Mateusz Harasymczuk
Anyone?
Class Based Views?

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



Looking for Class Base Views intro (not Generic Class Base Views!)

2011-05-25 Thread Mateusz Harasymczuk
I am looking for a Class Base Views introduction or tutorial.
I have googled the web, and all I was able to find was the Generic Class 
Base Views.

There were only a few examples of non generic views, however the code was to 
fuzzy.

Django generally has a superb documentation, but this part is not so good.

Q1. Or maybe I am wrong and there is no Class Based Views beside the Generic 
ones?

I want to move my function based views to the classes.
I would like to make them RESTful with login_required decorator for some of 
them:

I have this:

import re

from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic.base import TemplateView

nonalpha_re = re.compile('[^A-Z]')


class BaseView(TemplateView):
""" Subclass this and add GET / POST / etc methods. """
allowed_methods = ('GET', 'PUT', 'POST', 'DELETE', 'HEAD', 'OPTIONS')
context_object_name = "object"

def __call__(self, request, *args, **kwargs):
""" """
method = nonalpha_re.sub('', request.method.upper())

if not method in self.allowed_methods or not hasattr(self, method):
return self.http_method_not_allowed(request, *args, **kwargs)

return getattr(self, method)(request, *args, **kwargs)



class AuthenticatedView(BaseView):
""" Require login """

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

 
and then in my views.py


class ContractView(AuthenticatedView):
template_name = "crm/contract/index.html"

def GET(request, id):
c = get_object_or_404(Contract, id=id)
return {"contract": c}

and so on...

Q2. Am I thinking right?
Q3. How to make prettier JSON dumps?

for example if I set ContractView.mimetype = 'application/json'
I would like to render returned value from GET method and send it to browser 
as a JSON string instead of directing it to the template.

Looking forward to hearing from you.
Sincerely

Matt Harasymczuk
http://www.matt.harasymczuk.pl

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