Re: ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-16 Thread Melvyn Sopacua
On dinsdag 16 juli 2019 03:25:11 CEST Jacob Greene wrote:

> Hello! Has anyone dealt with this before? It seems that my forms don't add
> the CSS class to errors raised in model.clean() or model.clean_fields()
> methods.
> 
> I have a form that looks something like this:
> 
> class HttpsFaxBoxForm(forms.ModelForm):
> error_css_class = 'form_error'

> 
> And I run validation in my models(keep the admin page consistent) like this:

But your form is valid, so why should it apply error classes?
 
If you want to keep the admin page consistent, use the same form for admin, 
but your core problem is that you mix input validation (task of form) with 
data consistency (task of model). Keep those separated as much as possible and 
things will go smoother.
-- 
Melvyn Sopacua


-- 
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/1743720.jJN2cR3phd%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: How to include delete function in UpdateView instead a DeleteView

2018-08-11 Thread Melvyn Sopacua
On vrijdag 10 augustus 2018 16:51:54 CEST zengkeat wrote:

> I have a UpdateView for editing a post, but instead of making a DeleteView
> for delete a post, i try to make UpdateView include a function to delete
> the post. So ,i want to edit and delete a post in UpdateView. Is that
> possible ? i think i missing something in my code so the code keep getting
> error.

No, you're simply not conforming to the method signature.

> form_valid() missing 1 required positional argument: 'pk'

Your form_valid method wants an argument 'pk':

> def form_valid(self, form, pk):

But Django never will give you one. What you're looking for is 
self.kwargs['pk'] and the method for form_valid can only accept one argument, 
which is the form.

-- 
Melvyn Sopacua


-- 
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/1714845.lzVsRMqLTZ%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Downgrade and Upgrade Django migration

2018-08-05 Thread Melvyn Sopacua
On zaterdag 4 augustus 2018 18:03:21 CEST Andréas Kühne wrote:

> I don't know how to revert migrations though - I do think it's possible

Yes, easy. Name the app and migration you want to downgrade to:

python manage.py yourapp 0002

This would unapply 0003_new_model, 0004_change_new_model and so on.

If you want to unapply all migrations of a given app, then you use "zero":

python manage.py yourapp zero

This unapplies 0001, 0002 etc ...

This is documented at the "migrate" management command[1].

This only works when your migrations have a "reverse" operation coded, where 
RunSQL[2] 
and RunPython[3] is concerned, otherwise the system will not know how to 
unapply the 
migration.

If you want a system that automatically reverts migrations to a set version 
number of the 
entire project, then you'll need to create some custom code and your tools of 
choice will 
be:

- A RunPython migration in the project app, that keeps track of which 
migrations belong to 
which version ... or:
- You squash migrations when cutting a new release and name them consistently 
using "--
squashed-name[4]". For example: coolapp/migrations/0001_v1_0_0.py, 
hotapp/migrations/
0001_v1_0_0.py, coolapp/migrations/0002_v1_0_3.py

With either approach it should be possible to write a management command that 
gathers 
all the migrations to unapply and get back to a fixed point in time.

But what you really have to be aware of, is that it is destructive: if you 
added fields to a 
model and that model has new data in that field during the time it was 
deployed, rolling 
back the migration will destroy that new data.

So while you can go back, you can't easily go forward again and have that data 
magically 
reappear.


https://djangopackages.org/grids/g/versioning/

Probably in addition to custom code.
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/ref/django-admin/#migrate
[2] https://docs.djangoproject.com/en/2.0/ref/migration-operations/
#django.db.migrations.operations.RunSQL
[3] https://docs.djangoproject.com/en/2.0/ref/migration-operations/
#django.db.migrations.operations.RunPython
[4] 
https://docs.djangoproject.com/en/2.0/ref/django-admin/#cmdoption-squashmigrations-squashed-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+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/3452710.b6zlfaCYd4%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django App plugins

2018-07-29 Thread Melvyn Sopacua
On zondag 29 juli 2018 23:14:34 CEST Christian González wrote:
> On zondag 29 juli 2018 11:02:30 CEST Christian González wrote:

> > There might also be another reason and that is that in the Python
> > community, there's a good realisation that downloadable and instantly
> > installable plugins for a web project without dev(ops) interference
> > isn't necessarily a good thing.
> 
> Mh, not really. Look at Owncloud/Nextcloud. Is PHP, but a good example
> that this works. 

I have a good amount of experience with Magento, which has the same principle 
and dealt with all the downsides of it. But I personally don't know of any 
similar project within the Python community.

Doesn't mean it doesn't exist, just not as wide spread and after having dealt 
with the security holes, low quality not performing code, layout breakers and 
what not - I can't say I'm surprised. Magento has invested quite a bit in ways 
to check code quality on everything that hits the store.

Either way, keep in mind that you're not going to solve this *just* at the 
Django layer. You'll need some way to trigger the WSGI processor to load the 
new code in a safe manner and then run migrations. Good luck!

-- 
Melvyn Sopacua


-- 
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/1637102.li6HjgoyNo%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django Login Error

2018-07-29 Thread Melvyn Sopacua
On zondag 29 juli 2018 14:07:19 CEST Kasper Laudrup wrote:

> On 2018-07-29 10:27, lalitaquasoft wrote:
> > How to remove Unique username
> 
> How would you expect user management to work if usernames are not unique?

By using split fields. I've ran into this as well, as I want to allow the same 
username per different domain - ya know, like emails.

I ended up with a choice to duplicate the data as a single database field or 
ditch django.contrib.auth. I went for solving the problem at the form level 
and not storing the username / domain in the custom user model, but storing it 
as an email field that had to be unique.
-- 
Melvyn Sopacua


-- 
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/2157237.Hh3KulHEcb%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django App plugins

2018-07-29 Thread Melvyn Sopacua
On zondag 29 juli 2018 11:02:30 CEST Christian González wrote:
> anyone?
> I wondered if I'm the only one that has such a use case? 

I think so. Why not distribute it as a Django **project** so the plugins are 
reusable apps.
You can also nest apps, like "coolstuff.plugins.*". It may get tricky with 
unique app labels though.

Anyway, there's plenty of examples of Django based software that is 
distributed as a project. Mezzanine is one of them.

There might also be another reason and that is that in the Python community, 
there's a good realisation that downloadable and instantly installable plugins 
for a web project without dev(ops) interference isn't necessarily a good 
thing.
-- 
Melvyn Sopacua


-- 
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/1703732.VyyS66Gq1u%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: File-Backend or Filemanagement

2018-07-29 Thread Melvyn Sopacua
On zondag 29 juli 2018 10:50:58 CEST Muri Nicanor wrote:

> i'm writing a Django application that has the management of textfiles on
> the server as one of the requirements. I've already created a model that
> parses the textfiles and provides a way of editing the files. To choose
> the indivdiual textfiles i created a simple view that does a file
> listing (basically an os.listdir()), but that is not really a flexible
> solution (i.e. i would like to have pagination).

Please don't reinvent the wheel. There's plenty to choose from.
https://djangopackages.org/grids/g/file-managers/
-- 
Melvyn Sopacua


-- 
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/2952161.smV9ToK1WU%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: [Question] Django 2 - how to sum values based on filter and group by Year-Month

2018-07-27 Thread Melvyn Sopacua
On vrijdag 27 juli 2018 04:25:56 CEST Charles Sartori wrote:

> I need to Sum() the values filtering it with
> 1 - sum(values) where date < first day of the month
> 2 - sum(values) where date < last day of the month
> 
> Expected result(something like that):
> [
>  {'year-month': '2018-01'}, {'sum_before_month_day_one': *0*},
> {'sum_before_last_month_day': *60*},
>  {'year-month': '2018-02'}, {'sum_before_month_day_one': *60*},
> {'sum_before_last_month_day': *70*},
>  {'year-month': '2018-03'}, {'sum_before_month_day_one': *70*},
> {'sum_before_last_month_day': *100*},
> ]

Break it down:
- the only relevant part is the sum of the month
- the other is a running total you can keep track of without putting the 
burdon on the database

But, requirement 2) applied to the first result should strictly yield 30, not 
60. But I think that's an error in your requirement description.

> {'date': datetime.date(2018, 1, 1), 'quantity': 60.0}

(30 is *at* the last day of the month, not before it)
> 2018-01-31  30

-- 
Melvyn Sopacua


-- 
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/2165075.IrKYnSaKcf%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-26 Thread Melvyn Sopacua
On donderdag 26 juli 2018 02:35:01 CEST Gene wrote:
> Preventing code from using networking is a common approach for unit tests
> Firewall is a completely different story and has nothing common with this
> matter

It does, because he's looking for a catch-all  button. If you read the entire 
thread you'll see we've offered several times, several strategies for 
different approaches for unit tests.

But he's looking for the equivalent of  "turning off the main water line" - 
and that's a firewall or sandboxes / virtual machines without network routing.

Django has absolutely no way to do that and cannot, because there's no telling 
what 3rd party apps do (not that python has such a switch or even C).

-- 
Melvyn Sopacua


-- 
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/1777274.KOJhutkDlD%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Some Doubts on Session Expiries

2018-07-25 Thread Melvyn Sopacua
On woensdag 25 juli 2018 21:05:27 CEST vineeth sagar wrote:
> Hi,
> 
> I have been going crazy for the past few days trying to understand
> sessions, my settings.py file as the following,
> 
> SESSION_SAVE_EVERY_REQUEST=True
> SESSION_COOKIE_AGE=2*60
> 
> Now whenever a request is initiated shoudn't the expiry date of the cookie
> i.e the one that holds the session id ,doubled i.e become four minutes.

No. It stays 2 minutes. But two minutes from the last time it was used. If you 
were too late or have a clock out of sync, then you'll never get the update to 
the next two minutes.


> A user "admin" has initiated a request, done some work closed his browser,
> session cookie holding the session id has expired and that's wonderful as
> expected.
> 
> Now If I run this snippet,
> 
> from django.contrib.sessions.models import Session
> from django.utils import timzone
> 
> sessions = Sessions.objects.filter(expire_date__gte=timezone.now())
> 
> The above queryset has the session of the admin user, I am confused is this
> expected behavior? Can someone please address the queries for me.

That's just fine, because the browser will not send the cookie, so the session 
is never looked for. Once the date expires, it will be garbage collected.

-- 
Melvyn Sopacua


-- 
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/12365039.WSUnCLOFxh%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-25 Thread Melvyn Sopacua
On dinsdag 24 juli 2018 04:21:07 CEST Kum wrote:
> Is there a way to prevent people from accidentally doing so?

To prevent network access, there are firewalls. Django isn't the thing for it.

-- 
Melvyn Sopacua


-- 
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/3373993.c7B7MrKRp2%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Melvyn Sopacua
On maandag 23 juli 2018 17:23:20 CEST chuck.horow...@packetviper.us wrote:
> Hi Kum,
> 
> I think Melvyn's suggestion is a good one.  Is there any reason you
> couldn't do:
> 
> 
> import DEBUG from yourapp.settings
> 
> 
> And then check against that for your testing?

