Re: Using {% include %} and getting context with me

2019-02-13 Thread Mikkel Kromann
Bah! I should really read the docs more carefully.

>From the docs: "*Include:* *Loads a template and renders it with the 
current context.*" 
https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include

The example I posted actually works perfectly fine with regards to the 
include.
I just needed to fix spelling errors in the {% block %} names.
And in my_page1.html I also forgot the block from the base.html.
A working example of base.html and my_page1.html ought to look like this.

base.html:

{% block content %}
{% endblock %}


my_page1.html:
{% extends "base.html" %}
{% block % content %}

{% block foo %}
{% include foo.html %}
{% endblock foo % }

{% block bar %}
{% include bar.html %}
{% endblock bar % }

{% block baz %}
{% include baz.html %}
{% endblock baz % }

{% endblock content % }

Sorry. Keep calm, carry on :)

Mikkel

onsdag den 13. februar 2019 kl. 15.47.10 UTC+1 skrev Mikkel Kromann:
>
> Hi.
>
> I have a collection of apps where I find repeating myself when rendering 
> tables in the templates.
> In the stylised example below I have three types of tables, foo, bar and 
> baz.
> Each app is supposed to render various combinations of tables from its own 
> models, but also from other models' tables.
> (yes, it is a hideously complex structure - and believe me, I've tried to 
> simplify it a lot - even with some success)
>
> Can I - in a page which extends a base, include various "template 
> snippets", so that I can reuse the template snippets across several apps?
>
> base.html:
> 
> ...
> 
>
> my_page1.html:
> {% extends "base.html" %}
>
> {% block foo %}
> {% include foo.html %}
> {% endblock % }
>
> {% block bar %}
> {% include bar.html %}
> {% endblock % }
>
> {% block baz %}
> {% include baz.html %}
> {% endblock % }
>
> foo.html:
> {% if foo_context %}
> 
> {% endif %}
>
> bar.html:
> {% if bar_context %}
> 
> {% endif %}
>
> baz.html:
> {% if baz_context %}
> 
> {% endif %}
>
> As I understand, the snippets are evaluated without the context of 
> my_page1.html, right (e.g. foo_context).
> The docs (
> https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include) 
> seem to suggest that I could work around the context problem by writing:
>
> {% include foo.html with foo_context=foo_context %}
>
>
> Is that correctly understood in this case?
>
>
> thanks, Mikkel
>
>  
>
>

-- 
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/811a1421-4d7f-432f-ad1c-95e4f6015af7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is there a package for user-tagging and user-properties?

2019-02-13 Thread Charles Thayer
I'm aware of django-taggit (and similar) but I'm wondering if there's a 
package for tagging Users with properties that have values of different 
types, such as strings, ints, datetimes, etc.  For example, one might tag a 
user with "power-user", add a property for "last-visited-on" as 
datetime(2019, 02, 13), or add a property for "favorite-color" with the 
value "purple". These would be open-ended property/tag names where 
admin-users may be creating these ad-hoc.

Thanks,
/charles

-- 
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/57eb1708-d51f-4b6b-8ac4-2796062b2fb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Messages rejected?

2019-02-13 Thread Anton Melser
Thanks for the reply. I thought there might be a moderation queue (I never
made it as far as the dedicate list docs). I would be quite interested in
finding out what was inappropriate about my first attempt at posting and
what changed so that my second attempt (with a different email) was
acceptable. I would like to make sure any future questions I post to the
list are in the right form. Is that possible somehow, do you know?

Thanks.

On Thu, 14 Feb 2019 at 02:38, Tim Graham  wrote:

