Re: Dynamic View Selection

2017-08-13 Thread Khai Weng Au Yeong
Hey, Russ.

Alright, that answers plenty. If I were to do this I think I would 
experiment with implementing this into the Middleware segment.


Thanks,
Khai

On Saturday, 12 August 2017 01:03:18 UTC+8, Russell Keith-Magee wrote:
>
> Yes - but it doesn’t depend on some hidden feature of Django. It’s 
>
> A Django View is just a function that accepts a request + args, and 
> returns a response. That view can, itself, call other functions - including 
> other functions that can act as views. So, you could write a “switch 
> statement” view:
>
> def switch_view(request, arg1, arg2):
> if client_app_name == ‘xxx’:
> return xxx.view(request, arg1, arg2)
> else:
> return base_view(request, arg1, arg2)
>
> The logic of exactly how to manage the “switch” is entirely up to you.
>
> Depending on how you set up your client sub-packages, you might even be 
> able to use import logic to your advantage:
>
> def switch_view(request, arg1, arg2):
> try:
> client_module = importlib.import_module(‘project.%s.emailer.view’ 
> % client_name)
> return client_module.view(request, arg1, arg2)
> except ImportError:
> return base_view(request, arg1, arg2)
>
> Yours,
> Russ Magee %-)
>
> On 11 Aug 2017, at 5:32 am, Khai Weng Au Yeong  > wrote:
>
> Not sure if this has been covered before, but I was thinking about this 
> for awhile.
>
> Is there a way to dynamically select a View to be used by a URL without 
> having to replicate the URL dispatcher over and over via a "superceding" 
> like method. Like for example, in my project (let's say it's generic), if I 
> have "BaseEmailer" at ".emailer.views" and I have a client 
> with a special-case need installed at 
> ".clients.emailer.views", can I get Django to dynamically 
> select it just based off this logic: if client-app-name = base-app-name?
>
> -- 
> 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...@googlegroups.com .
> To post to this group, send email to django...@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/bc82a384-dec5-4f0a-8cb4-2e4c642b3677%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9f618882-19c2-4447-9195-f0a7b8c6dffd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sync local Database with remote REST API

2017-08-13 Thread Eron Lloyd
Has anyone ever come up with a best practices approach for this? 
Particularly if the remote service is the primary one.

On Monday, March 17, 2014 at 7:40:01 PM UTC-4, Leonard wrote:
>
> Hello everybody, I'm having an hard time to figuring this out.
> I'm designing a django project based on data retrieved from a remote 
> public REST API that will:
>
>- Retrieve data from a REST API
>- Saving the data in my models (my local db)
>- Analyze and process the local data asynchronously and create 
>statistics and trends
>
> When a user request the data:
>
>- Check if the local data (models) are in sync with the remote, 
>otherwise *fetch the remote data* and save them in the local db
>- Present the data
>
>
> *What is the best approach to do this? **My questions:*
>
>1. Should I design *my models replicating all the remote API fields*?
>- Can I use JSonField and store data in json format to speed things up?
>   - In this case would it be complex to calculate statistics on the 
>  data? 
>  In other words I can't use the django ORM and foreign keys if I 
>  store data in JSON format, right?
>   2. *Where should I call the remote API*?
>   - Considering that the remote data should "replicate" the database 
>   models, first I tough to add model methods that call the REST API 
> inside 
>   the models
>   - Or I could put them in the manager, considering that when a user 
>   needs the data he/she doesn't need to know if they are local or remote
>   - How do I tell django to grab the remote data and put them in db 
>   before presenting them?
>  - Maybe this should be an asynchronous task? 
>   
> Sorry for the complexity, I hope I was clear!
> Thanks in advance for your help
>
>

-- 
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/d9ab7a2b-1266-40b1-a478-2f7362b600e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: why when using the tag AMP or ⚡, the server django load four times or more, and when deleting this tag only load one time? I need help

2017-08-13 Thread ANTHONY WAINER


El sábado, 12 de agosto de 2017, 5:49:05 (UTC-5), ANTHONY WAINER escribió:
>
>
> 
>  
> 
>
>
>
>

-- 
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/c8470ba6-27dc-4f17-880e-01cee1a14687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why does combining multiple annotations work in my case?

2017-08-13 Thread Simon Charette
Hello there,

The issue tracked by #10060 only manifests itself when two different 
multi-valued relationships
are used to perform aggregated annotations.

In both of your provided examples you only perform SUM()s on a single 
multi-valued relationship
(ward and then munipality__ward) while the documentation examples spans 
results over two
different multi-valued relationships (authors and store).

Hope that makes things a bit clearer to you,

Best,
Simon

