问:
Setting a VBA form object using a string

Hello,

I am trying to set up a form which is a calendar from which the user can select a date (by default the current month appears). The form consists of 42 command buttons (I have left the default name ie. CommandButton1) which I am setting the day number.

At the moment I have a long-winded section of code for each button (I used Excel to generate this rather than type it all out) which locks and hides the button if it is outside of the month in question which looks like this:

```<code>NewDate.CommandButton1.Caption = Format(DATlngFirstMonth - DATintDayNumFirst + DATintX, "dd")
If DATintX < DATintDayNumFirst Then
    With NewDate.CommandButton1
        .Locked = True
        .Visible = DATbooShowExtraDays
        .ForeColor = RGB(150, 150, 150)
    End With
Else
    With NewDate.CommandButton1
        .Locked = False
        .Visible = True
        .ForeColor = RGB(0, 0, 0)
    End With
End If
</code>```

I know that I can refer to a command button by:

```<code>Dim objCommandButton As Object
Set objCommandButton = NewDate.CommandButton1
</code>```

..which neatens the code up somewhat. But what I would like to do is refer to the command button as a string so I can loop through all 42, ie.

```<code>Dim n as integer
n = 1

Do Until n > 42
Set objCommandButton = NewDate.CommandButton & n
'Some operations
n = n + 1
Loop
</code>```

Many thanks in advance for assistance.

答:
Here's code which iterates over ActiveX controls on active sheet:</p>

```<code>Sub IterateOverActiveXControlsByName()
    Dim x As Integer
    Dim oleObjs As OLEObjects
    Dim ctrl As MSForms.CommandButton
    Set oleObjs = ActiveSheet.OLEObjects
    For x = 1 To 10
        Set ctrl = oleObjs("CommandButton" & x).Object
    Next
End Sub
</code>```

Body:
Hello,

I am trying to set up a form which is a calendar from which the user can select a date (by default the current month appears). The form consists of 42 command buttons (I have left the default name ie. CommandButton1) which I am setting the day number.

At the moment I have a long-winded section of code for each button (I used Excel to generate this rather than type it all out) which locks and hides the button if it is outside of the month in question which looks like this:

NewDate.CommandButton1.Caption = Format(DATlngFirstMonth - DATintDayNumFirst + DATintX, "dd")
If DATintX < DATintDayNumFirst Then
    With NewDate.CommandButton1
        .Locked = True
        .Visible = DATbooShowExtraDays
        .ForeColor = RGB(150, 150, 150)
    End With
Else
    With NewDate.CommandButton1
        .Locked = False
        .Visible = True
        .ForeColor = RGB(0, 0, 0)
    End With
End If

I know that I can refer to a command button by:

Dim objCommandButton As Object
Set objCommandButton = NewDate.CommandButton1

..which neatens the code up somewhat. But what I would like to do is refer to the command button as a string so I can loop through all 42, ie.

Dim n as integer
n = 1

Do Until n > 42
Set objCommandButton = NewDate.CommandButton & n
'Some operations
n = n + 1
Loop

Many thanks in advance for assistance.

Body:
Here's code which iterates over ActiveX controls on active sheet:

Sub IterateOverActiveXControlsByName()
    Dim x As Integer
    Dim oleObjs As OLEObjects
    Dim ctrl As MSForms.CommandButton
    Set oleObjs = ActiveSheet.OLEObjects
    For x = 1 To 10
        Set ctrl = oleObjs("CommandButton" & x).Object
    Next
End Sub


来源: stackexchange

问:
json and how to work with it
say I have the following json object;

```<code>{'fname':'john', 'lname':'Locke'}
</code>```

and the following text boxes

```<code><input type="text" name="txtFirstName" value="" />
<input type="text" name="txtLastName" value="" />
</code>```

how do I go ahead and assign these textboxes the values in the json object with jquery?

答:
Something like this should do the trick:</p>

```<code>$("input[@name='txtFirstName']").val(jsonObject.fname);
$("input[@name='txtLastName']").val(jsonObject.lname);
</code>```

OwnerDisplayName: Emin

ContentLicense: CC BY-SA 2.5

Title: json and how to work with it

Body:
say I have the following json object;

{'fname':'john', 'lname':'Locke'}

and the following text boxes

<input type="text" name="txtFirstName" value="" />
<input type="text" name="txtLastName" value="" />

how do I go ahead and assign these textboxes the values in the json object with jquery?

Body:
Something like this should do the trick:

$("input[@name='txtFirstName']").val(jsonObject.fname);
$("input[@name='txtLastName']").val(jsonObject.lname);

OwnerDisplayName: John Fisher


问:
Regex return match and extended matches
Can regex return matches and extended matches. What I mean is one regex expression that can return different number of found elements depending on the structure. My text is:

```<code>AB : CDE / 123.456.1; 1
AC : DEF / 3.1.2
</code>```

My return (match) should be:

```<code>'AB', 'CDE', '123.456.1', '1'
'AC', 'DEF','3.1.2'
</code>```

So if there is a value after a semicolon then the regex should match and return that as well. But if is not there it should still match the part and return the rest.

My code is:

```<code>import re

s = '''AB : CDE / 123.456.1; 1
AC : DEF / 3.1.2'''

match1 = re.search(r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*(;\s*\d+)', s)
print(match1[0])

match2 = re.search(r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*', s)
print(match2[0])
</code>```

Where match1 only matches the first occurrance and match2 only the second. What would be the regex to work in both cases?

答:
The r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*(;\s*\d+)' pattern contains an obligatory (;\s*\d+) pattern at the end. You need to make it optional and you may do it by adding a ? quantifier after it, so as to match 1 or 0 occurrences of the subpattern.

With other minor enhancements, you may use

```<code>r'A[BC]\s*:\s*\w+\s*/\s*[\w.]+\s*(?:;\s*\d+)?'
</code>```

Note all capturing groups are removed, and non-capturing ones are introduced since you only get the whole match value in the end.

Details

A[BC] - AB or AC

\s*:\s* - a colon enclosed with 0+ whitespace chars

\w+ - or more word chars