Here's some code I used in a test:

class KvkApiTester(Testcase):
def skip_live_tests(self):
api_config = getattr(settings, 'KVKAPI', dict())
if not kvk_config or kvk_config['live_tests'] is False:
raise self.skipTest('live tests disabled or no KVKAPI 
configuration)

def test_api_key(self):
self.skip_live_tests()
... # actual tests

That way you know why tests are not running.

> 
> On Monday, July 23, 2018 at 8:22:17 AM UTC-4, Melvyn Sopacua wrote:
> > On maandag 23 juli 2018 13:39:27 CEST Jason wrote:
> > > you shouldn't be accessing external services with your tests
> > 
> > Non-sense. Part of interacting with a remote API is making sure it works
> > and
> > they didn't change anything (trust me, there's plenty of API's that change
> > without changing version numbers).
> > 
> > As for a global setting: no there isn't one. Your tests should have a
> > switch
> > of their own if you're worried about that.


-- 
Melvyn Sopacua


-- 
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/5218345.80TMzJj1UW%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Melvyn Sopacua
On maandag 23 juli 2018 13:39:27 CEST Jason wrote:
> you shouldn't be accessing external services with your tests

Non-sense. Part of interacting with a remote API is making sure it works and 
they didn't change anything (trust me, there's plenty of API's that change 
without changing version numbers).

As for a global setting: no there isn't one. Your tests should have a switch 
of their own if you're worried about that.

-- 
Melvyn Sopacua


-- 
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/4215975.Nr0BvRUCs3%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Good up-to-date Django report builder addons

2018-07-22 Thread Melvyn Sopacua
On zondag 22 juli 2018 11:07:45 CEST Gerald Brown wrote:
> Been there done that.
> 
> It would not select a range of dates and the date had to be specified as
> 2018-07-22, not Now() or Today().
> 
> I had 10 records that met the criteria but it only selected 2. Not very
> easy to use.
> 
> Also very limited support, did NOT reply to my questions.
> 
> Have you used it?  Did you have better results?

I haven't looked in detail yet, but I am for $work. If I have different 
results I will let you know. But we also have different requirements: our tech 
stack is built on DRF and frontend is vue-js. So, if the API works as 
advertised, it's unlikely we will be using the frontend.

-- 
Melvyn Sopacua

-- 
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/1763247.z7NN2UfXyq%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Good up-to-date Django report builder addons

2018-07-22 Thread Melvyn Sopacua
On zondag 22 juli 2018 10:34:17 CEST Gerald Brown wrote:
> I went to that site but sorry to say was UNABLE to find anything I could
> use as most are OUTDATED, written in Python 2.? ,Alpha or Beta versions
> that have not been updated in many years.

You gave up too early. I don't know why it's ranked all the way on the right, 
but this is defenitely stable and maintained and has a very good architecture:

https://djangopackages.org/packages/p/django-report-builder/

-- 
Melvyn Sopacua

-- 
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/1650919.b4eC4KpgT4%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Djando 2.0.7 image handling problem on production server

2018-07-22 Thread Melvyn Sopacua
On zondag 22 juli 2018 04:30:09 CEST mottaz hejaze wrote:
> thats why they invented virtualenv

Just so you know: pyenv is a wrapper around virtualenv, which can pin a project 
to a 
python version and just makes virtual environments easier to work with.

There's also virtualenvwrapper for somewhat the same thing, except you have to 
manually 
select the virtual environment. The combination of the two is a plugin for 
pyenv, called 
pyenvwrapper[1] .

A different approach to the same problem is mentioned by Gerald Brown.

So there are a lot of options to not work with versioned commands and the point 
I 
mentioned pyenv for is that it can read the required version for a given 
project from a 
single file in the project directory - something virtualenv cannot do.

-- 
Melvyn Sopacua


[1] https://github.com/pyenv/pyenv-virtualenvwrapper

-- 
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/5055941.sIZOHx7Dns%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Help with FilteredSelectMultiple

2018-07-21 Thread Melvyn Sopacua
On zaterdag 21 juli 2018 14:38:11 CEST Ike wrote:
> Good day everyone, I've been stuck with a problem I am having and I can't
> find any help online.

Even though you've done much effort to make a good problem description, you're 
still making us do a lot of work before we can diagnose your issue:

- imports are missing from code
- used modules (requirements.txt) are missing (where is FilteredSelectWidget 
from)
- get_success_url isn't properly indented
- the entire save code is missing (form_valid is not implemented)

It's much easier to either open source your project or setup an test project 
that actually works and has either a setup.py or requirements.txt, since this 
touches on several issues.

It's also completely unclear why you think you have to use function based 
views.

If what you really want is to have a save done as soon as a name enters or is 
removed from the box on the right, then the scope just increased tremendously 
and you need to grow frontend skills.

Otherwise, things just work out of the box (upon form submission, you can call 
form.save() in Formview.is_valid()) or the widget isn't worth it's salt.
-- 
Melvyn Sopacua

-- 
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/3656193.5LaPkouizu%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Djando 2.0.7 image handling problem on production server

2018-07-21 Thread Melvyn Sopacua
On zaterdag 21 juli 2018 19:08:03 CEST Asif Khan wrote:
> Oh dear I checked and found that Pillow was install in Python3.5 where as
> production setup is for Python3.6 so Pillow was installed by pip3.5 but not
> with pip3.6 which I have installed now.

Have a look at pyenv[1]. Relying on "versioned commands" goes wrong too 
often.

-- 
Melvyn Sopacua


[1] https://github.com/pyenv/pyenv

-- 
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/1932017.Pnh1MIuky5%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django + WSGI: no HTTP_COOKIE in environ

2018-07-21 Thread Melvyn Sopacua
On donderdag 19 juli 2018 10:34:35 CEST need_some_help wrote:

> I first need to make sure I am accessing them correctly. This is as simple
> as it gets I imagine:
> 
> view.py:
> 
> def index(environ, start_response, request):
> if not 'HTTP_COOKIE' in environ:
> response = HttpResponse("hello")
> response.set_cookie('user_agreement', 'cookie text',
> domain='.mysite.com')
> return response
> else:
> print environ['HTTP_COOKIE']
> 
> The webpage just prints 'hello' and never reaches the else not matter how
> many times I refresh the page. There are no cookies in the browser ever
> either.
> 
> Am I missing some middleware?

No, you have the wrong assumption about a view method's signature. The first 
argument 
is always the request, as in django.http.HttpRequest or more specifically, it's 
subclass 
django.core.handlers.WSGIRequest in the case of WSGI.
You're not writing a WSGI handler (who has environ as first argument). A view 
is two stops 
down and to give you the complete onion:
WSGI Handler -> Middleware -> view -> Middleware -> WSGI Handler

Anyway, the cookies are at request.COOKIES as per docs[1].
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/ref/request-response/

-- 
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/2658575.uAxzzMfALO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django "pub_date" error

2018-07-21 Thread Melvyn Sopacua
On maandag 16 juli 2018 04:52:51 CEST Daniel Tobi Onipe wrote:
> I wrote it exactly as it is in the tutorial...

Maybe that part. But you didn't define the pub_date field on the Question model 
or made a typo in the field name. Go back into models.py and check.

-- 
Melvyn Sopacua

-- 
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/7013073.8a7Clp303q%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Admin CSS Not Working in Opera or UC Browser

2018-07-21 Thread Melvyn Sopacua
On maandag 16 juli 2018 02:54:32 CEST Kayode Oladipo wrote:

> Attached is the settings file from my project.

Your settings file is not going to help. You're doing to have to dig into the 
browser's developer tools.
If you don't know how to do that, put the project online somewhere so we can 
have a look. You do *not *have to provide a login. We should be able to see 
what's wrong by just loading the admin login form.

Also, Opera for all intents and purposes is Chrome and if Chrome works, it's 
very 
likely to be a caching issue.
-- 
Melvyn Sopacua

-- 
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/2144919.41nlUsbhqF%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: How to create dynamic form field? Django 2.0

2018-07-19 Thread Melvyn Sopacua
On donderdag 19 juli 2018 16:18:07 CEST Django Lover wrote:
> This is hard for me understand can you please give some code. I am new in
> Django. PLEASE HELP ME

If you're new to Django don't try to do this and learn more about Django first. 
You don't have the knowledge to break down your problem into the right 
components, which for a Django developer up to the task would be very simple 
(as shown by the replies).
Walk before your run.
-- 
Melvyn Sopacua

-- 
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/3559019.g1zy2VpXjY%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Is there any way to disable dispatching of signals?

2018-07-19 Thread Melvyn Sopacua
On donderdag 19 juli 2018 18:22:46 CEST lorin...@gmail.com wrote:
> Is there any way to disable dispatching of signals?
> If not, I truly truly think there should be a way to do it :)
> 
> Possible use cases:
> - Prevent signals being called recursively because the signal code
> dispatched the same signal.

Subscribe to the signal with dispatch_uid[1].

> - Disable for scripts or management commands
> - Just bypass the signals on specific actions.

As Jason implies: both tasks of the observer, not the dispatcher. If a 
dispatcher does not 
call all registered observers as part of the API contract, you have no way to 
debug it (given 
that a signal dispatcher should be a black box to you) or at best you'd have 2 
places where 
things can go wrong instead of just one.

You thought up some use cases, but given the tone of your mail you mybe spent 
some 
time trying to shoehorn some code into a signal/observer pattern? Perhaps it's 
not the 
right fit for your problem.
-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/topics/signals/#preventing-duplicate-signals

-- 
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/6325556.ifQiiisRDa%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django Tutorial: "NoReverseMatch" Error

2018-07-19 Thread Melvyn Sopacua
On donderdag 19 juli 2018 20:39:15 CEST roflcopterpaul wrote:
> Yeah, I just discovered that after posting this. I'm ashamed to admit that
> single error had me baffled for days.

No shame needed, because at some point you read over and over it and read the 
same wrong thing as right in your brain. There's two tricks to it:
a) put the lines from the example below/above your line and compare above with 
below. Obviously this only works when you have an example and works better if 
you added or missed a letter.
b) ask sooner. A different set of eyes connected to a fresh brain makes  a 
world of difference. In fact, a lot of times just composing the mail can solve 
a problem as you put the code into a different setting and your brain has to 
process it again. Especially if you paste it as plain text without all the 
formatting of an IDE/editor.

-- 
Melvyn Sopacua

-- 
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/2626313.Z6rRR89q5h%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Use an external REST API in django admin

2018-07-18 Thread Melvyn Sopacua
On maandag 16 juli 2018 20:36:00 CEST Vijay Khemlani wrote:
> django rest framework would be your best bet
> 
> http://www.django-rest-framework.org/

For prosperity:

No, that would not help at all. DRF is used to *provide* an API to others. He 
wants to *use* an API as if it was a model. So save would PUT data to a REST 
api and not bother with database storage at all.

While possible, you'll have a hard time writing it as nothing in Django's 
models is going to be of any help. Getting it to perform well, is also a hard 
for a very simple reason: all your saving and loading is going to go over a 
network connection. Not to mention figuring out relations...