> Messages from first time posters go through a moderation queue.
>
> On Tuesday, February 12, 2019 at 9:56:26 PM UTC-5, Anton Melser wrote:
>>
>> Hi,
>> I asked a question last night with a Google for business account and had
>> the message bounce - is that normal?
>>
>> Google also hasn't kept the message anywhere so it's completely lost :(.
>>
>> Anton
>>
>> ps. Also posted to see whether this will also bounce...
>>
> --
> 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/2121f6d2-a61c-40e1-97e8-40591b6a7046%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq' | dc
This will help you for 99.9% of your problems ...

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


Re: Create a Celery task with Django

2019-02-13 Thread Luis Zárate
See http://django.pyexcel.org/en/latest/

Clean code could be made with this library.

El miércoles, 13 de febrero de 2019, valentin jungbluth <
valentin.a...@gmail.com> escribió:
> Thank you Andréas !
>
> I understand your comment, but it could be possible to illustrate it with
my code ? I spent 1 week and up to now I don't find any way to solve my
issue and execute my Celery task :/
>
> --
> 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/c15b2681-a630-4691-960d-2897f914a553%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyMdaQ3s7ZDegwQxY_oYCxaxBPQooNg7X1VYgEhuKqiLJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create a Celery task with Django

2019-02-13 Thread Luis Zárate
As Andreas suggest I try to create a function that receive a file object
and save the excel content there, Django response works like a file so when
you have a less than 7 then pass the http response and change the
headers.  With celery you can store your firters on str as json file and
pass to celery delay, then create a temporary file and pass to the excel
function with the filters decoded.

Django support Media Fields, so you can create a special file and add to a
model and send to a view that check and return de media url.  Also
important to delete the file after a period of time.

El miércoles, 13 de febrero de 2019, valentin jungbluth <
valentin.a...@gmail.com> escribió:
> Thank you Andréas !
>
> I understand your comment, but it could be possible to illustrate it with
my code ? I spent 1 week and up to now I don't find any way to solve my
issue and execute my Celery task :/
>
> --
> 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/c15b2681-a630-4691-960d-2897f914a553%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyMFMnUWWF1fk6jAjddiNvqjRyh5PEY-VsG1RL1eFriLNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Error- django.core.exceptions.ImproperlyConfigured

2019-02-13 Thread Aayush Aggarwal
Hi all,

I am using django-warrant(https://github.com/MetaMetricsInc/django-warrant) 
as my Authentication backend and using the django_warrant.UserObj as the 
User Model.When i try to run "python manage.py makemigrations" . I got this 
"django.core.exceptions.ImproperlyConfigured" error.
I have created a new project and startapp django_warrant and copied the 
code to the directory.I am looking use this UserObj as a reference in 
another app.

Any hacks or idea.?Is there any alternative.?

Thanks
Aayush Aggarwal
Here is Traceback:

(warrant3.6) ~/Desktop/workspace4/project$ python manage.py makemigrations 
django_warrant
Traceback (most recent call last):
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/apps/config.py",
 
line 165, in get_model
return self.models[model_name.lower()]
KeyError: 'userobj'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/auth/__init__.py",
 
line 193, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, 
require_ready=False)
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/apps/registry.py",
 
line 202, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/apps/config.py",
 
line 168, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'django_warrant' doesn't have a 'UserObj' model.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 15, in 
execute_from_command_line(sys.argv)
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 
line 371, in execute_from_command_line
utility.execute()
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 
line 347, in execute
django.setup()
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/__init__.py",
 
line 24, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/apps/registry.py",
 
line 120, in populate
app_config.ready()
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/admin/apps.py",
 
line 23, in ready
self.module.autodiscover()
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/admin/__init__.py",
 
line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/utils/module_loading.py",
 
line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/importlib/__init__.py", 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/auth/admin.py",
 
line 6, in 
from django.contrib.auth.forms import (
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/auth/forms.py",
 
line 20, in 
UserModel = get_user_model()
  File 
"/home/aayush/.virtualenvs/warrant3.6/lib/python3.6/site-packages/django/contrib/auth/__init__.py",
 
line 198, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % 
settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to 
model 'django_warrant.UserObj' that has not been installed

-- 
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/f7bb2291-5311-41fe-bef5-f4521f8ec9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Messages rejected?

2019-02-13 Thread Tim Graham
Messages from first time posters go through a moderation queue.

On Tuesday, February 12, 2019 at 9:56:26 PM UTC-5, Anton Melser wrote:
>
> Hi,
> I asked a question last night with a Google for business account and had 
> the message bounce - is that normal? 
>
> Google also hasn't kept the message anywhere so it's completely lost :(.
>
> Anton
>
> ps. Also posted to see whether this will also bounce...
>

-- 
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/2121f6d2-a61c-40e1-97e8-40591b6a7046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create a Celery task with Django

2019-02-13 Thread valentin jungbluth
Thank you Andréas !

I understand your comment, but it could be possible to illustrate it with 
my code ? I spent 1 week and up to now I don't find any way to solve my 
issue and execute my Celery task :/

-- 
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/c15b2681-a630-4691-960d-2897f914a553%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create a Celery task with Django

2019-02-13 Thread C. Kirby
Not directly relevant to your celery question, but I would like to point 
you to a project of mine - 
https://django-modelqueryform.readthedocs.io/en/latest/ It lets you build 
search form that generates complex Q objects. It would replace a lot of you 
GET field checking and filtering on that view, and I  think make it much 
more maintainable.



On Wednesday, February 13, 2019 at 6:34:17 AM UTC-5, valentin jungbluth 
wrote:
>
> Hello guys,
>
> I'm working on my Django project and I need to integrate Celery to do 
> something.
> I'm using Django 1.11.20.
>
> *My context :*
>
> I have a template page with a search form. Once you did a search, it 
> returns a table with search results.
> It's possible to export to .xls format with/without search.
>
> There are 2 possibilities :
>
>
>- If user wants to export *less than 70.000 objects*, the export 
>creates an HttpResponse with download link.
>- If user wants to export *more than 70.000 objects*, a Celery task 
>has to be initiate, it creates the file, save it into the MEDIA folder and 
>user gets an email with expirable download link.
>
> I'm trying to implement this second part.
>
> The check is done on template page with number of results according to the 
> search part. 
> If < 70.000 objects, export button calls *export_xls()* function, else it 
> calls the Celery task 
>
> *get_xls_export()HTML Template file :*
>
> {% if item_count > 0 and item_count < 7 %}
> {% if search_info_str %}
>   
>class="glyphicon glyphicon-export">
> {% else %}
>class="button btn btn-default print_items">
>   
> {% endif %}
> {% else %}
> {% if search_info_str %}
>   
>class="button btn btn-default" href="{% url 'ocabr:cron_export' model=model 
> search_info=search_info_str %}">
> {% else %}
>class="button btn btn-default print_items">
>class="button btn btn-default" href="{% url 'ocabr:cron_export' model=model 
> %}">
> {% endif %}
> {% endif %}
>
> This part calls the right function depending on search result.
>
> *Case 1 : Less than 70.000 objects*
>
> The view associated to the previous HTML template is :
>
> class FinalProductListView(PermissionRequiredMixin, EdqmListSearchView):
>
> model = FinalProduct
> page_title = _('Final Products')
> default_sort_params = ('manufacturer_name', 'asc')
> sort_params = ['pk']
>
> create_link = 'ocabr:finalproduct-add'
> update_link = 'ocabr:finalproduct-edit'
> delete_link = 'ocabr:finalproduct-delete'
> view_link = 'ocabr:finalproduct-view'
> print_link = 'ocabr:print-object'
>
> permission_required = 'ocabr.view_finalproduct'
>
> template_name = 'ocabr/final_product/final_product_search.html'
>
> paginate_by = getattr(PaginationMixin, 'paginate_by', None)
> headers = {
> 'releasing_body__short_name': 'Releasing Body/Institution',
> 'is_withdrawn': 'Is nullified',
> }
>
> # Configuration of fields
> fields = ['manufacturer_name', 'releasing_body__short_name', 
> 'product_trade_name', 'pheur_name', 'name', 'final_bulk',
>   'decision', 'date_decision', 'is_withdrawn', 'member_state']
>
> def get_queryset(self):
> queryset = super(FinalProductListView, self).get_queryset()
>
> date_format = settings.USER_DATE_FORMAT
> # Add filter from search form.
> if 'mah' in self.request.GET:
> if self.request.GET['mah'] != '':
> queryset = 
> queryset.filter(mah__icontains=self.request.GET['mah'].strip())
> if 'releasing_body' in self.request.GET:
> if self.request.GET['releasing_body']:
> queryset = 
> queryset.filter(releasing_body__id=int(self.request.GET['releasing_body']))
> if 'trade_name' in self.request.GET:
> if self.request.GET['trade_name'] != '':
> queryset = 
> queryset.filter(product_trade_name__icontains=self.request.GET['trade_name'].strip())
> if 'member_state' in self.request.GET:
> if self.request.GET['member_state']:
> queryset = 
> queryset.filter(member_state__id=int(self.request.GET['member_state']))
> if 'pheur_name' in self.request.GET:
> if self.request.GET['pheur_name'] != '':
> queryset = 
> queryset.filter(pheur_name__id=self.request.GET['pheur_name'])
> if 'decision' in self.request.GET:
> if self.request.GET['decision']:
> queryset = 
> queryset.filter(decision__id=int(self.request.GET['decision']))
> if 'final_bulk_num' in self.request.GET:
> if self.request.GET['final_bulk_num'] != '':
> queryset = 
> queryset.filter(final_bulk__icontains=self.request.GET['final_bulk_num'].strip())
> if 'domain' in self.request.GET:
> if self.request.GET['domain']:
> queryset = 
> 

Re: Using {% include %} and getting context with me

2019-02-13 Thread Avraham Serour
Maybe you can solve this using a templatetag?

On Wed, 13 Feb 2019, 16:47 Mikkel Kromann  Hi.
>
> I have a collection of apps where I find repeating myself when rendering
> tables in the templates.
> In the stylised example below I have three types of tables, foo, bar and
> baz.
> Each app is supposed to render various combinations of tables from its own
> models, but also from other models' tables.
> (yes, it is a hideously complex structure - and believe me, I've tried to
> simplify it a lot - even with some success)
>
> Can I - in a page which extends a base, include various "template
> snippets", so that I can reuse the template snippets across several apps?
>
> base.html:
> 
> ...
> 
>
> my_page1.html:
> {% extends "base.html" %}
>
> {% block foo %}
> {% include foo.html %}
> {% endblock % }
>
> {% block bar %}
> {% include bar.html %}
> {% endblock % }
>
> {% block baz %}
> {% include baz.html %}
> {% endblock % }
>
> foo.html:
> {% if foo_context %}
> 
> {% endif %}
>
> bar.html:
> {% if bar_context %}
> 
> {% endif %}
>
> baz.html:
> {% if baz_context %}
> 
> {% endif %}
>
> As I understand, the snippets are evaluated without the context of
> my_page1.html, right (e.g. foo_context).
> The docs (
> https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include)
> seem to suggest that I could work around the context problem by writing:
>
> {% include foo.html with foo_context=foo_context %}
>
>
> Is that correctly understood in this case?
>
>
> thanks, Mikkel
>
>
>
> --
> 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/8b0eca46-1d00-4bdd-8aba-d8d3a2043a1b%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/CAFWa6tK_J%3Dot4_rZx8n%3Dfv5R%3DBazDHCUrk1NQCxtGw5PfZVMEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using {% include %} and getting context with me

2019-02-13 Thread Mikkel Kromann
Hi.

I have a collection of apps where I find repeating myself when rendering 
tables in the templates.
In the stylised example below I have three types of tables, foo, bar and 
baz.
Each app is supposed to render various combinations of tables from its own 
models, but also from other models' tables.
(yes, it is a hideously complex structure - and believe me, I've tried to 
simplify it a lot - even with some success)

Can I - in a page which extends a base, include various "template 
snippets", so that I can reuse the template snippets across several apps?

base.html:

...


my_page1.html:
{% extends "base.html" %}

{% block foo %}
{% include foo.html %}
{% endblock % }

{% block bar %}
{% include bar.html %}
{% endblock % }

{% block baz %}
{% include baz.html %}
{% endblock % }

foo.html:
{% if foo_context %}

{% endif %}

bar.html:
{% if bar_context %}

{% endif %}

baz.html:
{% if baz_context %}

{% endif %}

As I understand, the snippets are evaluated without the context of 
my_page1.html, right (e.g. foo_context).
The docs 
(https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include) 
seem to suggest that I could work around the context problem by writing:

{% include foo.html with foo_context=foo_context %}


Is that correctly understood in this case?


thanks, Mikkel

 

-- 
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/8b0eca46-1d00-4bdd-8aba-d8d3a2043a1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create a Celery task with Django

2019-02-13 Thread Andréas Kühne
Hi,

FIrst of all - try to put all the code that is the same for both calls into
one method. This way you won't get any problems with that in the future
when you need to update the produced excel file. You can actually use the
same method in both cases because if you call the method WITHOUT delay() on
it, it will be called like a normal method.

To answer your question - all you need to do is have a view that calls the
get_xls_export.delay() task. What I would do is I would put all of the code
for the selection of which export to use into a view class. Then if the
count is less than 7 I would call the standard export without celery
and if it's more than 7 I would call the delayed function. So your View
could contain something like this:

def get():
  if count < 7:
 exported_file = export_xls()
  else:
 export_xls.delay()


Or something like that (this is just pseudocode :-))

