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

#76 : edit forms #83

Merged
merged 9 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 2 additions & 7 deletions src/cards/migrations/0010_auto_20180330_0942.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-03-30 09:42
from __future__ import unicode_literals

from django.db import migrations
Expand All @@ -8,12 +7,8 @@
def migrate_help_links(apps, schema_editor):
Cards = apps.get_model("cards", "Card")
for card in Cards.objects.all():
new_value = card.help_links
if '\n' in new_value:
new_value = new_value.split('\n')
else:
new_value = list(new_value)
card.help_links = str(new_value)
new_value = card.help_links.splitlines()
card.help_links = new_value
Copy link
Owner

Choose a reason for hiding this comment

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

The use of new_value is not necessary anymore

card.save()


Expand Down
8 changes: 4 additions & 4 deletions src/cards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def __str__(self):

class CardStat(models.Model):
waste_reduction = models.DecimalField(decimal_places=1, max_digits=6,
blank=True, null=True)
blank=True, null=True)
co2_reduction = models.DecimalField(decimal_places=1, max_digits=6,
blank=True, null=True)
blank=True, null=True)
water_use_reduction = models.DecimalField(decimal_places=1, max_digits=6,
blank=True, null=True)
blank=True, null=True)
status = models.CharField(max_length=16, choices=STATS_STATUS,
default='ACTIVE', blank=True, null=True)
default='ACTIVE', blank=True, null=True)
year = models.SmallIntegerField(blank=True, null=True)
data_sources = models.ManyToManyField(DataSource)

Expand Down
3 changes: 1 addition & 2 deletions src/cards/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def get_sources(self, source_list):
sources = []
for data_src in source_list:
try:
ds = DataSource.objects.get(name=data_src['name'],
link=data_src['link'], status=data_src['status'])
ds = DataSource.objects.get(**data_src)
except DataSource.DoesNotExist:
ds = DataSource.objects.create(**data_src)
sources.append(ds)
Expand Down
1 change: 1 addition & 0 deletions src/djangoreactredux/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser',
),
'COERCE_DECIMAL_TO_STRING': False,
}

# ############ REST KNOX ########################
Expand Down
2 changes: 1 addition & 1 deletion src/static/containers/AdminCardAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AdminCardAdd extends Component {
cancelCard = () => {
const {
form: { resetFields },
dispatch
dispatch,
} = this.props;
resetFields();
dispatch(push('/zw-admin/card'));
Expand Down
12 changes: 6 additions & 6 deletions src/static/containers/AdminUserAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AdminUserAdd extends Component {
cancelUser = () => {
const {
form: { resetFields },
dispatch
dispatch,
} = this.props;
this.props.form.resetFields();
dispatch(push('/zw-admin/user'));
Expand Down Expand Up @@ -68,8 +68,8 @@ class AdminUserAdd extends Component {
form,
} = this.props;
let initialData = {};
let userFields = createUserFields;
let btnText = 'Create user!';
let userFieldsAction = createUserFields;
let btnText = 'Créer !';
if (this.state.editing) {
initialData = {
username: get(this.props, 'user_data.username', ''),
Expand All @@ -80,10 +80,10 @@ class AdminUserAdd extends Component {
do_smoke: get(this.props, 'user_data.do_smoke', false),
gender: get(this.props, 'user_data.gender'),
};
userFields = editUserFields;
btnText = 'Edit User!';
userFieldsAction = editUserFields;
btnText = 'Éditer !';
}
const userForm = generateForm(form, this.createUser, this.cancelUser, userFields, initialData, btnText);
const userForm = generateForm(form, this.createUser, this.cancelUser, userFieldsAction, initialData, btnText);

return (
<Layout>
Expand Down
6 changes: 3 additions & 3 deletions src/static/containers/ZeroCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ ZeroCard.propTypes = {
cost_score: PropTypes.number.isRequired,
help_links: PropTypes.arrayOf(PropTypes.string),
card_stats: PropTypes.shape({
co2_reduction: PropTypes.string,
waste_reduction: PropTypes.string,
water_use_reduction: PropTypes.string,
co2_reduction: PropTypes.number,
waste_reduction: PropTypes.number,
water_use_reduction: PropTypes.number,
data_sources: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
Expand Down
16 changes: 3 additions & 13 deletions src/static/utils/generateForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Button, Form } from 'antd';
import { get } from 'lodash';

import './Form.css';

Expand All @@ -12,18 +13,7 @@ const generateFormItem = (form, item, initialData) => {
rules
};
if (initialData) {
if (id.includes('.')) {
const splitArray = id.split('.');
if (splitArray[0] in initialData) {
let init = initialData[splitArray[0]];
for (let data of splitArray.slice(1)) {
init = init[data];
}
options.initialValue = init;
}
} else if (id in initialData) {
options.initialValue = initialData[id];
}
options.initialValue = get(initialData, id);
}
if (valuePropName) {
options.valuePropName = valuePropName;
Expand Down Expand Up @@ -74,7 +64,7 @@ export const generateForm = (form, onSubmit, onCancel, fieldSets, initialData, b
onClick={onCancel}
size="large"
>
Cancel
Annuler
</Button>
</Form>
);
Expand Down