However, I don't understand your wish: what is the upside of storing data in a 
rest api this way?
-- 
Melvyn Sopacua

-- 
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/19903838.JmTxSYjbZD%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing Django through ssh tunneling and error to get status

2018-07-16 Thread Melvyn Sopacua
On maandag 16 juli 2018 08:56:06 CEST Dikus Extrange wrote:

> Not Found: /http:/127.0.0.1:8000/status
> Etc,etc...
> 
> 
> I wonder why the protocol has only a slash (http:/ rather http://). Could it
> be a wrong message?

This looks like a wrongly configured status monitor of some sorts, like for 
example using 
nginx health checks[1]. But there are more implementations, so don't focus on 
the nginx 
part.

Probably the quickest way to identify the culprit is to use sysadmin utilities 
like sockstat, 
netstat and similar.

-- 
Melvyn Sopacua


[1] https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/
#specifying-the-requested-uri

-- 
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/6625591.uGLnyAZ1v9%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: App structure : "One file - One object" - Is there a better way ?

2018-07-14 Thread Melvyn Sopacua
On vrijdag 13 juli 2018 13:44:21 CEST Mickael Barbo wrote:

> *I like working with " 1 file - 1 object " (Object could be class,
> function...).*
> It simplify visibility, debug etc... and it's easy for me to *don't pollute
> my brain* :-)

It only seems that way.  Debugging is actually much harder, as you jump from 
source file to source file, for the tiniest things.

My assumption is that you come from a php background, where you have single 
inheritance with autoload functionality. In php a lot is implicit, hidden and 
fragmented.

Python is a different animal. Imports are explicit. Sharing imports is a good 
thing. Bunding tiny classes (mixins, utilities) in one file is a good thing. 
Bundling related classes in a single file is a good thing.

When you really want to stick to one file per class, then you sacrifice 
performance. Where you could avoid an import for a related Django model, you 
now have to import the module and depending if you the need to avoid a 
circular import you either cause a runtime import or add extra startup time.

It's better to not adhere to such "one size fits all" rule systems but use your 
brain to construct your modules in a sensible way.

-- 
Melvyn Sopacua

-- 
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/11617338.cXBrDTWfSs%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: how to solve it view app.views.register didn't return an HttpResponse object. It returned None instead.

2018-07-13 Thread Melvyn Sopacua
On vrijdag 13 juli 2018 21:40:48 CEST Hambali Idrees Ibrahim wrote:
> i think you can use
> forms.is_valid():
> not
> form.is_valid():
> 
> it may work

No, it won't.
Jason diagnosed it correctly.

-- 
Melvyn Sopacua

-- 
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/3929766.tJMp80KjSl%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: 3719: 'utf8' is currently an alias for the character set UTF8MB3, which will be replaced by UTF8MB4 - When using MySQL sakila and world DB examples

2018-07-12 Thread Melvyn Sopacua
On donderdag 12 juli 2018 19:27:23 CEST Ram Munjuluri wrote:

> from django.db import models
> # Unable to inspect table 'city'
> *# The error was: (3719, "3719: 'utf8' is currently an alias for the
> character set UTF8MB3, which will be replaced by UTF8MB4 in a future
> release. Please consider using UTF8MB4 in order to be unambiguous.", None)*
> 
> Any suggestion here please? I seem to be stuck here.

Downgrade to MySQL 5.x or patch PyMySQL. More info:
https://github.com/PyMySQL/PyMySQL/issues/690

-- 
Melvyn Sopacua

-- 
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/2218292.uKYFzWeVbL%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: I made my first Django app, its goal is to generate a styleguide from your scss files

2018-07-12 Thread Melvyn Sopacua
On donderdag 12 juli 2018 17:13:52 CEST Carlo Ascani wrote:
> Il giorno gio 12 lug 2018 alle ore 16:44 Melvyn Sopacua
> 
>  ha scritto:
> > First and foremost: awesome job.
> 
> Thank you!
> 
> > On donderdag 12 juli 2018 14:38:16 CEST Carlo Ascani wrote:
> > > More details, if interested:
> > > https://gitlab.com/2pxsolidblack/django-marple
> > 
> > Your requirements.txt is a straight dump of pip freeze, including the `-e
> > .`. That's not maintainable.
> 
> mmm that requirements.txt is needed only for the demo project,
> I suppose I could leave that out from the package...?

It's convention that requirements.txt is for the project. You could leave it 
out, or you could rename it to requirements-demo.txt so it's clear what it's 
for. Would also make setting up "my own demo" easier.

> > I would worry about scaling: it's rather large in setup, so if for
> > instance I would load bootstrap 4's scss, would this be a gigantic long
> > page and menu?
> That's an amazing feedback, will work on that, thank you!

Related:
Normally, I setup:
scss/bootstrap.scss scss/bootstrap/variables.scss scss/bootstrap/color-
variables.scss and maybe a few others that override the standard bootstrap 
settings and reference the package files in node_modules/ for the originals.