Le vendredi 11 août 2017 16:32:42 UTC-4, gaazkamm a écrit :
>
>
> The documentation advises against combining multiple annotations in one 
> query: 
> https://docs.djangoproject.com/en/1.11/topics/db/aggregation/#combining-multiple-aggregations
>  
> due to the infamous bug #10060: 
> https://code.djangoproject.com/ticket/10060 
>
> And indeed, having tried the counter-example from the documentation, I can 
> easily reproduce the bug. 
>
> However... To my astonishment... I produced a **working** example of 
> combining multiple annotations. An example that, IIUC the aforementioned 
> docu and bug report, should **not** be working. 
>
> Not that I'm complaining, actually my life has just became much, MUCH 
> easier thanks to this query working... I only can't understand WHY is it 
> working? 
>
> Here's my case: (not minimalised too much to improve the chances of 
> failure): 
>
> file models.py: 
>
> from django.db.models import Model, CharField, PositiveSmallIntegerField, 
> PositiveIntegerField, ForeignKey, CASCADE 
>
> # Create your models here. 
>
>
> class Province(Model): 
> name = CharField(max_length=64, primary_key=True) 
>
>
> class Municipality(Model): 
> name = CharField(max_length=64, primary_key=True) 
> province = ForeignKey(Province, on_delete=CASCADE) 
>
>
> class Ward(Model): 
> no=PositiveSmallIntegerField() 
> municipality = ForeignKey(Municipality, on_delete=CASCADE) 
> spoiled_votes = PositiveIntegerField() 
> did_not_vote = PositiveIntegerField() 
>
> class Meta: 
> unique_together = ('no', 'municipality') 
>
>
> class Candidate(Model): 
> first_name = CharField(max_length=64) 
> last_name = CharField(max_length=64) 
>
> class Meta: 
> unique_together=('first_name', 'last_name') 
>
>
> class Votes(Model): 
> ward = ForeignKey(Ward, on_delete=CASCADE) 
> candidate = ForeignKey(Candidate, on_delete=CASCADE) 
> amount = PositiveIntegerField() 
>
> class Meta: 
> unique_together = ('ward', 'candidate') 
>
> File tests.py: 
>
> from django.test import TestCase 
> from random import seed, randrange 
> from worksapp.models import Province, Municipality, Ward, Candidate, Votes 
> from django.db.models import Subquery, Sum, OuterRef, PositiveIntegerField 
> from operator import attrgetter 
>
> # Create your tests here. 
>
>
> class AnnotateTest(TestCase): 
> def test(self): 
> seed(1) 
>
> provinces = [ 
> Province(name='Province'+str(i)) 
> for i in range(0, 10) 
> ] 
> Province.objects.bulk_create(provinces) 
>
> municipalities = [ 
> Municipality(name='Municipality'+str(i), 
> province=provinces[i//10]) 
> for i in range(0, 100) 
> ] 
> Municipality.objects.bulk_create(municipalities) 
>
> wards = [ 
> Ward( 
> no=i%10, municipality=municipalities[i//10], pk=i, 
> spoiled_votes=randrange(0, 100), did_not_vote=randrange(0, 
> 1000) 
> ) for i in range(0, 1000) 
> ] 
> Ward.objects.bulk_create(wards) 
>
> candidates = [ 
> Candidate(first_name='name'+str(i), 
> last_name='surname'+str(i), pk=i) 
> for i in range(0, 10) 
> ] 
> Candidate.objects.bulk_create(candidates) 
>
> votes = [ 
> Votes(ward=wards[i//10], candidate=candidates[i%10], 
> amount=randrange(0, 100), pk=i) 
> for i in range(0, 1) 
> ] 
> Votes.objects.bulk_create(votes) 
>
> multiple_annotate = Municipality.objects.annotate( 
> cand3votes=Subquery( 
> Votes.objects.filter( 
> candidate__first_name='name3', 
> candidate__last_name='surname3', 
> ward__municipality=OuterRef('pk') 
> 
> ).values('ward__municipality').annotate(res=Sum('amount')).values('res'), 
> output_field=PositiveIntegerField() 
> ), 
> cand7votes=Subquery( 
> Votes.objects.filter( 
> candidate__first_name='name7', 
> candidate__last_name='surname7', 
> ward__municipality=OuterRef('pk') 
> 
> ).values('ward__municipality').annotate(res=Sum('amount')).values('res'), 
> output_field=PositiveIntegerField() 
> ), 
> spoiled_votes=Sum('ward__spoiled_votes'), 
>   

JavaScriptCatalog: it's big or not?

2017-08-13 Thread Stanislav
Hi, 
JavaScriptCatalog and JSONCatalog don't contain translations from 
LOCALE_PATHS.


settings.py

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

LANGUAGES = [
('en', _('English')),
('de', _('German')),
('ru', _('Russian')),
]
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)


urls.py

urlpatterns += i18n_patterns(
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^jsoni18n/$', JSONCatalog.as_view(), name='json-catalog'),
)


terminal

django-admin makemessages -l de
django-admin makemessages -l ru


I'm added translation into locale\de\LC_MESSAGES\django.po, 
locale\ru\LC_MESSAGES\django.po

terminal

django-admin makemessages -d djangojs -l de
django-admin makemessages -d djangojs -l ru
django-admin compilemessages



But the response from the 
​http://127.0.0.1:8000/de/jsi18n/ 
​http://127.0.0.1:8000/ru/jsi18n/
​http://127.0.0.1:8000/ru/jsoni18n/
​http://127.0.0.1:8000/de/jsoni18n/
dont contain translations from LOCALE_PATHS. 
This urls contains tranlate only from
django\contrib\admin\locale\de\LC_MESSAGES\djangojs.po
django\contrib\admin\locale\ru\LC_MESSAGES\djangojs.po

I created a small case https://github.com/ctac22/django-localization

Can anyone explain me is it a bug or a usage mistake?


-- 
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/3cd59b3a-4095-4327-8a6e-0cd658b1034d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regarding virtualenv and python version 3.5 or 3.4 or other versions

2017-08-13 Thread Seo Brain
thanks for the suggestion.



On Sunday, August 13, 2017 at 8:11:57 AM UTC-7, Avraham Serour wrote:
>
> I suggest using 3.6, which is the current stable release
> if your machine or the server doesn't have this version installed you may 
> compile it yourself and create the virtualenv for the project from there
>
> There are some projects that help you with that, I like pythonz 
> https://github.com/saghul/pythonz
>
>
> On Sun, Aug 13, 2017 at 9:33 AM, Seo Brain  > wrote:
>
>> Hi, the question is about which python version suppose to use. On web 
>> server is ubuntu 14.4 - python v3.4 (i assume) with virtualenv, my local is 
>> python v3.5 or may be using v3.4 if i have to keep the same version on web 
>> server ? v3.4 seems has issue to install on one of my windows 7, but no 
>> issue on mac. or may be i suppose to use virtual-box to keep the 
>> environment same everywhere dev and production server ?
>> thanks in advance. Ross
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/7937063c-e3cb-44b7-b524-097b82d05d87%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48bcfe50-effc-4688-9492-9025c9f6885d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New Project Name

2017-08-13 Thread m712
What name you choose is completely up to you, to be honest. You should check 
PyPI for projects with the same name as you choose though. If you developed a 
project specifically for Django, you should prefix your package name with 
`django-` (i.e. django-whois).

On August 13, 2017 9:12:25 PM GMT+03:00, sakkhar saha 
 wrote:
>Hi, I am Sakkhar. I am from Bangladesh. Last month I started Django. So
>
>Please Suggest the name of project whois project i completed. 
>
>-- 
>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/ed9347f7-7cad-42c8-a0f7-8a2e3b15f3cb%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

--- :^) --- :^) --- :^) --- :^) --- :^) --- :^) --- :^) --- :^) ---
https://blaze.nextchan.org - https://gitgud.io/m712/blazechan
https://nextchan.org - https://gitgud.io/nextchan/infinity-next
I am awake between 7AM-12AM UTC, hit me up if something's wrong

