Re: How do I override default date formats per locale in Django?

2019-07-25 Thread אורי
*Update:* I found out that it's possible to override formats per locale in this
link , and
added formats for en and he locales, but they don't work. I added a
debugging code which you can see here
,
but it doesn't work. It shows dates like Jan. 1, 2018 and not as I expect.

I also don't know if DATE_FORMAT should be preceded by settings. in the
template, but it doesn't show anything without it.
אורי
u...@speedy.net


‪On Wed, Jul 24, 2019 at 8:45 PM ‫אורי‬‎  wrote:‬

> Hi,
>
> We are using Django 1.11 for Speedy Net. I want to override the default
> values of DATE_FORMAT and MONTH_DAY_FORMAT in English, but keep the default
> values (or define them again) in Hebrew. So they will not be the same and
> will not be identical to Django's default values. In English we will have:
>
> DATE_FORMAT = 'j F Y'
> MONTH_DAY_FORMAT = 'j F'
> YEAR_FORMAT = 'Y'
>
> And in Hebrew:
>
> DATE_FORMAT = 'j בF Y'
> MONTH_DAY_FORMAT = 'j בF'
>
> (and YEAR_FORMAT will be the same).
>
> The template currently looks like this:
>
> {% if can_view_profile and user.date_of_birth %}
> {% if can_view_dob_day_month or can_view_dob_year %}
> 
> {% if can_view_dob_day_month %}{% trans 'Birth Date' %}{%
> elif can_view_dob_year %}{% trans 'Birth Year' %}{% endif %}
> 
> {% if can_view_dob_day_month and can_view_dob_year %}
> {{ user.date_of_birth|date:settings.DATE_FORMAT }}
> {% elif can_view_dob_day_month %}
> {{ user.date_of_birth|date:settings.MONTH_DAY_FORMAT }}
> {% elif can_view_dob_year %}
> {{ user.date_of_birth|date:settings.YEAR_FORMAT }}
> {% endif %}
> 
> 
> {% endif %}
> {% endif %}
>
> And I want it to display the dates in these formats in each language. How
> do I do it?
> אורי
> u...@speedy.net
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeFaVPNC1RT3QqTPv7oVyPjSCtZZq_aO7UcHgMr%3DYTm16w%40mail.gmail.com.


Re: not too much experience with Django

2019-07-25 Thread Mike Dewhirst

On 26/07/2019 12:37 pm, yaba koba wrote:
Hi everyone I started Django almost 1 years ago and I like this 
framework and I make small blog projects with using (django + 
boostrap4, nginx + gunicorn) but I would like to make a professional 
website for the town hall from my small town with django.

My question is: What are the fundamentals for making a site like this?


0. PostgreSQL, Python 3
1. Security to prevent hacking*
2. CAPTCHA to prevent automated posts
3. Sensible error pages with good advice for the users if they encounter 
predictable problems

4. Logging to capture errors
5. Email infrastructure to (at least) email errors to you
6. Mailing lists for stakeholders, devs, managers, users
7. The usual continuous integration mechanism(s)**
8. Nice plan for backups, database dumps, encryption if necessary
9. A duplicate site for staging and testing and maybe restoring 
production backups***

10. The ability to roll the site back to a previous version if necessary
11. User documentation or brilliant user interface not requiring docs
12. Good design for user authentication/registration/permissions assignment
13. Plan for site business control and management, perhaps moderation of 
posts

14. Plan for growth and funding growth of infrastructure

* Security means different things to deal with different threats
 - https://docs.djangoproject.com/en/2.2/topics/security/
 - https://www.owasp.org
 - https://letsencrypt.org/

** "Usual" means everyone uses different bits and pieces but that includes:
 - repository for project code and artefacts
 - tools or scripts for testing or running tests
 - tools or scripts for deploying a tagged release to staging from the repo
 - same for production

*** A duplicate site doesn't necessarily mean duplicate machines. You 
could have https://www.whatever.com for the production site and 
https://staging.whatever.com for the  staging site.


That's probably not all but should get you started :)

Mike


thank you!
--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d44632b5-440b-479b-ad42-f9f979d956f2%40googlegroups.com 
.


--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/97834101-ff1f-d31f-1530-956b91d80fb0%40dewhirst.com.au.


not too much experience with Django

2019-07-25 Thread yaba koba
Hi everyone I started Django almost 1 years ago and I like this framework 
and I make small blog projects with using (django + boostrap4, nginx + 
gunicorn) but I would like to make a professional website for the town hall 
from my small town with django.
My question is: What are the fundamentals for making a site like this?
thank you!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d44632b5-440b-479b-ad42-f9f979d956f2%40googlegroups.com.


Job opporunity for an experienced Django/Python software engineer - Corvallis, OR (Remote possible)

2019-07-25 Thread Nikolas Stevenson-Molnar
The Conservation Biology Institute (CBI) is a non-profit organization of
scientists, GIS analysts, spatial modellers, and software engineers. Our
software development team works closely with scientists and stakeholders to
build software that helps them better understand and communicate their
data, and make scientifically-informed decisions.

We're currently looking to hire at least one, and possibly two experienced
full stack engineers with Python/Django experience. We use Django
extensively on the backend, and React on front end in our newer projects
(we have an older project using Dojo, but we have plans to migrate that to
React as well). We also use Golang for some backend components. Most of our
applications are GIS-focused, and we use Leaflet and Mapbox GL JS for
mapping.

The full job description is attached, including instructions to apply. Our
office is located in Corvallis, OR. We are open to hiring remote positions,
and currently have 2 remote software engineers on the team, including me.
Candidates must be able to work in the US.

Thanks,
Nik

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADW6jR%3DYE71DitXO-LPpu3WKTjUv0%3DLif_2xzKuF_7WScNTXGA%40mail.gmail.com.


CBI Senior Software Engineer - July 2019.pdf
Description: Binary data


Re: New user question: Where to put non-form validation code?

2019-07-25 Thread Matt Zand
Hi everyone,
Does anyone know how to post blog at below page:
https://www.djangoproject.com/community/blogs/

I am really frustrated as I submitted last week but nothing is there. Who
is in charge of blog posts on Django site?

Thx,
Matt



On Thu, Jul 25, 2019 at 12:38 AM Mike Dewhirst 
wrote:

> On 25/07/2019 1:03 pm, Jim Illback wrote:
> > I had a slight variation on this thread - where to put some M2M field
> > validation/deletion logic.
> >
> > I have a purely model-based form where a checkbox’s value determines
> > whether another field (it’s a M2M field) in the form should be NULL or
> > keep its values to be saved in the database. So, following the
> > appropriate separation of concerns as advocated below, I added logic
> > in both the models' clean and save override methods. Neither approach
> > set the other field to NULL when it should have been. The reason is
> > the form still contained M2M values even though the model said to
> > delete them (delete the set, actually).
> >
> > After a lot of trial and error, it turns out that the model’s save
> > seems to be run BEFORE the form’s save. To me, that seems backwards.
> > Shouldn’t the model’s processes (which are directly relate to the
> > database, the ultimate data source) occur last and well before the
> > form’s (which are merely an interaction with the user)? What was
> > happening was my model’s delete actually did the deletions (those IDs
> > were gone), but then the form’s processing came along afterwards and
> > re-inserted them again (with brand new IDs).
>
> Don't know what's happening here but you can be sure Django is doing it
> the right way.
>
> Maybe you need to look at your on_delete constants. models.CASCADE
> versus models.SET_NULL or models.PROTECT
>
> >
> > Can someone help me understand why Django has chosen this seemingly
> > “inversion” of processing - first models’ processes, then forms’? And,
> > perhaps more importantly, where should this either/or logic should be
> > placed so it will take effect?
> >
> > Thanks very much,
> > Jim Illback
> >
> >> On Jul 13, 2019, at 11:48 PM, Mike Dewhirst  >> > wrote:
> >>
> >> Well yes it could be called multifaceted.
> >>
> >> Usually but not always the interface with the user is the form. You
> >> can have non-database fields as well as model fields so either way
> >> there has to be a full suite of validation functionality available in
> >> both types of forms. Luckily, model forms automatically call
> >> model.clean() for you.
> >>
> >> Unit tests don't though. You have deliberately call obj.clean() if
> >> you want to test things. obj.save() doesn't call obj.clean().
> >>
> >> Actually, I also do a bit in view code too especially if there are
> >> non-database or hidden fields in the form. I know you are not
> >> supposed to validate data in a view for proper separation of concerns
> >> but it does keep my forms neater.
> >>
> >> The bottom line for me is that if I can imagine non-form access ...
> >> eg through an API ... then all validation possible has to be via
> >> model.clean() and the API has to remember to call clean() before
> >> saving every time there is a POST
> >>
> >> Hence I*always*put business rules validation in model.clean() and
> >> leave 'local' validation for the form.
> >>
> >> You are right. There are quite a few moving parts
> >>
> >> /Connected by Motorola/
> >>
> >>
> >> Dean Karres mailto:dean.kar...@gmail.com>>
> wrote:
> >>
> >> Thank you. There are way more parts to this than I would have imagined.
> >>
> >>
> >>
> >> On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst  >> > wrote:
> >>
> >> On 14/07/2019 10:37 am, Dean Karres wrote:
> >>> Hi,
> >>>
> >>> I am learning Django.  I am using CBVs.  My default "index.py"
> >>> view is basically a dashboard for the app I am playing with.  As
> >>> my models and views become more complicated I want to be able to
> >>> ask, for any model instance, is this instance "valid" or
> >>> "complete".  Valid means that all Required elements are present
> >>> and have reasonable values.  "Complete" means that an instance
> >>> is "valid" but also some specific bits of additional info are
> >>> also ok.
> >>>
> >>> For example I have a Student model that has name and address
> >>> info.  There is a ManyToMany relation to the Class(es) in which
> >>> that Student is enrolled.  A "student" instance is valid if the
> >>> name and address fields are filled.  A student is "complete" if
> >>> the student is valid and has signed up for one or more classes.
> >>>
> >>> So, my question is: where should the valid and complete methods
> >>> live?  Should they be in the Student model or CBV? Someplace
> >>> else?  Does it matter?
> >>
> >> I like to put that sort of stuff into model methods then add
> >> model.clean() to call them and raise whatever error may be
> >> appropriate if they fail.

Defining Models outside models.py

2019-07-25 Thread Sam Taiwo
Hi everyone,

I know there are currently 3 ways to define a model in Django
1) Define it directly in the models.py file
2) Define it directly in a models package in the same directory as your 
other app files
3) Define it somewhere completely different and just import the models into 
the models.py

My question is, is there a way to write a model in any arbitrary file in 
you directory and link it to your app without having to use models.py file 
or directory.
For example is there a way to write a model directly in the views file and 
then add some config to the settings or elsewhere to enable Django to know 
of it's existence and pick up any changes that happen to it.
I don't mind if it's a complete hack
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/95f073eb-8309-4454-8cfd-b190dde90cef%40googlegroups.com.