\s*/\s* - a /  enclosed with 0+ whitespace chars

[\w.]+ - 1 or more word or . chars

\s* - 0+ whitespaces

(?:;\s*\d+)? - an optional sequence of

; - a ;

\s* - 0+ whitespaces

\d+ - 1+ digits

ContentLicense: CC BY-SA 3.0

Title: Regex return match and extended matches

Body:
Can regex return matches and extended matches. What I mean is one regex expression that can return different number of found elements depending on the structure. My text is:

AB : CDE / 123.456.1; 1
AC : DEF / 3.1.2

My return (match) should be:

'AB', 'CDE', '123.456.1', '1'
'AC', 'DEF','3.1.2'

So if there is a value after a semicolon then the regex should match and return that as well. But if is not there it should still match the part and return the rest.

My code is:

import re

s = '''AB : CDE / 123.456.1; 1
AC : DEF / 3.1.2'''

match1 = re.search(r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*(;\s*\d+)', s)
print(match1[0])

match2 = re.search(r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*', s)
print(match2[0])

Where match1 only matches the first occurrance and match2 only the second. What would be the regex to work in both cases?

Body:
The r'((?:AB|AC))\s*:\s*(\w+)\s*\/\s*([\w.]+)\s*(;\s*\d+)' pattern contains an obligatory (;\s*\d+) pattern at the end. You need to make it optional and you may do it by adding a ? quantifier after it, so as to match 1 or 0 occurrences of the subpattern.

With other minor enhancements, you may use

r'A[BC]\s*:\s*\w+\s*/\s*[\w.]+\s*(?:;\s*\d+)?'

Note all capturing groups are removed, and non-capturing ones are introduced since you only get the whole match value in the end.

Details

A[BC] - AB or AC

\s*:\s* - a colon enclosed with 0+ whitespace chars

\w+ - or more word chars

\s*/\s* - a /  enclosed with 0+ whitespace chars

[\w.]+ - 1 or more word or . chars

\s* - 0+ whitespaces

(?:;\s*\d+)? - an optional sequence of

; - a ;

\s* - 0+ whitespaces

\d+ - 1+ digits


问:
React - What is the best way to change an elements text each time the user clicks anywhere on screen?
I've started learning React, and after having read through the documentation, have a question..

I want to do the following:

I want to render text as part of a component. Then when a user clicks anywhere on the screen, the text changes, then changes again on a second click, and then again on a third, and finally, a fourth click.

I'd like to know what best practice would be when doing this in react? I was thinking about using the 'onClick' method, but that would only allow for two states?

Some assistance would be very much appreciated to help me on my react journey.

const welcome =
Welcome to my app 1/4
;

ReactDOM.render(
  welcome,
  document.getElementById('theapp')
);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="/styles.css">
  <title>Learn ReactJS</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>

<body>
  <script src="https://s3.amazonaws.com/codecademy-content/courses/React/react-course-bundle.min.js"></script>
  <script src="/app.compiled.js"></script>

  <div id="theapp"></div>

</body>

</html></code>```

答:
You can put your texts in array like :

```<code> const data = ['one', 'two', 'three'];
</code>```

Than everytime when user clicks, increment the state i by 1.

```<code>import React from 'react';

const data = ['one', 'two', 'three']

class App extends React.Component {
   constructor(props){
    super(props);
      this.state = {
        name: 'hello',
        i : 0
      }
   }
   click(){
       // if it's the last element of array than it will start from 0 index again
       if(data[this.state.i] == undefined){
          this.setState({i : 0})
       }
       setTimeout(function() { this.setState({name: data[this.state.i], i : this.state.i + 1 }); }.bind(this), 50);
       // incrementing counter by 1 everytime user clicks

   }
   render() {

      return (
         <div>
             <div>
               <span>{this.state.name}</span>
               <button onClick={this.click.bind(this)}>Click</button>
             </div>

         </div>
      );
   }
}

export default App;
</code>```

Body:
I've started learning React, and after having read through the documentation, have a question..

I want to do the following:

I want to render text as part of a component. Then when a user clicks anywhere on the screen, the text changes, then changes again on a second click, and then again on a third, and finally, a fourth click.

I'd like to know what best practice would be when doing this in react? I was thinking about using the 'onClick' method, but that would only allow for two states?

Some assistance would be very much appreciated to help me on my react journey.

const welcome =
Welcome to my app 1/4
;

ReactDOM.render(
  welcome,
  document.getElementById('theapp')
);

<!DOCTYPE html>

  <meta charset="utf-8">
  <link rel="stylesheet" href="/styles.css">
  <title>Learn ReactJS</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Body:
You can put your texts in array like :

 const data = ['one', 'two', 'three'];

Than everytime when user clicks, increment the state i by 1.

import React from 'react';

const data = ['one', 'two', 'three']

class App extends React.Component {
   constructor(props){
    super(props);
      this.state = {
        name: 'hello',
        i : 0
      }
   }
   click(){
       // if it's the last element of array than it will start from 0 index again
       if(data[this.state.i] == undefined){
          this.setState({i : 0})
       }
       setTimeout(function() { this.setState({name: data[this.state.i], i : this.state.i + 1 }); }.bind(this), 50);
       // incrementing counter by 1 everytime user clicks

   }
   render() {

      return (
         <div>
             <div>
               <span>{this.state.name}</span>
               <button onClick={this.click.bind(this)}>Click</button>
             </div>

         </div>
      );
   }
}

export default App;


问:
Iterating through HashMap by values
I need to loop through a HashMap, but to give importance to the values' order.
For example, consider the following hash map of <String, Integer>:

```<code>{"dog" : 2, "bird": 3, "cat" : 1}
</code>```

Now, I need to loop through the hasp map in order of ascending values, so that

```<code>for () {
 System.out.println( currentKey );
}
</code>```

will always output

"cat", "dog", "bird"

答:
If you want to have the map sort itself by value as you insert entries then the easiest way would probably be to use something like the TreeMultimap in Google's collections library.

If you still want to use a hashmap but have the values sorted when you retrieve them from the set, then you can take two approaches - either you can get the values using the values() method and then run Collections.sort() on the returned list, or you can again use a class like TreeMultimap, adding all the entries in the current hashmap and then enumerating through them.

Title: Iterating through HashMap by values

Body:
I need to loop through a HashMap, but to give importance to the values' order.
For example, consider the following hash map of <String, Integer>:

{"dog" : 2, "bird": 3, "cat" : 1}

Now, I need to loop through the hasp map in order of ascending values, so that

for () {
 System.out.println( currentKey );
}

will always output

"cat", "dog", "bird"


问:
BIML SSIS ScriptTask as a data source - Error with OutputBuffer
I am getting the below error when trying to generate a package through BIML using a ScriptTask as a datasource.  I have a large (circa 5GB) XML file to load and wanted to use a StreamReader to get the data into the database.

'Output0Buffer' does not contain a definition for 'PORTF_LIST' and no extension method 'PORTF_LIST' accepting a first argument of type 'Output0Buffer' could be found (are you missing a using directive or an assembly reference?).

This is occurring for each column. The columns are dynamic and come from a separate method in a c# class looking at the dacpac so should be the same names and casing everywhere.

Sample of the file as below:

```<code><ANALYTICS>
  <INSTRUMENTS ASOF_DATE="3/31/2017" CREATE_DATE="4/2/2017" RECORDS="3763">
    <INSTRUMENT>
      <PORTF_LIST>XX1245897</PORTF_LIST>
      <PRT_FULL_NAME>Convertible Bonds</PRT_FULL_NAME>
      <ISIN>11803384</ISIN>
    </INSTRUMENT>
     </INSTRUMENTS>
</ANALYTICS>
</code>```

Output buffer is defined as below (there are 250 odd columns, but all follow the same pattern:

```<code>           <OutputBuffers>
                <OutputBuffer Name="Output0" IsSynchronous="false">
                    <Columns>
<Column Name="PORTF_LIST" DataType="String" Length="255"/>
<Column Name="PRT_FULL_NAME" DataType="String" Length="255"/>
<Column Name="ISIN" DataType="String" Length="255"/>
                    </Columns>
                </OutputBuffer>
            </OutputBuffers>
</code>```

The script task code where I am trying to add to the buffer is below:

```<code>    <#@ property name="Elements" type="String" #>
    <#@ property name="Columns" type="String" #>
    <#@ property name="BufferColumns" type="String" #>
    <#@ property name="RootElement" type="String" #>
    <ScriptComponentProject ProjectCoreName="SC_eb1debcd2374468ebccbbfad4fbe5976" Name="XmlSource">
              <AssemblyReferences>
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
                <AssemblyReference AssemblyPath="System.dll" />
                <AssemblyReference AssemblyPath="System.AddIn.dll" />
                <AssemblyReference AssemblyPath="System.Data.dll" />
                <AssemblyReference AssemblyPath="System.Windows.Forms.dll" />
                <AssemblyReference AssemblyPath="System.Xml.dll" />
                <AssemblyReference AssemblyPath="System.Xml.Linq.dll" />
                <AssemblyReference AssemblyPath="System.Core.dll" />
             </AssemblyReferences>
            <OutputBuffers>
                <!--
                Define what your buffer is called and what it looks like
                Must set IsSynchronous as false. Otherwise it is a transformation
                (one row enters, one row leaves) and not a source.
                -->
                <OutputBuffer Name="Output0" IsSynchronous="false">
                    <Columns>
                        <#=BufferColumns#>
                    </Columns>
                </OutputBuffer>
            </OutputBuffers>
              <Files>
                <File Path="Properties\AssemblyInfo.cs">
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("XmlSource")]
[assembly: AssemblyDescription("Script Component as source")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XmlSource")]
[assembly: AssemblyCopyright("Copyright @ 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
</File>
<File Path="main.cs">
<![CDATA[

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Security;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Forms;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{

        public override void PreExecute()
        {
            base.PreExecute();

        }

        public override void PostExecute()
        {
            base.PostExecute();
        }

        public string sourceFile =  Dts.Variables["User::FileName"].Value.ToString();

        public override void CreateNewOutputRows()
        {
            foreach (var myXmlData in (
                   from elements in StreamReader(sourceFile, "INSTRUMENT")
                   select new
                        {
PORTF_LIST = elements.Element("PORTF_LIST").Value,
PRT_FULL_NAME = elements.Element("PRT_FULL_NAME").Value,
ISIN = elements.Element("ISIN").Value

                        }
                ))
                {
                    try
                    {
                        Output0Buffer.AddRow();
    Output0Buffer.PORTF_LIST = myXmlData.PORTF_LIST;
    Output0Buffer.PRT_FULL_NAME = myXmlData.PRT_FULL_NAME;
    Output0Buffer.ISIN = myXmlData.ISIN;
                    }
                    catch (Exception e)
                    {
                        string errorMessage = string.Format("Data retrieval failed: {0}", e.Message);
                        bool cancel;
                        ComponentMetaData.FireError(0, ComponentMetaData.Name, errorMessage,string.Empty,0, out cancel);
                    }

                }

        }

        public static IEnumerable<XElement> StreamReader(String filename, string elementName)
        {

                         // Create an XML reader for this file.
                        using (XmlReader reader = XmlReader.Create(filename))
                        {
                            reader.MoveToContent(); // will not advance reader if already on a content node; if successful, ReadState is Interactive
                            reader.Read();          // this is needed, even with MoveToContent and ReadState.Interactive
                            while(!reader.EOF && reader.ReadState == ReadState.Interactive)
                            {
                                if(reader.NodeType == XmlNodeType.Element && reader.Name.Equals(elementName))
                                {
                                     // this advances the reader...so it's either XNode.ReadFrom() or reader.Read(), but not both
                                     var matchedElement = XNode.ReadFrom(reader) as XElement;
                                     if(matchedElement != null)
                                         yield return matchedElement;
                                }
                                else
                                    reader.Read();
                            }
                            reader.Close();

                        }
        }

}
]]>
                </File>
              </Files>
              <ReadOnlyVariables>
                  <Variable Namespace="User" DataType="String" VariableName="FileName" />
              </ReadOnlyVariables>
              <ReadWriteVariables>
              </ReadWriteVariables>
            </ScriptComponentProject>
</code>```

I've checked the code in a console app and it reads the XML file fine, but no luck with the BIML. There are about 250 odd columns so I am trying to avoid doing this manually so if you have any ideas what I am doing wrong I'd really appreciate it!

答:
It seems that the script task does not like underscores in the OutputBuffer.

I created a stub package manually and intellisense had PORTFLIST rather than PORTF_LIST when assigning the value.

So that snippit of code should be:

```<code>Output0Buffer.AddRow();
Output0Buffer.PORTFLIST = myXmlData.PORTF_LIST;
Output0Buffer.PRTFULLNAME = myXmlData.PRT_FULL_NAME;
Output0Buffer.ISIN = myXmlData.ISIN
</code>```

I have another error, my favorite "EmitSsis. Internal Compiler Error: Workflow EmitSsis contains fatal errors.", but at least this one is solved!

Thanks Bill for your help, and sorry I led you down the garden path with the wrong column name in the posted error, or you probably would have known the issue!

ContentLicense: CC BY-SA 4.0

Body:
I am getting the below error when trying to generate a package through BIML using a ScriptTask as a datasource.  I have a large (circa 5GB) XML file to load and wanted to use a StreamReader to get the data into the database.

'Output0Buffer' does not contain a definition for 'PORTF_LIST' and no extension method 'PORTF_LIST' accepting a first argument of type 'Output0Buffer' could be found (are you missing a using directive or an assembly reference?).

This is occurring for each column. The columns are dynamic and come from a separate method in a c# class looking at the dacpac so should be the same names and casing everywhere.

Sample of the file as below:

<ANALYTICS>
  <INSTRUMENTS ASOF_DATE="3/31/2017" CREATE_DATE="4/2/2017" RECORDS="3763">
    <INSTRUMENT>
      <PORTF_LIST>XX1245897</PORTF_LIST>
      <PRT_FULL_NAME>Convertible Bonds</PRT_FULL_NAME>
      <ISIN>11803384</ISIN>
    </INSTRUMENT>
     </INSTRUMENTS>
</ANALYTICS>

Output buffer is defined as below (there are 250 odd columns, but all follow the same pattern:

           <OutputBuffers>
                <OutputBuffer Name="Output0" IsSynchronous="false">
                    <Columns>
<Column Name="PORTF_LIST" DataType="String" Length="255"/>
<Column Name="PRT_FULL_NAME" DataType="String" Length="255"/>
<Column Name="ISIN" DataType="String" Length="255"/>
                    </Columns>
                </OutputBuffer>
            </OutputBuffers>

The script task code where I am trying to add to the buffer is below:

    <#@ property name="Elements" type="String" #>
    <#@ property name="Columns" type="String" #>
    <#@ property name="BufferColumns" type="String" #>
    <#@ property name="RootElement" type="String" #>

I've checked the code in a console app and it reads the XML file fine, but no luck with the BIML. There are about 250 odd columns so I am trying to avoid doing this manually so if you have any ideas what I am doing wrong I'd really appreciate it!

Body:
It seems that the script task does not like underscores in the OutputBuffer.

I created a stub package manually and intellisense had PORTFLIST rather than PORTF_LIST when assigning the value.

So that snippit of code should be:

Output0Buffer.AddRow();
Output0Buffer.PORTFLIST = myXmlData.PORTF_LIST;
Output0Buffer.PRTFULLNAME = myXmlData.PRT_FULL_NAME;
Output0Buffer.ISIN = myXmlData.ISIN

I have another error, my favorite "EmitSsis. Internal Compiler Error: Workflow EmitSsis contains fatal errors.", but at least this one is solved!

Thanks Bill for your help, and sorry I led you down the garden path with the wrong column name in the posted error, or you probably would have known the issue!


问:
Displaying data on first activity that is set in the second activity
The thing is I have a dashboard which will display data for 6 production lines, and the progress will be viewed in simply textviews.

However, the data for the textviews are coming from a series of IF statements and calculations which are performed on another activity.

When I run the app because the dashboard is trying to read data before it has been set by the second activity, there is null pointers which is understandable as I haven't got the chance to even get to the second activity yet.

To compromise I had to set the IF statements on the dashboard to buttons, however, this is hindering the usability of my app and I would like the data to automatically refresh on the dashboard without pressing a button.

On the second activity I am saving the values to shared preferences and then on the dashboard I am getting the shared preference and setting it to the textviews but still getting nulls as the dashboard is the first screen.

Line Details Java: (Home button to return to dashboard):

```<code>            SharedPreferences.Editor editor = getActivity().getSharedPreferences(MyPREFERENCES, MODE_PRIVATE).edit();

            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S2 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("20")) {
                if (actualshippersnum > optimum20) {
                    plus20 = (int) (actualshippersnum - optimum20);
                    editor.putInt("Key1", plus20);
                    Toast.makeText(getActivity(), "Line S1 ahead by: " + (plus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum20) {
                    minus20 = (int) (optimum20 - actualshippersnum);
                    editor.putInt("Key2", minus20);
                    Toast.makeText(getActivity(), "Line S1 behind by: " + (minus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum20) {
                    editor.putInt("Key3", percentageActual20);
                    Toast.makeText(getActivity(), "Line S1 is on target at!", Toast.LENGTH_LONG).show();
                }
            } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("30")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    plus30 = (int) (actualshippersnum - optimum30);
                    editor.putInt("Key 4", plus30);
                    Toast.makeText(getActivity(), "Line S1 ahead by: " + (plus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum30) {
                    minus30 = (int) (optimum30 - actualshippersnum);
                    editor.putInt("Key 5", minus30);
                    Toast.makeText(getActivity(), "Line S1 behind by: " + (minus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum30) {
                    editor.putInt("Key 6", percentageActual30);
                    Toast.makeText(getActivity(), "Line S1 is on target!", +Toast.LENGTH_LONG).show();
                }
            }
            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S2 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("20")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum20) {
                    plus20 = (int) (actualshippersnum - optimum20);
                    editor.putInt("Key 7", plus20);
                    Toast.makeText(getActivity(), "Line S2 ahead by: " + (plus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum20) {
                    minus20 = (int) (optimum20 - actualshippersnum);
                    editor.putInt("Key 8", minus20);
                    Toast.makeText(getActivity(), "Line S2 behind by: " + (minus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum20) {
                    editor.putInt("Key 9", percentageActual20);
                    Toast.makeText(getActivity(), "Line S2 is on target at!", Toast.LENGTH_LONG).show();
                }
            } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("30")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    plus30 = (int) (actualshippersnum - optimum30);
                    editor.putInt("Key 10", plus30);
                    Toast.makeText(getActivity(), "Line S2 ahead by: " + (plus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum30) {
                    minus30 = (int) (optimum30 - actualshippersnum);
                    editor.putInt("Key 11", minus30);
                    Toast.makeText(getActivity(), "Line S2 behind by: " + (minus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum30) {
                    editor.putInt("Key 12", percentageActual30);
                    Toast.makeText(getActivity(), "Line S2 is on target!", +Toast.LENGTH_LONG).show();
                }
            }
            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S3 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S3")) {
                if (spinnerSelection2.equals("20")) {
                    //HAVENT FILLED INTO DECOVIEW - 20
                    if (actualshippersnum == null) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("Refresh Error");
                        builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                        builder.setIcon(R.drawable.warning_icon);
                        builder.setCancelable(true);

                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });

                        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else
                    if (actualshippersnum > optimum20) {
                        plus20 = (int) (actualshippersnum - optimum20);
                        editor.putInt("Key 13", plus20);
                        Toast.makeText(getActivity(), "Line S3 ahead by: " + (plus20)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum < optimum20) {
                        minus20 = (int) (optimum20 - actualshippersnum);
                        editor.putInt("Key 14", minus20);
                        Toast.makeText(getActivity(), "Line S3 behind by: " + (minus20)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum == optimum20) {
                        editor.putInt("Key 15", percentageActual20);
                        Toast.makeText(getActivity(), "Line S3 is on target!" , Toast.LENGTH_LONG).show();
                    }
                }
                else if (spinnerSelection2.equals("30")) {

                    //HAVENT FILLED INTO DECOVIEW - 30
                    if (actualshippersnum == null) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("Refresh Error");
                        builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                        builder.setIcon(R.drawable.warning_icon);
                        builder.setCancelable(true);

                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });

                        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else
                    if (actualshippersnum > optimum30) {
                        plus30 = (int) (actualshippersnum - optimum30);
                        editor.putInt("Key 16", plus30);
                        Toast.makeText(getActivity(), "Line S3 ahead by: " + (plus30)+ " shippers" ,Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum < optimum30) {
                        minus30 = (int) (optimum30 - actualshippersnum);
                        editor.putInt("Key 17", minus30);
                        Toast.makeText(getActivity(), "Line S3 behind by: " + (minus30)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum == optimum30) {
                        editor.putInt("Key 18", percentageActual30);
                        Toast.makeText(getActivity(), "Line S3 is on target!", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    });
}
</code>```

Dashboard Java: (On Resume)

```<code>public void onResume() {
    super.onResume();

    int getKey1, getKey2, getKey3, getKey4, getKey5, getKey6, getKey7, getKey8, getKey9, getKey10, getKey11, getKey12, getKey13, getKey14, getKey15, getKey16,getKey17, getKey18;

    if (spinnerSelection == null || spinnerSelection2 == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
        builder.setTitle("Data Input Error");
        builder.setMessage("No SP found!");
        builder.setIcon(R.drawable.warning_icon);
        builder.setCancelable(true);

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("20")) {
        if (actualshippersnum > optimum20) {
            getKey1 = sharedPreferences.getInt("Key1", plus20);
            bar4.setText(getKey1);
        } else if (actualshippersnum < optimum20) {
            getKey2 = sharedPreferences.getInt("Key2", minus20);
            bar4.setText(getKey2);
        } else if (actualshippersnum == optimum20) {
            getKey3 = sharedPreferences.getInt("Key3", percentageActual20);
            bar4.setText(getKey3);
    }

        else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("30")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum30) {
            getKey4 = sharedPreferences.getInt("Key4", plus30);
            bar4.setText(getKey4);
        } else if (actualshippersnum < optimum30) {
            getKey5 = sharedPreferences.getInt("Key5", minus30);
            bar4.setText(getKey5);
        } else if (actualshippersnum == optimum30) {
            getKey6 = sharedPreferences.getInt("Key6", percentageActual30);
            bar4.setText(getKey6);
        }
    }
    if (spinnerSelection == null || spinnerSelection2 == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
        builder.setTitle("Data Input Error");
        builder.setMessage("No SP found");
        builder.setIcon(R.drawable.warning_icon);
        builder.setCancelable(true);

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("20")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum20) {
            getKey7 = sharedPreferences.getInt("Key7", plus20);
            bar5.setText(getKey7);
        } else if (actualshippersnum < optimum20) {
            getKey8 = sharedPreferences.getInt("Key8", minus20);
            bar4.setText(getKey8);
        } else if (actualshippersnum == optimum20) {
            getKey9 = sharedPreferences.getInt("Key9", percentageActual20);
            bar4.setText(getKey9);
        }
    } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("30")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum30) {
            getKey10 = sharedPreferences.getInt("Key10", plus30);
            bar4.setText(getKey10);
        } else if (actualshippersnum < optimum30) {
            getKey11 = sharedPreferences.getInt("Key11", minus30);
            bar4.setText(getKey11);
        } else if (actualshippersnum == optimum30) {
            getKey12 = sharedPreferences.getInt("Key12", percentageActual30);
            bar4.setText(getKey12);
        }
    }
        if (spinnerSelection == null || spinnerSelection2 == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Data Input Error");
            builder.setMessage("Line S3 Data has not been entered yet!");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (spinnerSelection.equals("S3")) {
            if (spinnerSelection2.equals("20")) {
                //HAVENT FILLED INTO DECOVIEW - 20
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum20) {
                    getKey13 = sharedPreferences.getInt("Key13", plus20);
                    bar6.setText(getKey13);
                } else if (actualshippersnum < optimum20) {
                    getKey14 = sharedPreferences.getInt("Key14", minus20);
                    bar6.setText(getKey14);
                } else if (actualshippersnum == optimum20) {
                    getKey15 = sharedPreferences.getInt("Key15", percentageActual20);
                    bar6.setText(getKey15);
                }
            } else if (spinnerSelection2.equals("30")) {

                //HAVENT FILLED INTO DECOVIEW - 30
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    getKey16 = sharedPreferences.getInt("Key16", plus30);
                    bar6.setText(getKey16);
                } else if (actualshippersnum < optimum30) {
                    getKey17 = sharedPreferences.getInt("Key17", minus30);
                    bar6.setText(getKey17);
                } else if (actualshippersnum == optimum30) {
                    getKey18 = sharedPreferences.getInt("Key18", percentageActual30);
                    bar6.setText(getKey18);
</code>```

答:
You can override onActivityResult method in "Dashboard" and get result from "Line Details" activity.
Follow this link for more info</p>

Body:
The thing is I have a dashboard which will display data for 6 production lines, and the progress will be viewed in simply textviews.

However, the data for the textviews are coming from a series of IF statements and calculations which are performed on another activity.

When I run the app because the dashboard is trying to read data before it has been set by the second activity, there is null pointers which is understandable as I haven't got the chance to even get to the second activity yet.

To compromise I had to set the IF statements on the dashboard to buttons, however, this is hindering the usability of my app and I would like the data to automatically refresh on the dashboard without pressing a button.

On the second activity I am saving the values to shared preferences and then on the dashboard I am getting the shared preference and setting it to the textviews but still getting nulls as the dashboard is the first screen.

Line Details Java: (Home button to return to dashboard):

            SharedPreferences.Editor editor = getActivity().getSharedPreferences(MyPREFERENCES, MODE_PRIVATE).edit();

            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S2 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("20")) {
                if (actualshippersnum > optimum20) {
                    plus20 = (int) (actualshippersnum - optimum20);
                    editor.putInt("Key1", plus20);
                    Toast.makeText(getActivity(), "Line S1 ahead by: " + (plus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum20) {
                    minus20 = (int) (optimum20 - actualshippersnum);
                    editor.putInt("Key2", minus20);
                    Toast.makeText(getActivity(), "Line S1 behind by: " + (minus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum20) {
                    editor.putInt("Key3", percentageActual20);
                    Toast.makeText(getActivity(), "Line S1 is on target at!", Toast.LENGTH_LONG).show();
                }
            } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("30")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    plus30 = (int) (actualshippersnum - optimum30);
                    editor.putInt("Key 4", plus30);
                    Toast.makeText(getActivity(), "Line S1 ahead by: " + (plus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum30) {
                    minus30 = (int) (optimum30 - actualshippersnum);
                    editor.putInt("Key 5", minus30);
                    Toast.makeText(getActivity(), "Line S1 behind by: " + (minus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum30) {
                    editor.putInt("Key 6", percentageActual30);
                    Toast.makeText(getActivity(), "Line S1 is on target!", +Toast.LENGTH_LONG).show();
                }
            }
            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S2 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("20")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum20) {
                    plus20 = (int) (actualshippersnum - optimum20);
                    editor.putInt("Key 7", plus20);
                    Toast.makeText(getActivity(), "Line S2 ahead by: " + (plus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum20) {
                    minus20 = (int) (optimum20 - actualshippersnum);
                    editor.putInt("Key 8", minus20);
                    Toast.makeText(getActivity(), "Line S2 behind by: " + (minus20) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum20) {
                    editor.putInt("Key 9", percentageActual20);
                    Toast.makeText(getActivity(), "Line S2 is on target at!", Toast.LENGTH_LONG).show();
                }
            } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("30")) {
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    plus30 = (int) (actualshippersnum - optimum30);
                    editor.putInt("Key 10", plus30);
                    Toast.makeText(getActivity(), "Line S2 ahead by: " + (plus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum < optimum30) {
                    minus30 = (int) (optimum30 - actualshippersnum);
                    editor.putInt("Key 11", minus30);
                    Toast.makeText(getActivity(), "Line S2 behind by: " + (minus30) + " shippers", Toast.LENGTH_LONG).show();
                } else if (actualshippersnum == optimum30) {
                    editor.putInt("Key 12", percentageActual30);
                    Toast.makeText(getActivity(), "Line S2 is on target!", +Toast.LENGTH_LONG).show();
                }
            }
            if (spinnerSelection == null || spinnerSelection2 == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Data Input Error");
                builder.setMessage("Line S3 Data has not been entered yet!");
                builder.setIcon(R.drawable.warning_icon);
                builder.setCancelable(true);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else if (spinnerSelection.equals("S3")) {
                if (spinnerSelection2.equals("20")) {
                    //HAVENT FILLED INTO DECOVIEW - 20
                    if (actualshippersnum == null) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("Refresh Error");
                        builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                        builder.setIcon(R.drawable.warning_icon);
                        builder.setCancelable(true);

                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });

                        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else
                    if (actualshippersnum > optimum20) {
                        plus20 = (int) (actualshippersnum - optimum20);
                        editor.putInt("Key 13", plus20);
                        Toast.makeText(getActivity(), "Line S3 ahead by: " + (plus20)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum < optimum20) {
                        minus20 = (int) (optimum20 - actualshippersnum);
                        editor.putInt("Key 14", minus20);
                        Toast.makeText(getActivity(), "Line S3 behind by: " + (minus20)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum == optimum20) {
                        editor.putInt("Key 15", percentageActual20);
                        Toast.makeText(getActivity(), "Line S3 is on target!" , Toast.LENGTH_LONG).show();
                    }
                }
                else if (spinnerSelection2.equals("30")) {

                    //HAVENT FILLED INTO DECOVIEW - 30
                    if (actualshippersnum == null) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("Refresh Error");
                        builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                        builder.setIcon(R.drawable.warning_icon);
                        builder.setCancelable(true);

                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });

                        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else
                    if (actualshippersnum > optimum30) {
                        plus30 = (int) (actualshippersnum - optimum30);
                        editor.putInt("Key 16", plus30);
                        Toast.makeText(getActivity(), "Line S3 ahead by: " + (plus30)+ " shippers" ,Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum < optimum30) {
                        minus30 = (int) (optimum30 - actualshippersnum);
                        editor.putInt("Key 17", minus30);
                        Toast.makeText(getActivity(), "Line S3 behind by: " + (minus30)+ " shippers" , Toast.LENGTH_LONG).show();
                    } else if (actualshippersnum == optimum30) {
                        editor.putInt("Key 18", percentageActual30);
                        Toast.makeText(getActivity(), "Line S3 is on target!", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    });
}

Dashboard Java: (On Resume)

public void onResume() {
    super.onResume();

    int getKey1, getKey2, getKey3, getKey4, getKey5, getKey6, getKey7, getKey8, getKey9, getKey10, getKey11, getKey12, getKey13, getKey14, getKey15, getKey16,getKey17, getKey18;

    if (spinnerSelection == null || spinnerSelection2 == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
        builder.setTitle("Data Input Error");
        builder.setMessage("No SP found!");
        builder.setIcon(R.drawable.warning_icon);
        builder.setCancelable(true);

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    } else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("20")) {
        if (actualshippersnum > optimum20) {
            getKey1 = sharedPreferences.getInt("Key1", plus20);
            bar4.setText(getKey1);
        } else if (actualshippersnum < optimum20) {
            getKey2 = sharedPreferences.getInt("Key2", minus20);
            bar4.setText(getKey2);
        } else if (actualshippersnum == optimum20) {
            getKey3 = sharedPreferences.getInt("Key3", percentageActual20);
            bar4.setText(getKey3);
    }

        else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("30")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum30) {
            getKey4 = sharedPreferences.getInt("Key4", plus30);
            bar4.setText(getKey4);
        } else if (actualshippersnum < optimum30) {
            getKey5 = sharedPreferences.getInt("Key5", minus30);
            bar4.setText(getKey5);
        } else if (actualshippersnum == optimum30) {
            getKey6 = sharedPreferences.getInt("Key6", percentageActual30);
            bar4.setText(getKey6);
        }
    }
    if (spinnerSelection == null || spinnerSelection2 == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
        builder.setTitle("Data Input Error");
        builder.setMessage("No SP found");
        builder.setIcon(R.drawable.warning_icon);
        builder.setCancelable(true);

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("20")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum20) {
            getKey7 = sharedPreferences.getInt("Key7", plus20);
            bar5.setText(getKey7);
        } else if (actualshippersnum < optimum20) {
            getKey8 = sharedPreferences.getInt("Key8", minus20);
            bar4.setText(getKey8);
        } else if (actualshippersnum == optimum20) {
            getKey9 = sharedPreferences.getInt("Key9", percentageActual20);
            bar4.setText(getKey9);
        }
    } else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("30")) {
        if (actualshippersnum == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Refresh Error");
            builder.setMessage("No SP found");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (actualshippersnum > optimum30) {
            getKey10 = sharedPreferences.getInt("Key10", plus30);
            bar4.setText(getKey10);
        } else if (actualshippersnum < optimum30) {
            getKey11 = sharedPreferences.getInt("Key11", minus30);
            bar4.setText(getKey11);
        } else if (actualshippersnum == optimum30) {
            getKey12 = sharedPreferences.getInt("Key12", percentageActual30);
            bar4.setText(getKey12);
        }
    }
        if (spinnerSelection == null || spinnerSelection2 == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
            builder.setTitle("Data Input Error");
            builder.setMessage("Line S3 Data has not been entered yet!");
            builder.setIcon(R.drawable.warning_icon);
            builder.setCancelable(true);

            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        } else if (spinnerSelection.equals("S3")) {
            if (spinnerSelection2.equals("20")) {
                //HAVENT FILLED INTO DECOVIEW - 20
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum20) {
                    getKey13 = sharedPreferences.getInt("Key13", plus20);
                    bar6.setText(getKey13);
                } else if (actualshippersnum < optimum20) {
                    getKey14 = sharedPreferences.getInt("Key14", minus20);
                    bar6.setText(getKey14);
                } else if (actualshippersnum == optimum20) {
                    getKey15 = sharedPreferences.getInt("Key15", percentageActual20);
                    bar6.setText(getKey15);
                }
            } else if (spinnerSelection2.equals("30")) {

                //HAVENT FILLED INTO DECOVIEW - 30
                if (actualshippersnum == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
                    builder.setTitle("Refresh Error");
                    builder.setMessage("Cannot Refresh! Please Fill in Line Details");
                    builder.setIcon(R.drawable.warning_icon);
                    builder.setCancelable(true);

                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });

                    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (actualshippersnum > optimum30) {
                    getKey16 = sharedPreferences.getInt("Key16", plus30);
                    bar6.setText(getKey16);
                } else if (actualshippersnum < optimum30) {
                    getKey17 = sharedPreferences.getInt("Key17", minus30);
                    bar6.setText(getKey17);
                } else if (actualshippersnum == optimum30) {
                    getKey18 = sharedPreferences.getInt("Key18", percentageActual30);
                    bar6.setText(getKey18);


问:
JSON attribute as relation type name
```<code>with {conatcts_count:10,account_count:20,time_stamp:'2010_12_231'} as data
merge (u:Customers1 {name:'sai',id:1})-[r:REL {conatcts_count:data.conatcts_count,account_count:data.account_count,ts:data.time_stamp}]-(s:Sale1 {name:'sales_123',id:1})
</code>```

I have tried this... But it always creating a new nodes when I am changing the values of JSON. I am looking for something which takes the JSON timestamp and create a relation with same nodes.

答:
It's due to the MERGE command.

Usage : MERGE pattern

The merge command performs a MATCH pattern at first, and if there is no result, then it does a CREATE pattern

So if you don't have any relationship between yours n and s nodes, the MATCH returns nothing, and so ask the DB to create the pattern (u)-[:REL]->(s).

What you should instead, it's this :

```<code>with {conatcts_count:10,account_count:20,time_stamp:'2010_12_231'} as data
MERGE (u:Customers1 {name:'sai',id:1})
MERGE (s:Sale1 {name:'sales_123',id:1})
MERGE (u)-[:REL {conatcts_count:data.conatcts_count,account_count:data.account_count,ts:data.time_stamp}]-(s)
</code>```

Title: JSON attribute as relation type name

Body:
with {conatcts_count:10,account_count:20,time_stamp:'2010_12_231'} as data
merge (u:Customers1 {name:'sai',id:1})-[r:REL {conatcts_count:data.conatcts_count,account_count:data.account_count,ts:data.time_stamp}]-(s:Sale1 {name:'sales_123',id:1})

I have tried this... But it always creating a new nodes when I am changing the values of JSON. I am looking for something which takes the JSON timestamp and create a relation with same nodes.

Body:
It's due to the MERGE command.

Usage : MERGE pattern

The merge command performs a MATCH pattern at first, and if there is no result, then it does a CREATE pattern

So if you don't have any relationship between yours n and s nodes, the MATCH returns nothing, and so ask the DB to create the pattern (u)-[:REL]->(s).

What you should instead, it's this :

with {conatcts_count:10,account_count:20,time_stamp:'2010_12_231'} as data
MERGE (u:Customers1 {name:'sai',id:1})
MERGE (s:Sale1 {name:'sales_123',id:1})
MERGE (u)-[:REL {conatcts_count:data.conatcts_count,account_count:data.account_count,ts:data.time_stamp}]-(s)


问:
How to switch Keyspace in Cassandra using CQL?
I used USE billKeyspace; to enter a keyspace and start using it. Now I want to exit this keyspace and enter another keyspace. How to do that?

If I use exit; or quit; it exits out of cql session itself and then I have to connect again.

答:
You can switch simply by "use" command.</p>

```<code>cqlsh>    DESC KEYSPACEs;

system_distributed system_auth system system_traces

cqlsh> use system_distributed;
cqlsh:system_distributed>
cqlsh:system_distributed>
cqlsh:system_distributed> use system_auth;
cqlsh:system_auth>
</code>```

Body:
You can switch simply by "use" command.

cqlsh>    DESC KEYSPACEs;

system_distributed system_auth system system_traces

cqlsh> use system_distributed;
cqlsh:system_distributed>
cqlsh:system_distributed>
cqlsh:system_distributed> use system_auth;
cqlsh:system_auth>


问:
Django: How to show all images in images model
I am trying to show all images associated with the currently selected user

This is built off of this solved question: django upload to image model with foreign key to user

Model.py

```<code>class Images(models.Model):
    image = models.ImageField(upload_to='profile_image', null=True, default='profile_image/none/no-img.png')
    user = models.ForeignKey(User, on_delete=models.CASCADE)
</code>```

Views.py

```<code>@login_required
def index_account(request):
    args = {'user': request.user }
    return render(request, 've/cp/index_account.html', args)
</code>```

Template > index_account.html

```<code>    <p><a href="{% url 've:edit_images' %}">Edit your images</a></p>
    # test to see if it worked w/o if
    {{ user.images.image}}

    # ideal solution
    {% if user.images.images %}
        {% for img in user.images %}
        <img src="{{ user.images.image.url }}"><br>
        {% endfor %}
    {% else %}
    <p>No images</p>

    {% endif %}

    <br>
    <hr>
</code>```

答:
The code you have provided is not going to work for what you want. So here is an example of something that probably will:

Example

views.py

```<code>from app_name.models import Images
@login_required
def index_account(request):
    images = Images.objects.filter(user=request.user)
    return render(request, 've/cp/index_account.html', {"images": images})
</code>```

index_account.html

```<code><p><a href="{% url 've:edit_images' %}">Edit your images</a></p>

# ideal solution
{% if images %}
    {% for img in images %}
    <img src="{{ img.url }}"><br>
    {% endfor %}
{% else %}
<p>No images</p>

{% endif %}

<br>
<hr>
</code>```

Hope this helps!

Body:
I am trying to show all images associated with the currently selected user

This is built off of this solved question: django upload to image model with foreign key to user

Model.py

class Images(models.Model):
    image = models.ImageField(upload_to='profile_image', null=True, default='profile_image/none/no-img.png')
    user = models.ForeignKey(User, on_delete=models.CASCADE)

Views.py

@login_required
def index_account(request):
    args = {'user': request.user }
    return render(request, 've/cp/index_account.html', args)

Template > index_account.html

Edit your images

    # test to see if it worked w/o if
    {{ user.images.image}}

    # ideal solution
    {% if user.images.images %}
        {% for img in user.images %}

        {% endfor %}
    {% else %}

No images

    {% endif %}

Body:
The code you have provided is not going to work for what you want. So here is an example of something that probably will:

Example

views.py

from app_name.models import Images
@login_required
def index_account(request):
    images = Images.objects.filter(user=request.user)
    return render(request, 've/cp/index_account.html', {"images": images})

index_account.html

<p><a href="{% url 've:edit_images' %}">Edit your images</a></p>

# ideal solution
{% if images %}
    {% for img in images %}
    <img src="{{ img.url }}"><br>
    {% endfor %}
{% else %}
<p>No images</p>

{% endif %}

<br>
<hr>

Hope this helps!


问:
How to run angular cli ng test with production build settings and AOT enabled
Is there a way to run the angular cli tests with the command ng test that tells the underlining compiler to use the ng build --prod settings?

I ask because here are often aot compilation errors encountered with ng build --prod that do not occur with normal compilation with ng build

答:
Have you tried ng build --aot ?

https://angular.io/guide/aot-compiler

To test with production settings you could use ng test --environment=prod.