Regards

Andréas


Den ons 13 feb. 2019 kl 12:34 skrev valentin jungbluth <
valentin.a...@gmail.com>:

> Hello guys,
>
> I'm working on my Django project and I need to integrate Celery to do
> something.
> I'm using Django 1.11.20.
>
> *My context :*
>
> I have a template page with a search form. Once you did a search, it
> returns a table with search results.
> It's possible to export to .xls format with/without search.
>
> There are 2 possibilities :
>
>
>- If user wants to export *less than 70.000 objects*, the export
>creates an HttpResponse with download link.
>- If user wants to export *more than 70.000 objects*, a Celery task
>has to be initiate, it creates the file, save it into the MEDIA folder and
>user gets an email with expirable download link.
>
> I'm trying to implement this second part.
>
> The check is done on template page with number of results according to the
> search part.
> If < 70.000 objects, export button calls *export_xls()* function, else it
> calls the Celery task
>
> *get_xls_export()HTML Template file :*
>
> {% if item_count > 0 and item_count < 7 %}
> {% if search_info_str %}
>   
>class="glyphicon glyphicon-export">
> {% else %}
>class="button btn btn-default print_items">
>   
> {% endif %}
> {% else %}
> {% if search_info_str %}
>   
>class="button btn btn-default" href="{% url 'ocabr:cron_export' model=model
> search_info=search_info_str %}">
> {% else %}
>class="button btn btn-default print_items">
>class="button btn btn-default" href="{% url 'ocabr:cron_export' model=model
> %}">
> {% endif %}
> {% endif %}
>
> This part calls the right function depending on search result.
>
> *Case 1 : Less than 70.000 objects*
>
> The view associated to the previous HTML template is :
>
> class FinalProductListView(PermissionRequiredMixin, EdqmListSearchView):
>
> model = FinalProduct
> page_title = _('Final Products')
> default_sort_params = ('manufacturer_name', 'asc')
> sort_params = ['pk']
>
> create_link = 'ocabr:finalproduct-add'
> update_link = 'ocabr:finalproduct-edit'
> delete_link = 'ocabr:finalproduct-delete'
> view_link = 'ocabr:finalproduct-view'
> print_link = 'ocabr:print-object'
>
> permission_required = 'ocabr.view_finalproduct'
>
> template_name = 'ocabr/final_product/final_product_search.html'
>
> paginate_by = getattr(PaginationMixin, 'paginate_by', None)
> headers = {
> 'releasing_body__short_name': 'Releasing Body/Institution',
> 'is_withdrawn': 'Is nullified',
> }
>
> # Configuration of fields
> fields = ['manufacturer_name', 'releasing_body__short_name',
> 'product_trade_name', 'pheur_name', 'name', 'final_bulk',
>   'decision', 'date_decision', 'is_withdrawn', 'member_state']
>
> def get_queryset(self):
> queryset = super(FinalProductListView, self).get_queryset()
>
> date_format = settings.USER_DATE_FORMAT
> # Add filter from search form.
> if 'mah' in self.request.GET:
> if self.request.GET['mah'] != '':
> queryset =
> queryset.filter(mah__icontains=self.request.GET['mah'].strip())
> if 'releasing_body' in self.request.GET:
> if self.request.GET['releasing_body']:
> queryset =
> queryset.filter(releasing_body__id=int(self.request.GET['releasing_body']))
> if 'trade_name' in self.request.GET:
> if self.request.GET['trade_name'] != '':
> queryset =
> queryset.filter(product_trade_name__icontains=self.request.GET['trade_name'].strip())
> if 'member_state' in self.request.GET:
> if self.request.GET['member_state']:
> queryset =
> queryset.filter(member_state__id=int(self.request.GET['member_state']))
> if 'pheur_name' in self.request.GET:
> if self.request.GET['pheur_name'] != '':
> queryset =
> queryset.filter(pheur_name__id=self.request.GET['pheur_name'])
> if 

