Skip to content

Refactoring to Django3.2#192

Open
xusy2k wants to merge 1 commit intoSustainableUrbanDesign:masterfrom
xusy2k:main
Open

Refactoring to Django3.2#192
xusy2k wants to merge 1 commit intoSustainableUrbanDesign:masterfrom
xusy2k:main

Conversation

@xusy2k
Copy link

@xusy2k xusy2k commented Jan 26, 2022

Beginning migration to Django3.2 following directives from https://github.com/cookiecutter/cookiecutter-django:

  • Django3.2: Split settings into several files according with environments
  • OpenLayers 6.12
  • Vue 2.6.14

Beginning migration to Django3.2 following directives from https://github.com/cookiecutter/cookiecutter-django:

* Django3.2: Split settings into several files according with
environments
* OpenLayers 6.12
* Vue 2.6.14
Comment on lines +25 to +35
kw = {
"table": "osm_points_of_interest",
"epsg": 4326,
"limit": 200,
}
try:
kw["xmin"], kw["ymin"], kw["xmax"], kw["ymax"] = request.GET["ext"].split(",")
except (KeyError, ValueError):
pass

osm_query = create_osm_to_geojson_query(**kw)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having difficulty understanding this change. What is the goal of this diff?

Comment on lines +60 to +106
onMapPostCompose({ vectorContext, frameState }) {
},
fetchOsmData: function () {
this.isFetching = true;
let map = this.$refs.map.$map;
let url = url_fetch_osm;
let currentExtent = map.getView().calculateExtent(map.getSize());
let projectionCode = map.getView().getProjection().getCode();
let transformExtent = ol.proj.transformExtent(currentExtent, projectionCode, 'EPSG:4326');
url += "?ext=" + transformExtent.toString()
//console.log(url);
fetch(url)
.then(response => response.json())
.then((data) => {
if (data.features) {
this.osmData = data;
} else {
console.log("There is no features")
}
this.isFetching = false;
});
},
onMapMoveStart() {

},
onMapMoveEnd() {
if (this.isFetching) {
return
}
this.fetchOsmData();
},
onMapMounted() {
// now ol.Map instance is ready and we can work with it directly
this.$refs.map.$map.getControls().extend([
new ol.control.ScaleLine(),
new ol.control.FullScreen(),
new ol.control.OverviewMap({
collapsed: true,
collapsible: true,
}),
new ol.control.ZoomSlider(),
]);
this.$refs.map.$map.updateSize();
},
onMapClicked(e) {
console.log(e.coordinate);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good, but may exceed the scope of a "Django 3.2 refactor" PR. Let's leave them for now, since they probably don't block the review process.

{% block js_extra %}
<script type="text/javascript">
let api_login = "{% url 'rest_login' %}";
let login_error_txt="{% trans 'El usuario y/o la contraseña que especificaste no son correctos' %}.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The localisation base language is English. I believe this string will get added to the English strings, which may be confusing for content translators. I believe we should use the English equivalent of this message in the login template.

Comment on lines +59 to +94
$(document).ready(function () {
$('#f_login').on("submit", function(ev){
$("#f_login_error").hide();
ev.preventDefault();
const data={ "username": $("#id_login").val(), 'password': $("#id_password").val()}
fetch(api_login, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => {
if (response.status==400){
$("#f_login_error_txt").html(login_error_txt);
$("#f_login_error").show();
} else {
is_logged = true;
}
response.json()
})
.then(data => {
if ((data) || (is_logged)) {
let next = $("input[name=next]").val();
if (next === undefined) {
next = "/"
}
window.location.href=next;
}
})
.catch((error) => {
$("#f_login_error_txt").html(error);
$("#f_login_error").show();
});
})
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like more than just a refactor of the login process. Should we split this to a separate PR?



class AccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request: HttpRequest):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need a feature to block signups. Let's focus this pull request on Django 3.2, actually Django 4 now, compatibility :-)

@@ -0,0 +1,19 @@
# Django
# ------------------------------------------------------------------------------
django==3.2.11 # pyup: < 4.0 # https://www.djangoproject.com/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consider migrating to Django 4.x now :-)

Comment on lines +11 to +12
mypy==0.931 # https://github.com/python/mypy
django-stubs==1.9.0 # https://github.com/typeddjango/django-stubs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes for static analysis look great, but may be out of scope for the current PR :-)

Copy link
Contributor

@brylie brylie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this PR looks great! Let's reconsider a couple of the changes that are beyond the scope of refactoring, such as those I've mentioned in previous comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants