Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some SonarCloud warnings. #883

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions frontend/__tests__/Profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ describe('shallow <Profile /> components', () => {
{"slug": "google-oauth2", "connected": false, "label": "Google", "class": "google"}
];

it('render', () => {
// todo
// expect(createComponentWithIntl(<Profile user={user} providers={providers}/>)).toMatchSnapshot('Profile');
});
// it('render', () => {
// expect(createComponentWithIntl(<Profile user={user} providers={providers}/>)).toMatchSnapshot('Profile');
// });

it('profileFormUpdate', () => {
global.fetch.mockResponse("{}");
Expand Down
16 changes: 8 additions & 8 deletions frontend/games/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class Game extends React.Component {
let addr = `${ws_scheme}:https://${window.location.host}/ws/${this.GAME_NAME}/`;
this.ws = new Sockette(addr, {
timeout: 5e3,
onopen: e => this.setState(state => ({...state, wsState: true})),
onopen: () => this.setState(state => ({...state, wsState: true})),
onmessage: e => this.dispatchMessage(e),
onreconnect: e => this.setState(state => ({...state, wsState: null})),
onmaximum: e => this.setState(state => ({...state, wsState: false})),
onclose: e => this.setState(state => ({...state, wsState: null})),
onerror: e => this.setState(state => ({...state, wsState: false}))
onreconnect: () => this.setState(state => ({...state, wsState: null})),
onmaximum: () => this.setState(state => ({...state, wsState: false})),
onclose: () => this.setState(state => ({...state, wsState: null})),
onerror: () => this.setState(state => ({...state, wsState: false}))
});
};

Expand Down Expand Up @@ -88,8 +88,8 @@ class Game extends React.Component {
try {
let response = await fetch(`${window.location.origin}/puzzle/area/${id}/infobox/`, {method: 'GET'});
let data = await response.json();
let regions = this.state.regions.map((region) =>
region.id === id ? {...region, infobox: prepareInfobox(data)} : region);
let regions = this.state.regions.map((item) =>
item.id === id ? {...item, infobox: prepareInfobox(data)} : item);
this.setState(state => ({...state, regions: regions, infobox: data, showInfobox: true}));
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -136,7 +136,7 @@ class Game extends React.Component {
</div>
{this.render_congratulation()}
</div>;
};
}
}

export default Game;
2 changes: 1 addition & 1 deletion frontend/index/IndexPane.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import {Button, Tab} from "react-bootstrap";
import {Button} from "react-bootstrap";
import {FormattedMessage as Msg} from "react-intl";
import Card from "./card";
import React from "react";
Expand Down
4 changes: 2 additions & 2 deletions frontend/profile/ChangePasswordForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import React from "react";
import {Alert, Button, Form} from "react-bootstrap";
import {CSRFfetch, getFormData} from "../utils";
import { Input, PasswordInput } from '../components/Input';
import {PasswordInput} from '../components/Input';
import {Field, Form as FormWrapper} from "react-final-form";
import {FormattedMessage as Msg} from "react-intl";


export default class ChangePasswordForm extends React.Component {
onSubmit = async (values, form, callback) => {
onSubmit = async (values, form) => {
let data = getFormData(values);
data.append('new_password2', values['new_password1']);
let options = {method: 'POST', body: data};
Expand Down
4 changes: 2 additions & 2 deletions frontend/profile/ProfileForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default class ProfileForm extends React.Component {
onSubmit = async (values) => {
let options = {method: 'POST', body: getFormData(values)};
let response = await CSRFfetch(`${window.location.pathname}?section=main`, options);
return await response.json();
return response.json();
};

_render = ({handleSubmit, form, submitting}) => {
_render = ({handleSubmit, _form, submitting}) => {
return <Form onSubmit={handleSubmit}>
<Field name="username" component={UsernameInput} label={<Msg id="username"/>}/>
<Field name="email" component={Input} label={<Msg id="email"/>} type="email"/>
Expand Down
46 changes: 26 additions & 20 deletions maps/management/commands/fix_infobox_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,36 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('--since', action='store', type=int, default=None, help='Since id')

def update_translation(self, area: Region, updated):
for lang in settings.ALLOWED_LANGUAGES:
trans = area.load_translation(lang)
trans.infobox = updated[lang]
trans.save()

def update_region(self, area: Region):
updated = None
for lang in settings.ALLOWED_LANGUAGES:
trans = area.load_translation(lang)
infobox = trans.infobox
if 'capital' in infobox and isinstance(infobox['capital'], dict) and 'wiki' in infobox['capital']:
updated = check_link(area, lang, infobox['capital'], 'wiki', False)

if 'wiki' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'wiki', False)
if 'flag' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'flag', True)
if 'coat_of_arms' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'coat_of_arms', True)

if updated:
logger.info('Update translation for %s', area)
self.update_translation(area, updated)

def handle(self, *args, **options):
query = Region.objects.order_by('id').all()
if options['since']:
query = query.filter(pk__gte=options['since'])
for area in tqdm(query.iterator(), total=query.count()):
logger.debug('Check region %s', area)
updated = None
for lang in settings.ALLOWED_LANGUAGES:
trans = area.load_translation(lang)
infobox = trans.infobox
if 'capital' in infobox and isinstance(infobox['capital'], dict) and 'wiki' in infobox['capital']:
updated = check_link(area, lang, infobox['capital'], 'wiki', False)

if 'wiki' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'wiki', False)
if 'flag' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'flag', True)
if 'coat_of_arms' in infobox and updated is None:
updated = check_link(area, lang, infobox, 'coat_of_arms', True)

if updated:
logger.info('Update translation for %s', area)
for lang in settings.ALLOWED_LANGUAGES:
trans = area.load_translation(lang)
trans.infobox = updated[lang]
trans.save()
self.update_region(area)
sleep(3)
12 changes: 6 additions & 6 deletions maps/static/maps/js/google.maps.Polygon.getBounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* @see https://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
*/
if (!google.maps.Polygon.prototype.getBounds) {
google.maps.Polygon.prototype.getBounds = function(latLng) {
var bounds = new google.maps.LatLngBounds();
var paths = this.getPaths();
var path;
google.maps.Polygon.prototype.getBounds = function(_latLng) {
const bounds = new google.maps.LatLngBounds();
const paths = this.getPaths();
let path;

for (var p = 0; p < paths.getLength(); p++) {
for (let p = 0; p < paths.getLength(); p++) {
path = paths.getAt(p);
for (var i = 0; i < path.getLength(); i++) {
for (let i = 0; i < path.getLength(); i++) {
bounds.extend(path.getAt(i));
}
}
Expand Down
4 changes: 2 additions & 2 deletions maps/wambachers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gzip
import json
import logging
from dataclasses import dataclass
from dataclasses import dataclass, field
from io import BytesIO
from pathlib import Path
from typing import Dict, List, Optional
Expand All @@ -18,7 +18,7 @@ class WambachersNode:
id: int
text: Optional[str] = None
level: Optional[int] = None
children: List['WambachersNode'] = None
children: List['WambachersNode'] = field(default_factory=list)

@property
def osm_id(self) -> int:
Expand Down
5 changes: 1 addition & 4 deletions static/css/registration.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
.login-container h3 {
text-align: center;
line-height: 300%;
font-size: 22px;
}

.login-container .row {
Expand All @@ -56,10 +57,6 @@
width: 100%;
}

.login-container h3 {
font-size: 22px;
}

.profile-menu {
margin-top: 20px;
}
Expand Down