Re: update object without updating auto_now fields

2019-02-13 Thread Андрей Маслов
MyModel.objects.filter(pk=obj.pk).update(...)

https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.DateField.auto_now
The field is only automatically updated when calling Model.save() 

. 
The field isn’t updated when making updates to other fields in other ways 
such as QuerySet.update() 
,
 
though you can specify a custom value for the field in an update like that.

среда, 13 февраля 2019 г., 10:25:54 UTC+2 пользователь Mohammad Etemaddar 
написал:
>
> I think about times that I need to edit user profiles without touching 
> auto_now field.
> How can I do it?
>

-- 
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/21ddf025-5407-44f5-aad4-710fcf93b756%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Create a Celery task with Django

2019-02-13 Thread valentin jungbluth
Hello guys,

I'm working on my Django project and I need to integrate Celery to do 
something.
I'm using Django 1.11.20.

*My context :*

I have a template page with a search form. Once you did a search, it 
returns a table with search results.
It's possible to export to .xls format with/without search.

There are 2 possibilities :


   - If user wants to export *less than 70.000 objects*, the export creates 
   an HttpResponse with download link.
   - If user wants to export *more than 70.000 objects*, a Celery task has 
   to be initiate, it creates the file, save it into the MEDIA folder and user 
   gets an email with expirable download link.