-- 
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/6BCB4C8F-AB60-4907-AE97-22680D221873%40getbackinthe.kitchen.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


New Project Name

2017-08-13 Thread sakkhar saha
Hi, I am Sakkhar. I am from Bangladesh. Last month I started Django. So 
Please Suggest the name of project whois project i completed. 

-- 
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/ed9347f7-7cad-42c8-a0f7-8a2e3b15f3cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regarding virtualenv and python version 3.5 or 3.4 or other versions

2017-08-13 Thread Avraham Serour
I suggest using 3.6, which is the current stable release
if your machine or the server doesn't have this version installed you may
compile it yourself and create the virtualenv for the project from there

There are some projects that help you with that, I like pythonz
https://github.com/saghul/pythonz


On Sun, Aug 13, 2017 at 9:33 AM, Seo Brain  wrote:

> Hi, the question is about which python version suppose to use. On web
> server is ubuntu 14.4 - python v3.4 (i assume) with virtualenv, my local is
> python v3.5 or may be using v3.4 if i have to keep the same version on web
> server ? v3.4 seems has issue to install on one of my windows 7, but no
> issue on mac. or may be i suppose to use virtual-box to keep the
> environment same everywhere dev and production server ?
> thanks in advance. Ross
>
> --
> 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/7937063c-e3cb-44b7-b524-097b82d05d87%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tJi0OTi9sQbd23AxSuXZ12b6-YtNFp8J-q%2BuP_aPhji4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


regarding virtualenv and python version 3.5 or 3.4 or other versions

2017-08-13 Thread Seo Brain
Hi, the question is about which python version suppose to use. On web 
server is ubuntu 14.4 - python v3.4 (i assume) with virtualenv, my local is 
python v3.5 or may be using v3.4 if i have to keep the same version on web 
server ? v3.4 seems has issue to install on one of my windows 7, but no 
issue on mac. or may be i suppose to use virtual-box to keep the 
environment same everywhere dev and production server ?
thanks in advance. Ross

-- 
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/7937063c-e3cb-44b7-b524-097b82d05d87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.