I wouldn't need documentation on the original bootstrap files, in fact, I'd 
like my style guide to show only the files in scss/* not references in those 
files to locations outside of it.

Maybe a little more complex so a long term goal for you :)

-- 
Melvyn Sopacua

-- 
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/6425602.xWjK9ymFqQ%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: I made my first Django app, its goal is to generate a styleguide from your scss files

2018-07-12 Thread Melvyn Sopacua
First and foremost: awesome job.

On donderdag 12 juli 2018 14:38:16 CEST Carlo Ascani wrote:

> More details, if interested: https://gitlab.com/2pxsolidblack/django-marple

Your requirements.txt is a straight dump of pip freeze, including the `-e .`. 
That's not maintainable.

I would worry about scaling: it's rather large in setup, so if for instance I 
would load bootstrap 4's scss, would this be a gigantic long page and menu?

Keep at it!
-- 
Melvyn Sopacua

-- 
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/2153578.lO0Rj1njIq%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Using multiple keyword arguments with reverse()

2018-07-10 Thread Melvyn Sopacua
On maandag 9 juli 2018 14:58:25 CEST Derek wrote:
> Thanks Melvyn
> 
> The call to reverse() *was* included in my original code snippets: see
> below.
> 
> > return HttpResponseRedirect(
> > 
> > reverse('uploads:upload_details',
> > 
> > kwargs={'view': view, 'mid':result.pk})
> 
> And that call does not work.

Ah, totally read over it. But - it *does* work, otherwise upload_details 
wouldn't get called, 
since the url would not have a 3 in it.

Your problem is somewhere else and I still don't get how the decorator ties in. 
Try to 
reduce it to an mcve[1].
-- 
Melvyn Sopacua


[1] https://stackoverflow.com/help/mcve

-- 
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/2047086.mNi3lG958X%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django + WSGI: no HTTP_COOKIE in environ

2018-07-10 Thread Melvyn Sopacua
On dinsdag 10 juli 2018 14:40:41 CEST need_some_help wrote:
> I've followed numerous examples, but the only one that does not return
> errors are the implementations of the two functions below. There doesn't
> seem to be an HTTP_COOKIE key in the environ. The request value only gets
> set with POST and GET. Think something is wrong with my setup, because none
> of the common usage patterns I've seen online like request.POST don't work.

...

> You can see their is no HTTP_COOKIE in the keys. If I'm not setting it
> right, or there's something I need to check, please let me know.

Do you know how cookies work? Specifically, that on the first request to a 
server by a new browser (or command line), there never are cookies?

-- 
Melvyn Sopacua

-- 
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/3648020.a4HAOye7Rv%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django-Autocomplete-light Styling Input Box

2018-07-10 Thread Melvyn Sopacua
On dinsdag 10 juli 2018 15:24:16 CEST umar...@gmail.com wrote:

> But now I'm not able to change the input box create by autocomplete-light.
> I've seen we can create ours custom html base on the receive data from the
> database but is there a way to just use the default Html and CSS created by
> the framework and change some styling attribute like width, of height ?

Yes you can:
- Override html[1] 
- Pass options to Select2[2] 

P.S. Excellently formulated question.
-- 
Melvyn Sopacua


[1] 
http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#displaying-results-using-custom-html
[2] 
http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#passing-options-to-select2

-- 
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/1762850.8RUfgpKREi%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Caching JSON in Django

2018-07-09 Thread Melvyn Sopacua
On maandag 9 juli 2018 09:19:59 CEST Ravi Bhushan wrote:

> plzz help me to solve this problem

Ask more times. It really helps getting you quality auto ignores.
-- 
Melvyn Sopacua

-- 
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/2838446.qCC5UmfGUK%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Using multiple keyword arguments with reverse()

2018-07-08 Thread Melvyn Sopacua
On zondag 8 juli 2018 13:58:33 CEST Derek wrote:

> I am attempting to pass multiple keyword arguments from a reverse() call
> (from my app called `uploads`).

There's no call to reverse in your code. But to do this:

reverse('upload_details', kwargs={'view': 'site', 'mid', 3})

> *urls.py*
> 
> urlpatterns = [
> url(
> regex=r'^add/$',
> view=views.add_new,
> name='add_new'),
> url(
> regex=r'^details/(?P[a-z.]+)/(?P\d+)?$',
> view=views.upload_details,
> name='upload_details'),
> ]
> 
> *views.py*
> 
> def add_new(request)
> # ... process data via a form; create a result object
> return HttpResponseRedirect(
> reverse('uploads:upload_details',
> kwargs={'view': view, 'mid':result.pk})
> )
> 
> def upload_details(request, view='site', mid=None):
> # ... run process based on view and mid args
> 
> 
> When the `upload_details` view gets called, the 'mid' does not set (even
> though it has a valid integer value); examining the
> contrib/auth/decorators.py file in debug mode:
> 
> def decorator(view_func):
> @wraps(view_func, assigned=available_attrs(view_func))
> def _wrapped_view(request, *args, **kwargs):
> if test_func(request.user):
> return view_func(request, *args, **kwargs)

And how is that relevant as well? I think you're missing some code in your 
copy, cause this decorator also is not in your view code.

-- 
Melvyn Sopacua

-- 
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/3786925.Ha4mB3saOt%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: Attempted relative import in non-package

2018-07-08 Thread Melvyn Sopacua
On zondag 8 juli 2018 08:40:03 CEST darkblakh...@gmail.com wrote:

> Traceback (most recent call last):
> File "/root/Desktop/website/movies/views.py", line 4, in 
> from .models import mdb
> ValueError: Attempted relative import in non-package

You should really create your "movies app" with:

`python manage.py startapp movies`

That will create the correct boilerplate.

-- 
Melvyn Sopacua

-- 
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/2248183.zDUnD0f5Bq%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: JSON serializable issue

2018-07-07 Thread Melvyn Sopacua
Hi,

> However i am not
> sure about it and i cannt find where to looking for. I am sending an
> attachment with the bug. I have many days with it.
> Thanks for any idea.


This looks like you're trying to store an exception in a session, using the 
JSON session backend. Since json doesn't know how to serialize an exception 
object, it bails out.

The underlying problem is that you're trying to store more then 80 chars into 
a field with max lenght 80. Without code, it is impossible to tell how the two 
relate.

-- 
Melvyn Sopacua

-- 
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/6363934.dWIXy7cGKv%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django DateField

2018-07-06 Thread Melvyn Sopacua
On vrijdag 6 juli 2018 16:46:08 CEST 'dtdave' via Django users wrote:
> Many thanks for the help on this. I have implemented the following:
> models.py
> start_date = models.DateField(null=True, blank=True,)
> asap = models.BooleanField(default=False)
> 
> I have amend my manager so the order is right on the template.
> The template is where I am going wrong.
> This what I have started with in my template;
> {% if 'job.asap' == 'True' %}
> Start Date: {{job.asap}}

{% if job.asap %}
Start Date: {% trans "as soon as possible" %}
{% else %}
 Start Date: {{job.start_date}}
{% endif %}

-- 
Melvyn Sopacua

-- 
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/3475945.xbvqS7dl4M%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: tests pass individually but fail together

2018-07-05 Thread Melvyn Sopacua
On donderdag 5 juli 2018 18:07:58 CEST clavierpla...@gmail.com wrote:
> It's a script that's supposed to run in the background for an inventory
> management program. The basic idea is that it periodically collects Order
> objects that are associated with a particular Status (1-M foreign key,
> though more like 1-1 in practice). Orders have one or many Orderlines. Then
> it makes all the necessary changes to various quantity fields in various
> inventory tables. So if an Orderline contains a request for 3 of a
> particular item, then 3 of that item are reserved in inventory (or
> backordered or however it needs to go). So far that part has been fine.
> 
> But when that's finished, the Orders and associated Orderlines need updated
> Statuses. The assert statements say that only some of them were updated,
> even though I watched them all update correctly--it's like a partial
> rollback happens before the test finishes. The other failing test checks
> that the process of updating the statuses also logs the events properly in
> a History table; but when the test is run as a suite, the event is only
> partially logged--some records are created and some aren't. But the test
> results are always consistent for the way the test was run.

My first instinct is to run  the suite with `--parallel 1` and see if that 
changes anything. Also, it really helps to have some code - if only to see how 
the methods relate to each other if at all.

-- 
Melvyn Sopacua

-- 
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/18693819.ysi9JWK4Ts%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django DateField

2018-07-05 Thread Melvyn Sopacua
On donderdag 5 juli 2018 19:05:47 CEST 'dtdave' via Django users wrote:

> However, now I have been asked to change this so that some projects have a
> start date of ASAP and others have date.
> These then need to be listed in my template with ASAP tasks coming first
> and then those with a start date coming in descending order.
> 
> I am at a loss as to how to achieve this so would welcome any pointers or
> ideas.


Asap field is a boolean. Date field needs to be able to be blank and null.
Then:

tasks = Task.objects.order_by('asap', '-start_date')

Done :)
-- 
Melvyn Sopacua

-- 
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/1733804.HaluoI3dcq%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: help with learning path

2018-07-05 Thread Melvyn Sopacua
On donderdag 5 juli 2018 14:45:11 CEST backintow...@gmail.com wrote:

> I have been learning python and Django for the past 12 months, however, I
> seem to be stuck with moving forward. I have completed basic tutorials,
> read beginner and some intermediate books. The problem I'm having is
> finding a learning resource somewhere between intermediate and
> professional. 

I find that the intermediate path in any programming language is doing things 
yourself and getting experience.  Learn to recognize how certain bugs 
manifest, how to setup a project and how to writing libraries / mechanisms.

If you keep working from examples, you're limiting yourselves to those 
examples and there's a lot of "howto" stuff out there of varying quality.

If I'd had to think up a project, that is actually useful in this day and age 
try coding a site using a vue.js frontend with a Django Restframework backend, 
no Django templates at all. Borrow code here and there, but do not work from 
examples. Learn to find your own path from user requirements to technical 
architecture to detailed implementation.

For bug tracking skills - a good way is picking up bugs in Django itself, by 
regularly visiting the bug tracker.

Good luck!
-- 
Melvyn Sopacua

-- 
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/2366002.rELHsNdlzO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-07-02 Thread Melvyn Sopacua
On vrijdag 29 juni 2018 09:44:40 CEST Mickael Barbo wrote:

> I try to create a way to archive (copy) the same object instance on an
> other DataBase.
> 
> I followed this advice : # https://stackoverflow.com/
> questions/21699707/python-how-to-copy-all-attibutes-from-
> base-class-to-derived-one

That advice is for normal python classes. Django models have some restrictions, 
one 
being that fields are special attributes. Messing with a model's __init__() is 
not something 
you normally do as a model's class creation is highly customized.

If you're really using 2 different databases, a model's save() operation 
supports a `using` 
keyword that allows you to select the database connection[1]. Archiving becomes 
really 
easy that way.


-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#selecting-a-database-for-save

-- 
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/2130083.vAuLGcjiVo%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid HTTP_HOST header when website being accessed by public IP

2018-07-02 Thread Melvyn Sopacua
On maandag 2 juli 2018 17:25:20 CEST Kasper Laudrup wrote:

> Instead I added the following to my HTTPS server section:
> 
> if ($host != my-website.org {
> return 404;
>  }
> 
> Seems to solve my problem just fine. Letsencrypts certbot had already
> done something similar for the HTTP section redirect.

The only reason to set it up like that for HTTPS is that it's possible the SNI 
name differs from the HTTP Host header. For HTTP redirects it makes no sense: 
the HTTP header is in plain text and is used to determine the server block to 
pick. So putting an if statement there, is just doing it again, on every 
request, because electrons are cheap. Save the electrons!

Anyhow - instead of return 404, I would do:

return 301 https://$server_name$request_uri

How I normally set things up:

server {
listen 443 default_server ssl http2;
server_name localhost;

return 301 https://djangoserver.example.com$request_uri
}

server {
listen 443;
server_name djangoserver.example.com;

# ... django setup
}
-- 
Melvyn Sopacua

-- 
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/1733971.5nBxyqRtuB%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model fields using mysql?

2018-07-02 Thread Melvyn Sopacua
On maandag 2 juli 2018 21:33:35 CEST hardik dadhich wrote:

> Can anyone tell me how can I make dynamic Django model fields? I mean to
> say that I want to save excel file data in Django model using MySQL. and
> excel column can vary. The user can upload 100 column table or he can be
> upload 1000 column table in the database. so it is possible to add
> dynamically in db.

It makes little sense to store this in a database, because you cannot define 
relations for 
what you don't know about. But if you must ...

One way to do this is to use the EAV data model[1]. This is because at 1000 
columns = 1000 
fields, you will most certainly hit MySQL's maximum row size[2].

-- 
Melvyn Sopacua


[1] https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model
[2] https://dev.mysql.com/doc/refman/5.7/en/column-count-limit.html

-- 
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/1682319.7IaycB50Qv%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid HTTP_HOST header when website being accessed by public IP

2018-07-02 Thread Melvyn Sopacua
On zondag 1 juli 2018 19:10:15 CEST Tomasz Knapik wrote:

> Maybe you could restrict host headers at the nginx layer, but I don't
> think it's worth your effort... 

If you think of it like that it seems like a lot of work. But if you simply 
setup a default 
server that redirects to the actual Django server with correct hostname, then 
all you 
need is 2 server blocks: 1 default, 1 with correct `server_name`.

See Request Processing[1] for more background information and tricks.
-- 
Melvyn Sopacua


[1] http://nginx.org/en/docs/http/request_processing.html

-- 
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/1649516.A6oeUnqeAf%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Isolated virtualenv and mod_wsgi - how do I do this on Apache

2018-07-01 Thread Melvyn Sopacua
On donderdag 28 juni 2018 17:46:42 CEST Bruce Whealton wrote:

> In all cases, a virtualenv is recommended for any Python
> deployment.  In both cases, I have Apache as the web server with mod_wsgi.
> Obviously, I need the server, Apache, to activate the
> Django environment.  I can ssh to my VPS but what good is that.  I don't
> need my username to be activating the Python isolated environment.  As soon
> as I close the ssh session the activated environment
> is no longer activated.  My best guess is that the Apache user must
> activate the virtual environment and keep it activated as an isolated
> virtual environment.

Virtualenv "activation" is not magic. It simply adjusts PATH so that the 
virtualenv's bin directory is first. This means that whenever "python" or "pip" 
is typed into the shell it will not execute `/usr/bin/python` but
`your-virtualenv/bin/python`. Handing apache a sanitized PATH with the 
virtualenv bin dir as first directory, will effectively do the same as 
"activation".

(To be complete: activate also alters your shell prompt, this has no effect in 
one-off application launches).

-- 
Melvyn Sopacua

-- 
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/2410185.edddNGrWiM%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: post_save signal is not dispatched

2018-06-24 Thread Melvyn Sopacua
On zondag 24 juni 2018 15:45:47 CEST Dejan Spasić wrote:
> def post_save_user(**kwargs: Dict[str, Any]) -> None:
> if kwargs['created']:
> return None

So for new users, you bail out and do nothing. Your code works exactly as you 
wrote it.

-- 
Melvyn Sopacua

-- 
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/1595824.LYJT9xCsNO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /feedback/by/feedback/new Cannot assign "": "Feedback.user" must be a "User" instance.

2018-06-24 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 21:10:27 CEST Saloni Kalra wrote:
> Thank you for your reply. I removes all the migrations and dropped the
> database. Now when I try to make migrations i get the following error in my
> terminal.
> Thanks and regards,
> Saloni
> 
> *Error:*
> accounts.User.user_ptr: (fields.E301) Field defines a relation with the
> model 'auth.User', which has been swapped out.
> HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

I suggest you read and understand this entire section:
https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#auth-custom-user


-- 
Melvyn Sopacua

-- 
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/5782852.cBHu3mGn29%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /feedback/by/feedback/new Cannot assign "": "Feedback.user" must be a "User" instance.

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 10:52:09 CEST Saloni Kalra wrote:
> https://github.com/salonikalra/feedback
> This is a feedback application for teachers by the students. I have been
> constntly getting the following error:
> ValueError at /feedback/by/feedback/new
> Cannot assign "": "Feedback.user" must be a "User" instance.

You're using a custom user model, but have not set AUTH_USER_MODEL[1].

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model

-- 
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/1971033.SWcSYpt7Ld%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django Postgres Intermediary doesn't set ON DELETE CASCADE

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 14:40:30 CEST Jason wrote:
> Not quite.  If you run python manage.py sqlmigrate 
> , you can see the SQL generated for that migration.
> 
> https://docs.djangoproject.com/en/2.0/ref/django-admin/#django-admin-sqlmigr
> ate
> 
> Because Django emulates Cascade, its done outside of the db, and therefore
> shouldn't be a db-level constraint.

The case for and against can be made pretty much with the same argument:
- for: if a row is deleted outside of Django, so by direct database 
manipulation, then the relations become inconsistent, so having database 
reflect models prevents this.
- against: if a row is deleted outside of Django, so by direct database 
manipulation, then signals are not processed and objects are deleted 
regardless. The consequences of this are unpredictable and application 
specific.

Django chose to not align model relations with database representation. 
Knowing this means you have to handle things through Django exclusively where 
it matters.

-- 
Melvyn Sopacua

-- 
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/2141218.LMxEerG5hG%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 14:30:08 CEST Mikkel Kromann wrote:

> In models.py:
> def GetItemPaths():paths = [ ]
> for i in [ 'Model1', 'Model2', 'Model3' ]:
> p = path( i + '/list/', ItemListView.as_view(model=i), name=i +
> '_list' )
> paths.append(p)
> 
> return paths
> 
> However, there seems to be a problem with trying to pass the model name to
> my CBV ItemListView.
> Unless I replace the model=i with e.g. model=Model1 I get the following
> error:
> 
> 'str' object has no attribute '_default_manager'
> 
> 
> So it certainly seems that using model=i will not pass the model name.
> Is this because the argument for model= expects not a string but an object?

Yes. You can use import_module from django.functional to pass a dotted path. 
Or you can use apps.get_model() to get a model class for a app name / model 
name combo.

-- 
Melvyn Sopacua

-- 
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/2271710.2KSSaTsjz5%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django Postgres Intermediary doesn't set ON DELETE CASCADE

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 00:56:36 CEST James Bellaby wrote:

> However when looking are the SQL in Postgresql it's created the Membership
> table constraint for the Group id with "ON DELETE NO ACTION"
> 
> CONSTRAINT groups_membership_group_id_d4404a8c_fk_groups_group_id FOREIGN
> KEY (group_id)
> REFERENCES public.groups_group (id) MATCH SIMPLE
> ON UPDATE NO ACTION
> ON DELETE NO ACTION
> DEFERRABLE INITIALLY DEFERRED,
> 
> My understanding was that setting CASCADE on the group in the Membership
> modal would set ON DELETE CASCADE for the Membership table CREATE?
> 
> If it's not a bug and I've missed something, I apologies in advance.

You missed the part where Django implements this at the application level by 
emulating 
this[1]. This is (among other things) to be able to run signals[2], which it 
can't do if the 
database is doing the deletion.

-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.CASCADE
[2] 
https://github.com/django/django/blob/master/django/db/models/deletion.py#L276

-- 
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/1923431.bMXvI7QtcM%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: prevent AppConfig.ready() from running twice

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 02:01:06 CEST Mike Dewhirst wrote:

> Is there a python singleton pattern which might work?

No, cause the startup is done in 2 different processes which do not share 
state. So both processes will have a "new singleton".
This is why you need an IPC mechanism, such as file locks or shared memory. In 
the case of one-off launchers, it's usually easier to implement the 
restrictions on the client side (the program being launched). Long running 
launchers (like inetd, systemd) can prevent double launch in other ways as 
they can keep their own state.
-- 
Melvyn Sopacua

-- 
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/3828451.OQlbSIQ3MC%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid URLs passing validation by URLValidator

2018-06-22 Thread Melvyn Sopacua
On vrijdag 22 juni 2018 02:50:08 CEST Tim Bell wrote:

> http://#FOO#/b...@example.com
> 
> I believe that this is passing validation because "#FOO#/bar" is being
> treated as a username, with "example.com" as the hostname. However,
> "#FOO#/bar" shouldn't be valid as a username because the "#" and "/"
> characters aren't percent-encoded.

You are right about the slash. Not about the pound sign:
"The user name (and password), if present, are followed by a
commercial at-sign "@". Within the user and password field, any ":",
"@", or "/" must be encoded." - RFC 1738, section 3.1.
This is because the pound sign doesn't have a special meaning until after the 
hostname.  
However, officially, HTTP urls do not allow for username and password as 
outlined in 
section 3.3:

An HTTP URL takes the form:

  http://:/?

where  and  are as described in Section 3.1. If :
is omitted, the port defaults to 80.  No user name or password is
allowed.

So then, the parsing becomes:
scheme  = http
host = foo
path = /b...@example.com/

Which also brings us to the reserved character portion:
Many URL schemes reserve certain characters for a special meaning:
their appearance in the scheme-specific part of the URL has a
designated semantics. If the character corresponding to an octet is
reserved in a scheme, the octet must be encoded.  The characters ";",
"/", "?", ":", "@", "=" and "&" are the characters which may be
reserved for special meaning within a scheme. No other characters may
be reserved within a scheme.

Which means, that in http scheme, @ is not reserved and as such does not have 
to be 
encoded.

That said - Django still validates the ftp variant as being correct, so the bug 
is still there 
and nice catch!
-- 
Melvyn Sopacua

-- 
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/3531137.DPOh9oWQhX%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: prevent AppConfig.ready() from running twice

2018-06-22 Thread Melvyn Sopacua
On donderdag 21 juni 2018 16:23:23 CEST clavierpla...@gmail.com wrote:

> If it helps, here is the reason I need to override this multi-instantiation
> behavior: my application launches a multiprocessing.Process at startup to
> monitor and run background tasks. Having more than one background Process
> running at once is going to wreak havoc on the application. I've looked at
> other options to accomplish similar purposes, but those would all be
> instantiated multiple times, also.
> 
> Any suggestions?

Use a locked pidfile to prevent multiple daemons starting up. I recall the 
python-daemon package being capable of this (and lots of other good stuff).

https://pagure.io/python-daemon/
-- 
Melvyn Sopacua

-- 
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/139066525.eYAS18T7Ez%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django says a modification was made to Auth user when I didn't, and migration has a timestamp from the future. Help?

2018-06-22 Thread Melvyn Sopacua
On vrijdag 22 juni 2018 05:36:42 CEST JJ Zolper wrote:
> It's Jun 21 at 11:30 pm in my world fyi.
> 
> On Thursday, June 21, 2018 at 11:34:50 PM UTC-4, JJ Zolper wrote:

And 23:30 + 4 = 27:30 = 3:30 next day. Django generates migration timestamps 
in UTC time.

> > You'll see the timestamp on this post and here's the migration it thinks
> > it needs to make:

Do you have a custom user model?
-- 
Melvyn Sopacua

-- 
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/2474311.fTER52XSdO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Forms in Bootstrap 4 Modals?

2018-06-21 Thread Melvyn Sopacua
I have a lot of this stuff worked out, but for Bootstrap 3. I've done this in a 
UX library I've 
used for various projects, so it's kinda of a need-driven collection of 
widgets, CBV's and 
form components - not exactly something for general use.

I've made it available on Gitlab, so you can see how you add various modals to 
a single 
view. In my case I mostly used a context menu to launch the modals, but I never 
bothered 
with the Ajax part, instead the forms get submitted normally, generating a page 
reload. 
That part you have to do yourself, but there's a lot in there you can build on:

- Wrapper for a Form[1] 
- Mixins to handle addtional forms[2] 
- Template tags to render a bootstrap 3 modal[3] 
- etcetera...


And here's an example of a view from a project management tool that I wrote 
with it:

class ProjectDetailView(DefaultPageMixin, AdditionalFormsMixin,
ContextMenuMixin, generic.DetailView):
model = models.Project
context_object_name = 'project'
template_name = 'view/project.html'

def generate_context_menu(self) -> None:
self.add_active_menu_link('view_project', _('View Project'), icon='eye')
self.add_context_menu_modal(
'edit_project', _('Edit Project'), 'edit-project', icon='pencil',
title=_('Edit current project')
)
self.add_context_menu_modal(
'add_task', _('Add Milestone'), 'add-task', icon='plus-square',
)

def generate_additional_forms(self):
proj_update_url = reverse('core:project_edit',
  kwargs={'slug': self.object.slug})
task_create_url = reverse('core:project_task_create')
self.add_additional_form(
'project_update_form', forms.ProjectForm, proj_update_url,
model_instance=self.object,
)
self.add_additional_form(
'add_milestone_form', forms.NewProjectTaskForm, task_create_url,
initial={'project': self.object, 'is_milestone': True},
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
del context['object']
project = self.object  # type: models.Project
context['has_milestones'] = project.has_milestones
context['milestones'] = project.milestones.order_by('sequence', 'title')

return context

I may clean up the library for more general use, but in the mean time, hope 
this helps you 
along with your quest.

On donderdag 21 juni 2018 18:23:26 CEST Alexander Joseph wrote:
> Awesome! Thanks Kirby, I will try that out and let you know
> 
> On Thu, Jun 21, 2018 at 10:12 AM, C. Kirby  wrote:
> > Ok, this is good to work with. Let us tackle this issue by issue. The
> > first issue is that your modal is not showing up. I see several possible
> > issues:
> > 
> > Replace
> > 
> >   Click here to show the modal
> > 
> >  with
> > 
> > Create a new wafer
> > design
> > 
> > Having the href in the a tag makes it want to load to a new page, but also
> > load the modal, I think. Since you reference the form url in the ajax call
> > you don't need it in an a tag. Also in the bootstrap4 api reference it
> > only
> > launches modals from buttons, not from  tags
> > 
> > Next/if that doesn't get you a further I would check to make sure teh
> > modal structure is correct before worrying about the ajax call.
> > 
> > Put the contents of the gaas_wafer_design_form.html into the modal in
> > gaas_wafer_design_list.html. Remove the form elements and just have a
> > complete, static bootstrap modal on the page. Also comment out the
> > on(show.bs.modal). Noting the date on the tutorial it looks like it might
> > be using an alpha or beta version of bootstrap4. If you can't get a static
> > modal to show up this way then you will have to go take a look at the
> > bootstrap4 api and match the modal structure.
> > 
> > If you have the same/new issues after trying those we can tackle them next
> > 
> > Kirby
> > 
> > --
> > You received this message because you are subscribed to a topic in the
> > Google Groups "Django users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/
> > topic/django-users/CPspzgE33Dk/unsubscribe.
> > To unsubscribe from this group and all its topics, 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/53d50894-98f7-4d92-a1c2-0a9d61e19fea%40googlegroups.com
> >  > 9d61e19fea%40googlegroups.com?utm_medium=email_source=footer> .
> > 

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

Re: saving django session data for anonymous user

2018-06-21 Thread Melvyn Sopacua
On woensdag 13 juni 2018 14:40:05 CEST Siddharth Srivastava wrote:
> Thanks  Anthony for your prompt reply. current implementation is that i am
> using django orm query to pull the user cart details and cart id(session
> key) is the key so when user switch from anonymous
> user to actual user then i loses the data came from the query.
> 
> so when user gets authenticated then it create new session id then previous
> session data we lose. I am not finding much help in google:(.

This is a very bad design. Why don't simply store the cart ID in the session, 
rather then using a session ID for a cart's ID? This is just one of the 
problems you're going to face.
For example, implementing abandoned cart reminders is going to be no joyride 
and pretty much standard functionality in e-commerce these days. Sessions are 
there to store data and Django automatically copies the data in the session 
from anonymous user to logged in user. It's what sessions are made for.

-- 
Melvyn Sopacua

-- 
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/3751359.ac4gruEBS1%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: How to fill latitude and longitude values from an existing location field in Django+Python?

2018-06-21 Thread Melvyn Sopacua
On donderdag 21 juni 2018 14:29:17 CEST prateek gupta wrote:
> Got it Jason, I will not post anymore now.

Well, not the same question at least. The second one was better, since it was 
specific. What you're asking with this question is too broad and doing it on 
stackoverflow will yield the same results.

You're basically asking us to code it for you, because you have a  deadline 
and not enough understanding of Django or it's eco system. There are a lot of 
helpful people on this list, but if you want this done on the short term, you 
can enlist someone to tutor you or cooperate on the project with you. 
Naturally, you should offer some incentive to people as this isn't a simple 
Question & Answer problem.

-- 
Melvyn Sopacua

-- 
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/2859111.WbdiAzZ8Y1%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Why some Django fields are not saved in database?

2018-06-21 Thread Melvyn Sopacua
On donderdag 21 juni 2018 11:31:26 CEST prateek gupta wrote:

> Thanks for reviewing the code.
> 
> I am new to Django and just tried to put logic from googling to achieve my
> goal.
> That's why I don't understand my code completely.

Try to understand it before applying. The main issue you're facing is the 
difference 
between class attributes and model fields.

A model field is a special class attribute that Django stores in the database. 
You have to 
declare them using one of the field types[1] that Django supports.
Everything else is not saved in the database.

You're using a custom model field[2] for the location in your model. Part of 
that field is 
that it stores in the lon/lat information for you, so that you don't have to 
worry about it. 
What it doesn't provide is a solid way for you to get the location data from 
the field. As 
you've figured out, it is stored as a string, which makes it difficult to make 
queries on lon/
lat coordinates.

So it's probably not the right tool for the job. But before you go looking for 
a different 
package, you should really learn more about Django, for example complete the 
tutorial 
and in your case it'll be helpful to go through the GIS tutorial[3] as well. 
Cause then you'd 
discover that other then support for Mapbox and Google maps, Django already has 
built 
in most of what the DJango Location Field package is offering you.

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/ref/models/fields/
[2] https://docs.djangoproject.com/en/2.0/howto/custom-model-fields/
[3] https://docs.djangoproject.com/en/2.0/ref/contrib/gis/tutorial/

-- 
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/4665207.94lpJElZK9%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Why some Django fields are not saved in database?

2018-06-21 Thread Melvyn Sopacua
On donderdag 21 juni 2018 10:42:09 CEST prateek gupta wrote:

> Issue is in database , latitude/longitude values are blank.
> 
> What I am doing wrong here?

Why do you not understand your own code? How did you get that code - you 
explicitly code it so that it they do NOT end up in the database. So why are 
you asking why?

-- 
Melvyn Sopacua

-- 
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/117666335.BCEecK4HXi%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-21 Thread Melvyn Sopacua
On donderdag 21 juni 2018 10:19:08 CEST Mikkel Kromann wrote:

> However, I'd really like to give all my urls names so that they can be
> easily reversed (e.g. success links).
> urlpatterns = [
> path('list//',ItemListView.as_view(),  name=
> mName+'_list'),
> ]
> 
> From what I can see, my model name mName is passed only to the view and
> apparently not to the name constructor inside urls.py
> Also, while I do not entirely understand the reverse naming process, I
> sense that it might not be too easy to reverse the url name if it is not
> spelled out directly.
> 
> Are there any options for handling this in urls.py?

Take a look at crudlfap's Router class to see how to generate dynamic urls. In 
short: let a router who generates views for models generate the urlpatterns. 
All django is looking for is an iterable that is named 'urlpatterns' in a urls 
module.

https://github.com/yourlabs/crudlfap/blob/master/src/crudlfap/router.py#L274
-- 
Melvyn Sopacua

-- 
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/7023284.eSgYguR0o7%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: python inspectdb got "The error was: function unnest(smallint[]) does not exist"

2018-06-21 Thread Melvyn Sopacua
On woensdag 20 juni 2018 19:12:00 CEST weiwei.hs...@keeptruckin.com wrote:

> When I run "python3 manage.py inspectdb", I got below error messages:
> 
> 
> # Unable to inspect table 'eld_messages'
> 
> # The error was: function unnest(smallint[]) does not exist
> 
> HINT:  No function matches the given name and argument types. You may need
> to add explicit type casts.

Unnest is a PostgreSQL specific array function, that doesn't have a counterpart 
in Django's ORM, so Django does not know how to handle that.

In most cases I'd say, try to write a function for it, but in this case it may 
be better to refactor the table. Do you know the function of the table and why 
it would need an array of small ints stored? Can it be refactored to use 
another table?
-- 
Melvyn Sopacua

-- 
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/2071092.vFfFbuVlZb%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: saving django session data for anonymous user

2018-06-12 Thread Melvyn Sopacua
On dinsdag 12 juni 2018 12:01:32 CEST Siddharth Srivastava wrote:

>  so the scenario is that whenever anonymous
> user check out and mapped data against that session id is purged. Is there
> any mechanism to save anonymous user session data even after user logs in.
> kindly provide easy possible solution as i am bit new to django:)


Well, the easy solution is to follow the documentation[1]:

Note that any data set during the anonymous session is retained in the
session after a user logs in.

-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/topics/auth/default/#how-to-log-a-user-in

-- 
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/1614496.8M6cUJZ5yO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Passing Django Template Vars to JS

2018-06-11 Thread Melvyn Sopacua
On maandag 11 juni 2018 20:11:36 CEST Simon Connah wrote:

> I like the idea of the custom attribute. I'll do that then.

The common way is to use a data- attribute[1].
-- 
Melvyn Sopacua


[1] https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/
Use_data_attributes

-- 
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/2026797.eeRFsSjbx6%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote:
> > > It is the default hostname for django.contrib.sites
> > 
> > <https://github.com/django/django/blob/master/django/contrib/sites/managem
> > ent.py#L28> with SITE_ID = 1.
> 
> OK - so that might be a smoking gun that I have not configured the "sites"
> model correctly? I have so far not really related to the "sites"
> functionality at all.

It's enabled by default. And from the admin you can edit that hostname and add 
more sites.
Because Django supports multiple sites with a single admin, it generates fully 
qualified URLs for the "view on site" functionality, if django.contrib.sites is 
in INSTALLED_APPS.

-- 
Melvyn Sopacua

-- 
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/1591437.ilrU06Q2TX%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 13:30:51 CEST Joakim Hove wrote:

> things do not work from the Admin. When I click on the "View on Site" link
> i am redirected to "http://example.com/transaction/view/23635/; and I get
> an error message about failed XML parsing. I have no clue where the
> "example.com" address comes from - that string is not in my codebase.

It is the default hostname for django.contrib.sites[1] with SITE_ID = 1.
-- 
Melvyn Sopacua


[1] https://github.com/django/django/blob/master/django/contrib/sites/
management.py#L28

-- 
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/2721239.SktWtCEFV2%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: bootstrap to the login template

2018-06-07 Thread Melvyn Sopacua
On woensdag 6 juni 2018 22:58:50 CEST G.R. Nobles wrote:
> Below are two forms, the login form (top) and a bootstrap form (bottom),
> I'm trying to apply bootstrap to the login page, how can I integrate
> bootstrap onto the login objects, e.g. {{ form.username }} is the entire
> textbox, so I'm at a loss being a beginner with Django (my first week).

I find this difficult to answer, because you mention "apply" and "integrate" 
bootstrap. You have a certain expectation there.

What is that expectation?

-- 
Melvyn Sopacua

-- 
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/1650404.2fMrPQvyA6%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-06 Thread Melvyn Sopacua
On woensdag 6 juni 2018 18:25:35 CEST 'Anthony Flury' via Django users wrote:
> Does the test client execute javascript as well ? I can't remember.

No. Not even the HTML.

For that you need selenium, which is a whole different beast. The test client 
is used for "unit tests for views". Selenium is in the realm of integration 
tests, or acceptance tests if you will. It validates the end result, not a 
unit of code.
-- 
Melvyn Sopacua

-- 
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/2061765.he2AIJnB6B%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Sponsor subdomain pointing to part of our Django site?

2018-06-04 Thread Melvyn Sopacua
On maandag 4 juni 2018 20:40:03 CEST Richard Brockie wrote:
> On Mon, Jun 4, 2018 at 9:01 PM Melvyn Sopacua  wrote:
> > This isn't a problem. Neither url nor reverse is capable of returning URLs
> > with hostnames, at least not that I'm aware of. Only django.contrib.site
> > <https://docs.djangoproject.com/en/2.0/ref/contrib/sites/#getting-the-curr
> > ent-domain-for-display> module can do this for out-of-band communications.
> 
> Aha - there's an error in how I posed the question. I was confusing the url
> and reverse() outputs with the links as interpreted by a browser.
> 
> If http_host is ''subdomain.sponsor.url" we are at the site using the
> sponsor's alias which maps to a unique "/year/slug/" on our site (just one
> of many). In this case, we require the output of {% url %} and reverse() to
> have 2 possibilities:
> 
>1. Normal operation (with our default http_host): returns the full path:
>"/year/slug/some/more/path/"
>2. Sponsor http_host: returns a trimmed path: "/some/more/path". Here
>"/year/slug" is suppressed as it is built into the
> ''subdomain.sponsor.url" alias.
> 
> I hope this clarifies what we think we need to do

Aha! Now I get it! This should be solveable at the WSGI layer:

PATH_INFO
The remainder of the request URL's "path", designating the virtual "location" 
of the 
request's target within the application. This *may* be an empty string, if the 
request URL 
targets the application root and does not have a trailing slash.

See https://www.python.org/dev/peps/pep-0333/

A URL rewrite or proxy at the webserver level should work as well. It may take 
a bit of 
experimenting.

-- 
Melvyn Sopacua

-- 
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/8690183.REoEi0XuKK%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: python manage.py (anything) NOT WORKING ANYMORE

2018-06-04 Thread Melvyn Sopacua
On maandag 4 juni 2018 12:58:39 CEST Gerald Brown wrote:
> I have been using ./manage.py shell for awhile and now all of a sudden it
> has stopped working with the error "AttributeError: 'property' object has
> no attribute '__dict__'".  I get the same error with anything I enter after
> the ./manage.py (i.e. runserver, dbshell, etc)

You most likely switched to Python 3. But a backtrace would help a lot to 
understand the cause.

-- 
Melvyn Sopacua

-- 
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/3093672.KM6zN6OXxa%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Sponsor subdomain pointing to part of our Django site?

2018-06-04 Thread Melvyn Sopacua
On maandag 4 juni 2018 13:26:24 CEST Richard Brockie wrote:

> However, I'm pretty sure that we will need to make some changes to our
> project to deal with links when the site is being accessed through
> "subdomain.sponsor.url/". You are correct that {% url %} is used in the
> templates as well as django.core.urlresolvers.reverse() being used in the
> code. However, I think we need to catch the case where url or reverse() are
> returning "site.url/year/slug/some/more/path/" and convert it to
> "subdomain.sponsor.url/some/more/path/" based on the http_host in the
> request.
> 
> I'm wondering if this is a solved problem?

This isn't a problem. Neither url nor reverse is capable of returning URLs with 
hostnames, 
at least not that I'm aware of. Only django.contrib.site[1] module can do this 
for out-of-
band communications.

So if you're encountering such cases, then you're using custom or 3rd party 
code or have a 
hardcoded hostname in your templates or are using the site module.

There is no magic case where reverse or the url template tag decides to add a 
hostname, 
because it senses you want it. And if you just want to serve the exact same 
site on a 
different domain, then ALLOWED_HOSTS is all you need.

If you want to brand the site with a different look and feel, then you will 
need the site 
module, because then you will serve different content.

If you're asking "how can i be sure there are no mistakes in our code", then 
you should 
already know the answer - test, test, test :).
-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/ref/contrib/sites/#getting-the-current-domain-for-display

-- 
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/1789736.NRtqCP1Ze9%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-04 Thread Melvyn Sopacua
On maandag 4 juni 2018 08:00:08 CEST Bernd Wechner wrote:
> Say I have a page on my Django website (because I do) that I would like to
> take a snapshot of on an automated basis on the server itself with a
> crontab say. I imagine writing a small python script that I could run, that
> loads Django, a settings file, knows a URL and has a way of saying "give me
> the rendered page for that URL please" and save it in a file.

...

> a) there's a canonical way to do this already that can be recommended

Yep. The test client [1]... if your template uses request related information 
(like logged in 
user). The cheaper method is something like this code[2], but this only renders 
the 
template and you'd have to provide a context so view code is bypassed.

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/topics/testing/tools/#the-test-client
[2] https://github.com/melvyn-sopacua/django_xtc/blob/master/xtc/__init__.py#L49

-- 
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/3641770.R8fxcq3Jsz%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Sponsor subdomain pointing to part of our Django site?

2018-06-03 Thread Melvyn Sopacua
On zondag 3 juni 2018 22:45:31 CEST Richard Brockie wrote:

> Any advice on how I can accomplish this? Any particular things I would need
> to do in the Django project to make this possible?

Since you seem to be using the {% url %} tag and have no absolute URLs with 
the hostname in it, I don't think Django is part of the problem, short of 
ALLOWED_HOSTS setting.

Your problem would be in the webserver configuration and as you suspected the 
SSL certificate.

Why don't you add a subdomain 'test', add it to allowed hosts setting, add the 
certificate and see what breaks. I don't think anything breaks at all.
-- 
Melvyn Sopacua

-- 
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/33245904.Kc6r1lpH81%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Updating django database

2018-06-02 Thread Melvyn Sopacua
On zaterdag 2 juni 2018 15:12:08 CEST Albin Antony wrote:
> For updating multiple models at the same time, Should we create multiple
> instances?

Multiple models (Patient and Medication) or multiple instances of the same 
model (more than one Patient)?

The later can be done with a single manager operation. The first cannot.

-- 
Melvyn Sopacua

-- 
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/1591788.fE9Xf09d5R%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing a 'please wait' page

2018-06-01 Thread Melvyn Sopacua
On vrijdag 1 juni 2018 01:35:36 CEST Mohammed Noor wrote:

> I want to be able to display a page saying 'please wait for  taken to complete process>'  after submit button is clicked. Can you please
> give me any ideas on how to implement this.

As said by others, celery is one way to do this and this tutorial shows all 
things required to provide user feedback:

https://buildwithdjango.com/blog/post/celery-progress-bars/

-- 
Melvyn Sopacua

-- 
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/2601912.fUvbL4GUKq%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Call to method that takes in a request

2018-06-01 Thread Melvyn Sopacua
On vrijdag 1 juni 2018 13:02:54 CEST Yufenyuy Veyeh Didier wrote:

> I wish to know  how I can call a method that takes in a request as one of
> its parameters such as
> 
> def get(self, request, pk):
> 
> #I am writing a test method to test the above method too.

If you want to test a view, use the TestClient[1].

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/topics/testing/tools/#the-test-client

-- 
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/6045502.LxK3jo6LkC%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: URL Concatenation Issue

2018-06-01 Thread Melvyn Sopacua
On vrijdag 1 juni 2018 00:14:32 CEST John Regis, Jr. wrote:

> I have *href="about/"*. Also tried *href="./about/"* and same result.

Please revisit this section in the tutorial[1]. If you haven't done the 
tutorial at all, 
please do it before trying a project on your own. You are missing a few 
fundamentals the tutorial touches upon, such as the basics of URLs and URL 
paths[2].
-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/intro/tutorial03/#removing-hardcoded-urls-in-templates
[2] https://stackoverflow.com/a/904066/1600649

-- 
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/138901869.PMmXthNE3q%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: dumpdata fails with crytpic error

2018-06-01 Thread Melvyn Sopacua
On vrijdag 1 juni 2018 06:22:43 CEST Bernd Wechner wrote:

> Anyone seen this before. How does one diagnose this given the vague nature
> of the message? 

Using the --traceback flag.

-- 
Melvyn Sopacua

-- 
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/2720311.AXnXxhnEOH%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: href not working

2018-05-31 Thread Melvyn Sopacua
On donderdag 31 mei 2018 15:49:28 CEST Caleb Bryson wrote:
> my blog view.py is empty at the moment
> 
> 
> Mysite url.py
> 
> from django.contrib import admin
> 
> from django.conf.urls import url, include
> 
> 
> 
> urlpatterns = [
> 
> url(r'^admin/', admin.site.urls),
> 
> url(r'^', include( 'hybridair.urls')),

This matches anything that has a beginning. So that always matches, anything 
after it, is ignored (Django works on first match base).


> url(r'^', views.index, name='index'),

And again.

So anything that is not admin, goes to the homepage.
-- 
Melvyn Sopacua

-- 
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/2507550.5rhCOJ8Mzy%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: href not working

2018-05-31 Thread Melvyn Sopacua
On donderdag 31 mei 2018 05:56:59 CEST Caleb Bryson wrote:
> So i am trying to create a directory with a Home,Blog,and Contact
> selection. But every time i click on one of them they all go back to the
> home page.

If the url in your addressbar is /blog/  after clickin on it, but you see the 
homepage content, then your homepage url pattern matches too much.

If you get redirected to the homepage, then there's something wrong in your 
blog view code.

Given that it applies to both contact and blog, the first option is more 
likely, but you could be making the same mistake in both views.

-- 
Melvyn Sopacua

-- 
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/1865269.oQ2Mhu4JUg%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /polls/1/vote/

2018-05-29 Thread Melvyn Sopacua
On dinsdag 29 mei 2018 14:07:59 CEST Caleb Bryson wrote:

> def vote(request, question_id):
> ... # same as above, no changes needed.

You fell into the cut-and-paste-without-reading trap.
-- 
Melvyn Sopacua

-- 
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/1949880.9Y4zlWCeNm%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: money field question

2018-05-29 Thread Melvyn Sopacua
On dinsdag 29 mei 2018 11:03:56 CEST Mike Dewhirst wrote:

> Also, despite using decimal.Decimal under the covers it wants its money
> as strings.
> 
> Python 3.6.3
> 
>  >>> from money import money
>  >>> print(money.Money(23.45, 'AUD'))
> 
> AUD 23.449289457264239899814128875732421875
> 
>  >>> print(money.Money('23.45', 'AUD'))
> 
> AUD 23.45

No, that's decimal.Decimal and floats being an approximation:

>>> from decimal import Decimal 

>>> print('{:.48f}'.format(23.45)) 
>>> print('{:.55f}'.format(23.45)) 

So decimal.Decimal's constructor converts strings to decimal numbers with as 
much 
precision as given. It also applies to floats, except that floats have more 
precision then 
typed.
-- 
Melvyn Sopacua

-- 
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/4704533.IngrlRvRmB%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Multisite strategy

2018-05-24 Thread Melvyn Sopacua
On donderdag 24 mei 2018 16:39:34 CEST Anthony Petrillo wrote:

> So I was thinking that was an option so that I could build one site and
> then have translations into other languages so when the user picked a
> language everything will switch to that language. Is this a naive
> assumption?

A bit. Everything that is in the code can be translated using the gettext 
functionality 
outlined in the documention. Everything that is in the database, cannot.

You will need separate app for that. Which is the best fit for you, depends on 
a number 
of factors, but here are some to choose from:

>From the Django Packages Internationalizion[1] grid:

- Django Model Translation
-  Parler
-  Linguist
-  Model Trans

> On Tuesday, May 22, 2018 at 2:31:36 AM UTC-4, Carlo Ascani wrote:
> > Hi all,
> > 
> > I'd like to implement something like this:
> > 
> > One Django project to serve 3 sites:
> > 1. `domain.com` which is the "master" site, containing just a landing page
> > 2. `de.domain.com` which is the "German" site
> > 3. `en.domain.com` which is the "UK" site
> > 
> > `de` and `en` refers the location, not the language (e.g. `
> > de.domain.com/en/` <http://de.domain.com/en/> is the German site in
> > English)
> > 
> > If you go to `domain.com` you can choose the language and the country,
> > and you are just redirected to the right place.
> > 
> > Is `contrib.site` suitable for that scenario?
> > I was thinking at 3 different sites.
> > If so, how can I use them locally while in development?
> > 
> > Any other suggestions?
> > 
> > Best,
> > Carlo


-- 
Melvyn Sopacua


[1] https://djangopackages.org/grids/g/i18n/

-- 
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/2693684.PrGW0JMWH4%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: help me out

2018-05-24 Thread Melvyn Sopacua
On donderdag 24 mei 2018 17:28:53 CEST Umar Kambala wrote:
> It is located in mysite/polls/template/polls/

It should be in mysite/polls/templates/polls/

Note: templates with an s, not template.

-- 
Melvyn Sopacua

-- 
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/61115682.T1ecY6nzIZ%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with Django migrate - fine with 2.7x python, but error with 3.6.4?

2018-05-24 Thread Melvyn Sopacua
On donderdag 24 mei 2018 00:31:57 CEST Benjamin Schollnick wrote:
> Okay, squashing seems to have resolved this issue...

Did you find any issues with the documentation on squashing?

> Seems a bit voodoo-ish, but it worked.  Any suggestions for preventing this
> in the future would be nice!

It's voodoo-ish cause you stopped analyzing the problem and went for the work-
around.

So my best guess is:
- The two 0018 migrations were caused by 2 different branches in the source 
repository, adding migrations in parallel
- These were applied to the database also in parallel
- Further migrations were added, depending on the 0018 migrations
- One migration was removed that was the common ancenstor for one of the 0018 
migrations and another migration.

Without reconstructing the dependency graph it will be difficult to see how you 
could have solved it.
To prevent it, establish a protocol for your developers to communicate with 
eachother when adding and removing migrations.

-- 
Melvyn Sopacua

-- 
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/1555096.CvhEgTB1t9%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Starting your first app

2018-05-23 Thread Melvyn Sopacua
On woensdag 23 mei 2018 22:59:50 CEST Caleb Bryson wrote:
> Hey I am new to python and i am trying to use django to make my first web
> page. I know the basics of python but i am stuck on the step where you
> start your app. i made sure i have a directory and have installed south to
> help out

:(

> https://jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-wa

Please don't use a blogpost from 2012. Django has excellent documentation, 
among which a tutorial that is kept up to date. This post hasn't been, as it 
talks about south, something that went obsolete with Django 1.8 (and we're now 
on 1.11LTS / 2.0 and 2.1 is around the corner).

https://docs.djangoproject.com/en/2.0/#first-steps
-- 
Melvyn Sopacua

-- 
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/5186520.HJiarYheb3%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with Django migrate - fine with 2.7x python, but error with 3.6.4?

2018-05-23 Thread Melvyn Sopacua
On woensdag 23 mei 2018 12:55:58 CEST Benjamin Schollnick wrote:

> nerv:quickbbs Benjamin$ manage.py migrate --run-syncdb

 


> (quickbbs) nerv:quickbbs Benjamin$ python3 manage.py migrate
> 
> Running on nerv.local
> 
> CommandError: Conflicting migrations detected; multiple leaf nodes in the
> migration graph: (0019_auto_20171108_0155, 0044_auto_20180519_1914 in
> quickbbs).

Not convinced yet this is a py2 versus py3 problem. First, you're running 
different command flags (though, not sure it matters in this case). Second, the 
Django version for py3 can be different from the py2 version.

>From the backtrace it isn't clear though which app is causing this. If it 
really is a py2 versus py3 issue, then I suspect that some migrations are done 
only for py3, though that is really bad practice.

-- 
Melvyn Sopacua

-- 
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/2403869.zZKC4CeI1l%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-21 Thread Melvyn Sopacua
On woensdag 16 mei 2018 14:00:28 CEST Paolo Chilosi wrote:
> just a note on your note: I created a few more new project/app using
> PyCharm create facility and I found the app registered in the
> INSTALLED_APPS settings. I do not know if it is Django or PyCharm that
> introduce this setting. 

It's you. Cause you filled in "polls" as the application name (not the project 
name).

-- 
Melvyn Sopacua

-- 
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/8224690.SOUbQsCI1f%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django login() function works in production but not in development

2018-05-19 Thread Melvyn Sopacua
On dinsdag 15 mei 2018 00:55:38 CEST pieceofkayk2...@gmail.com wrote:
> My code
> returns the print statement 'User is active' when I sign in with a user on
> my project page; however, my user never gets logged in during the next
> step.

How did you determine the user doesn't get logged in?
-- 
Melvyn Sopacua

-- 
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/7615988.lIG82e8qKF%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: New to Python

2018-05-19 Thread Melvyn Sopacua
On dinsdag 15 mei 2018 21:13:52 CEST Mo El wrote:

> I`m new to python and i have been watching a lot of tutorials regarding web
> scraping using python, and my question is what is the best library to use,

When asking for "best", try to make that more objective, by listing 
requirements and nice to have features.

That said, you may want to take a look at scrapely:
https://pypi.org/project/scrapely/

> and can someone help me to understand how to write a scrapped data to an
> HTML, say i scrapped some data from a website and i wanted to write that
> data to another page to view or use using python as well.

Since you're in the Django user group, you would use Django and it's template 
engine: https://docs.djangoproject.com/en/2.0/topics/templates/

-- 
Melvyn Sopacua

-- 
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/4707090.Is6yrToolF%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Standard approach

2018-05-19 Thread Melvyn Sopacua
On donderdag 17 mei 2018 00:44:32 CEST Mike Dewhirst wrote:

> More advanced users tend to focus on the more advanced problems and
> that's the way it should be.

Not always true. You tend to focus on things that show research and effort. 
The level of competence then doesn't matter. It just so happens that anyone 
who loads http://localhost:8000/ during the tutorial and gets a 404, then 
tells the group the tutorial is wrong, clearly doesn't show research (asked 
and answered a gazillion times) nor effort (read the tutorial again to see 
your mistake, ans yes, it's possible to read over it again and again and not 
see it, which is why you should use the search-before-asking algorithm).

So it looks as though more advanced users focus on more advanced problems, but 
that certainly isn't the case - it just coincides with the fact that beginner 
problems are often thrown into the group without any thought or research.

And can I just say, sometimes with an attitude unbecoming of someone who wants 
others to spend time on his/her problems. But that's the nature of Open Source 
communities.

This is rather elaborate, but should be any forum's charter:
http://www.catb.org/esr/faqs/smart-questions.html

-- 
Melvyn Sopacua

-- 
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/1976853.iyU7qaXFUZ%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Public Django administrative database

2018-05-19 Thread Melvyn Sopacua
On vrijdag 18 mei 2018 10:18:27 CEST Daniel Chimeno wrote:
> Hi community!
> 
> I'm involved in a project heavily related to administrative geographic
> entities in UK.
> (postal_sectors, postal areas, etc..)
> Although at the moment is only for UK, could be expanded to other countries.
> At first, I look
> into https://github.com/django/django-localflavor/tree/master/localflavor/gb
> but there aren't so many entities there.
> 
> Then, searched in Google for some hours and couldn't find any reliable
> database or csv.

This really wasn't that hard to find (include "gis" in your searches):
http://geoportal.statistics.gov.uk/

And governments in Europe are stimulated to provide that data to their 
citizens free of charge and in open formats (since we pay taxes for the 
government to gather that data, so why should we pay twice).

Here's the equivalent for The Netherlands:
http://www.nationaalgeoregister.nl/geonetwork/srv/dut/catalog.search#/home
https://www.kadaster.nl/bag

And Switzerland:
https://opendata.swiss/en/group/geography

Note that these are all to be considered authoritative, but not all are 
provided in a useful format. Therefore it sometimes pays off to go with 
alternative proprietary services, purchase databases that have information 
linked properly or go with Open Street Map.
-- 
Melvyn Sopacua

-- 
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/12126462.rBThRD8xn7%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: getting error while reloading the url"http://localhost:8000/polls/".The error is given below.Please tell my why i am seeing this error?

2018-05-19 Thread Melvyn Sopacua
If you're going to send each error you get to the list to be resolved, you're 
not going to learn any debugging skills.

Errors have all the information for you to figure out yourself why things are 
wrong. Read them, follow the back traces and figure it out.

There are times where backtraces are hard to read or do not have the answer in 
an obvious way. But so far, you haven't encountered those at all.

-- 
Melvyn Sopacua

-- 
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/4006117.UF1rpJ4i1Y%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Adding to all templates context via Middleware

2018-05-14 Thread Melvyn Sopacua
On maandag 7 mei 2018 17:59:02 CEST Daniel Roseman wrote:
> I still don't understand what is being repeated or why. You need to specify
> that in your settings, and you can add whatever context processors you
> like. You don't need to specify it twice, so nothing is being repeated.

What Bernd means is that if you don't specify it, Django will create such 
dictionary, just not with the special context processor.

This is basically a matter of authority and circular import avoidance:
1) Suppose I don't want any context processors, I'd have no way to specify 
that if my settings isn't deemed authoritative and Django just fills in what it 
thinks it's missing
2) If you want to "edit defaults in project settings" you are bound to run 
into circular imports as the Django settings needs to load your settings and 
you want to import the Django settings.


-- 
Melvyn Sopacua

-- 
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/175.3yudL1jLur%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 16:42:49 CEST Matthew Pava wrote:

> But if in your use case, you had a million records in which you were trying
> to filter

Full stop right there. No one is filtering anything in the original use case, 
so you're comparing apples and oranges.
Filtering you would do in the database, but you'd still not use annotate, 
cause you can simply filter on the dob using standard __gte/__lte etc. lookups.
-- 
Melvyn Sopacua

-- 
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/1618227.LY2WuIfJ59%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 15:38:01 CEST Matthew Pava wrote:
> You could use the ORM to get the difference of two dates like so:
> Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) -
> F('dob'), output_field=DurationField()))
> https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#cast
> https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#now

Sure, but what's the upside? The downside is that your objects are bigger, 
more data transferred from db to python layer, more complex query.

What I'm trying to conveigh here, is not to shoehorn the ORM into your notion 
of SQL, but to think in models, model fields, object properties and model 
relations.

There will be times where the ORM needs help from SQL, but pick your battles.
-- 
Melvyn Sopacua

-- 
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/4047248.Nn77cOrblS%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On zondag 13 mei 2018 03:44:37 CEST Gerald Brown wrote:
> As I have said previously, I am new to Django ORM so I would like to know
> howto/find reference to Django ORM Query to the following SQL Select
> statements:

Do you want to use SQL or use Django? Pick one.

> 1. From Mariadb.
> 
> SELECT name, date_of_birth,
> *TIMESTAMPDIFF(YEAR,date_of_birth,'2014-08-02'/or curdate())* AS age FROM
> some table.

The Django way:

Use case: I want to gather a person's name, date of birth and age for all 
people modeled using Person.

from datetime import date

class Person(models.Model):
name = models.CharField(max_length=100)
dob = models.DateField()

@property
def age(self) -> int:
diff = date.today() - self.dob
return diff.year

people = Person.objects.defer('name', 'dob').all()

> 2. General SQL statement
> SELECT field1, field2, field10 from some table

See defer() as above.

> 3. How to see all of the data from those statements which SQL shows me.

Use case: I want to show people's name, date of birth and age.

Using above "people":

print('name', 'date of birth', 'age')
for person in people:
print(people.name, people.dob, people.age)

-- 
Melvyn Sopacua

-- 
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/4418595.HAJx60YL8B%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing models.py

2018-05-14 Thread Melvyn Sopacua
Hi Mark,

On zondag 13 mei 2018 18:11:07 CEST Mark Phillips wrote:
> What should be unit tested in models.py? I assume the storing of data and
> retrieving of data from the database does not need to be tested, as I
> further assume django has a full set of tests for those operations.

You should test your business requirements. Even for those operations. Best 
illustrated:

# models.py
class Customer(models.Model):
email = models.EmailField()
name = models.CharField(max_length=100)

# tests.py

class CustomerTestCase(TestCase):
def test_create(self):
data = { 'email': 'i...@example.com', name='John Doe' }
  first = Customer.objects.create(**data)
with self.assertRaisesMessage(IntegrityError, 'duplicate key 
value'):
second = Customer.objects.create(**data)

This test will fail cause there's no unique constrain on email, which is 
likely to be a business requirement. You should test it. Especially because if 
someone refactor years down the line and accidentally removes the requirement, 
you have a problem.

> * Labels for all fields
> something like
> def test_first_name_label(self):
> author=Author.objects.get(id=1)
> field_label = author._meta.get_field('first_name').verbose_name
> self.assertEquals(field_label,'first name')

I would say this is exactly the thing you wouldn't test: anything dealing with 
_meta. Test these further downstream, by verifying form labels and their 
translated version if it applies. And I'd say the exact wording of a form 
label may not be at all important, so you could skip this.

-- 
Melvyn Sopacua

-- 
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/2172791.13n9OJESef%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   5   6   7   >