I'm trying to implement this second part.

The check is done on template page with number of results according to the 
search part. 
If < 70.000 objects, export button calls *export_xls()* function, else it 
calls the Celery task 

*get_xls_export()HTML Template file :*

{% if item_count > 0 and item_count < 7 %}
{% if search_info_str %}
  
  
{% else %}
  
  
{% endif %}
{% else %}
{% if search_info_str %}
  
  
{% else %}
  
  
{% endif %}
{% endif %}

This part calls the right function depending on search result.

*Case 1 : Less than 70.000 objects*

The view associated to the previous HTML template is :

class FinalProductListView(PermissionRequiredMixin, EdqmListSearchView):

model = FinalProduct
page_title = _('Final Products')
default_sort_params = ('manufacturer_name', 'asc')
sort_params = ['pk']

create_link = 'ocabr:finalproduct-add'
update_link = 'ocabr:finalproduct-edit'
delete_link = 'ocabr:finalproduct-delete'
view_link = 'ocabr:finalproduct-view'
print_link = 'ocabr:print-object'

permission_required = 'ocabr.view_finalproduct'

template_name = 'ocabr/final_product/final_product_search.html'

paginate_by = getattr(PaginationMixin, 'paginate_by', None)
headers = {
'releasing_body__short_name': 'Releasing Body/Institution',
'is_withdrawn': 'Is nullified',
}

# Configuration of fields
fields = ['manufacturer_name', 'releasing_body__short_name', 
'product_trade_name', 'pheur_name', 'name', 'final_bulk',
  'decision', 'date_decision', 'is_withdrawn', 'member_state']

def get_queryset(self):
queryset = super(FinalProductListView, self).get_queryset()

date_format = settings.USER_DATE_FORMAT
# Add filter from search form.
if 'mah' in self.request.GET:
if self.request.GET['mah'] != '':
queryset = 
queryset.filter(mah__icontains=self.request.GET['mah'].strip())
if 'releasing_body' in self.request.GET:
if self.request.GET['releasing_body']:
queryset = 
queryset.filter(releasing_body__id=int(self.request.GET['releasing_body']))
if 'trade_name' in self.request.GET:
if self.request.GET['trade_name'] != '':
queryset = 
queryset.filter(product_trade_name__icontains=self.request.GET['trade_name'].strip())
if 'member_state' in self.request.GET:
if self.request.GET['member_state']:
queryset = 
queryset.filter(member_state__id=int(self.request.GET['member_state']))
if 'pheur_name' in self.request.GET:
if self.request.GET['pheur_name'] != '':
queryset = 
queryset.filter(pheur_name__id=self.request.GET['pheur_name'])
if 'decision' in self.request.GET:
if self.request.GET['decision']:
queryset = 
queryset.filter(decision__id=int(self.request.GET['decision']))
if 'final_bulk_num' in self.request.GET:
if self.request.GET['final_bulk_num'] != '':
queryset = 
queryset.filter(final_bulk__icontains=self.request.GET['final_bulk_num'].strip())
if 'domain' in self.request.GET:
if self.request.GET['domain']:
queryset = 
queryset.filter(domain__id=int(self.request.GET['domain']))
if 'manufacturer_name' in self.request.GET:
if self.request.GET['manufacturer_name'] != '':
queryset = 
queryset.filter(manufacturer_name__id=self.request.GET['manufacturer_name'])
if 'date_from' in self.request.GET and 'date_to' in 
self.request.GET:
if self.request.GET['date_from'] and not 
self.request.GET['date_to']:
try:
queryset = 
queryset.filter(date_decision__gte=Utils.filter_date_format(self.request.GET['date_from'],
 
date_format))
except:
pass
if not self.request.GET['date_from'] and 
self.request.GET['date_to']:
try:
queryset = 
queryset.filter(date_decision__lte=Utils.filter_date_format(self.request.GET['date_to'],
 
date_format))
except:
pass
if self.request.GET['date_from'] and 
self.request.GET['date_to']:
   

Re: Passing values

2019-02-13 Thread Ivan Martić
In first page(form), i want to search for vendor. Afterwords when i click
on one we go into another page. On this page we have performance form where
we need to give ratings from 1 to 5 for that particular vendor.
So when I rate all the fields and press save, i want to store all rating
data in sql together with vendor name, timestamp and username who saved tha
data.

That was all working fine in for loop(except vendor part, needed to enter
data in input field myself), but when i divide performance form into
separate fields in HTML all crashed. Please see txt enclosed.
Thank you for your response.


sri, 13. velj 2019. u 11:48 Mohammad Etemaddar 
napisao je:

> Dear Ivan,
> If I get you right, You have a page with form, and you want to post it to
> another page. so, fill the "action" part of html form with the second
> page's url.
>
> Also the timezone.now is allways available in any python file you are
> working on it, and also request and request.user
>
> What do you want to do exactly?
>
> On Wednesday, February 13, 2019 at 1:45:46 PM UTC+3:30, Ivan Martić wrote:
>>
>> Hi all,
>>
>> where can i find more info regarding passing values in views/forms/url.
>> What I need is to pass value from form in previous url page to the form
>> in next url page(also prefilling with data like timezone.now, request,user)
>>
>> Thank you in advance.
>> Ivan
>>
> --
> 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/5eb3df26-ae0d-44c7-8f4b-e7b0b6e5e01e%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/CAFab_C_HtQsH7%3Dq0%3D4vYtRHN%3D5RKO0qhNow%3Degosk0RLfbdUSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from datetime import date
from django.forms import widgets


GRADE_CHOICES = (
('1', 'Excellent'),
('2', 'Very good'),
('3', 'Good'),
('4', 'Adequate'),
('5', 'Poor')
)


class Performance(models.Model):
id = models.AutoField(db_column='ID', primary_key=True, blank=False, 
unique=True)
supplier_name = models.CharField(db_column='Supplier name',max_length=9, 
blank=True, null=True)
deliverability = models.CharField(db_column='Deliverability', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
goodwill = models.CharField(db_column='Goodwill', blank=True, max_length=1, 
null=True, choices=GRADE_CHOICES)
certification = models.CharField(db_column='Certification', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)

compliance_with_spec_field = models.CharField(db_column='Compliance with 
spec#', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
quality_of_the_delivery = models.CharField(db_column='Quality of the 
Delivery', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
quantity_reliability = models.CharField(db_column='Quantity reliability', 
max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
fulfilment_of_deadlines = models.CharField(db_column='Fulfilment of 
deadlines', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)

reaction_time = models.CharField(db_column='Reaction time', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
flexibilty = models.CharField(db_column='Flexibilty', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
economical_offer = models.CharField(db_column='Economical offer', 
max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
price_performance_ratio = models.CharField(db_column='Price-performance 
ratio', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)

credit = models.CharField(db_column='Credit', max_length=1, blank=True, 
null=True, choices=GRADE_CHOICES)
rating = models.CharField(db_column='Rating', max_length=255, blank=True, 
null=True, choices=GRADE_CHOICES)
rated_by = models.CharField(db_column='Rated by', max_length=255, 
blank=True, null=True)

Re: Passing values

2019-02-13 Thread Mohammad Etemaddar
Dear Ivan,
If I get you right, You have a page with form, and you want to post it to 
another page. so, fill the "action" part of html form with the second 
page's url.

Also the timezone.now is allways available in any python file you are 
working on it, and also request and request.user

What do you want to do exactly?

On Wednesday, February 13, 2019 at 1:45:46 PM UTC+3:30, Ivan Martić wrote:
>
> Hi all,
>
> where can i find more info regarding passing values in views/forms/url.
> What I need is to pass value from form in previous url page to the form in 
> next url page(also prefilling with data like timezone.now, request,user)
>
> Thank you in advance.
> Ivan
>

-- 
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/5eb3df26-ae0d-44c7-8f4b-e7b0b6e5e01e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Passing values

2019-02-13 Thread Ivan Martić
Hi all,

where can i find more info regarding passing values in views/forms/url.
What I need is to pass value from form in previous url page to the form in 
next url page(also prefilling with data like timezone.now, request,user)

Thank you in advance.
Ivan

-- 
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/53f99288-1b18-4c4a-8a1a-92b465519d87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Keeping/accessing the data Django generates during a test run

2019-02-13 Thread Anton Melser
>
> When you use django unittests commit is made as no-op. Use --keepdb and at
> the end of your tests run SQL commit against your database cursor
> connection.
>

Awesome, exactly the info I was missing. Thanks for your help.
Cheers,
Anton

-- 
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/CAKywjPpYWa3D9KvB%3DzYoas_UNKgHxk%3DY4vJqeAGnjLE65Kq0Gg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Keeping/accessing the data Django generates during a test run

2019-02-13 Thread Jani Tiainen
When you use django unittests commit is made as no-op. Use --keepdb and at
the end of your tests run SQL commit against your database cursor
connection.

On Wed, Feb 13, 2019 at 5:54 AM Anton Melser  wrote:

> Hi,
>
> I can't work out whether it is expected or whether I am missing something.
> I would like to keep the DB data that I generate during a test run to
> inspect/persist it. --keepdb means I have empty tables at the end,
> strangely even if I ctrl-C a test run. It would also be logical for test
> data to get cleaned... Is there an option I can add to keep it?
>
> I have a lot of calls to external services that should be mocked. The json
> returned from these calls is put in the DB as-is, so if I can just set up
> an initial run of the tests and then get the data from the DB that would be
> optimal. I could add file writes about the place to persist, but I want to
> evolve the test data over time and will need to do this often, so being
> able to do that from the DB would be very handy.
>
> Any pointers?
>
> Thanks,
> Anton
>
> --
> 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/f9d2dfe3-c832-45bd-a6d3-7f3415f1293d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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/CAHn91ofX4s7zouEtU-3OMuzQuRWFUw6v-uqHVEixjKPgy-p5ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


update object without updating auto_now fields

2019-02-13 Thread Mohammad Etemaddar
I think about times that I need to edit user profiles without touching 
auto_now field.
How can I do it?

-- 
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/0d3ef3d6-8452-4028-b2a2-ca9980b51476%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.