Project

General

Profile

« Previous | Next » 

Revision 8

Added by Matt Wheeler about 14 years ago

Some bug fixes.
Slight hack in eml-coverage and veg.xsd to get around Django case-insensitivity & VegX entities that only differ by case.
Changed default db relationship to one2many from many2many

View differences:

lookups.php
23 23
'IndividualOrganismType' => True,
24 24
'ObservationType' => True,
25 25
'AbioticObservationType' => True,
26
'TemporalCoverage' => True,
27
'TaxonomicCoverage' => True,
28 26
'TaxonRelationshipAssertion' => True,
29 27
'Specimen' => True,
30 28
'Publication' => True,
......
35 33

  
36 34
//Identified by the id field of the entity they extend
37 35
$idExtend = array(
38
'temporalCoverage' => 'TemporalCoverage_extend',
39
'taxonomicCoverage' => 'TaxonomicCoverage_extend',
36
#'taxonomicCoverageLC' => 'TaxonomicCoverage_extend',
37
#'temporalCoverageLC' => 'TemporalCoverage_extend'
40 38
'personnel' => 'ResponsibleParty_extend',
41 39
'associatedParty' => 'ResponsibleParty_extend'
42 40
);
......
64 62
      $primaryKey = 'ISSN__exact';
65 63
      $primaryNodeName = 'ISSN';
66 64
      $secondaryKeys = array('pageRange__exact');
67
      $secondaryNodenames = array('pageRange');
65
      $secondaryNodeNames = array('pageRange');
68 66
      break;
69 67
    case 'Book':
70 68
    case 'AudioVisual':
......
127 125
}
128 126

  
129 127
$adHocAttr = array(
130
'Institution' => True
128
'Institution' => True,
129
'TemporalCoverage' => True,
130
'TaxonomicCoverage' => True,
131
'temporalCoverageLC' => True,
132
'taxonomicCoverageLC' => True
131 133
);
132 134

  
133 135
function handleAdHocAttr($tName) {
......
139 141
  $secondaryNodeNames = array();
140 142

  
141 143
  switch($tName) {
144
    case 'TemporalCoverage':
145
      $primaryKey = 'attr_id__exact';
146
      $primaryAttrName = 'id';
147
      break;
148
    case 'TaxonomicCoverage':
149
      $primaryKey = 'attr_id__exact';
150
      $primaryAttrName = 'id';
151
      break;
152
    case 'temporalCoverageLC':
153
      $primaryKey = 'TemporalCoverage_extend__attr_id__exact';
154
      $primaryAttrName = 'id';
155
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
156
      $secondaryNodeNames = array('system','scope');
157
      break;
158
    case 'taxonomicCoverageLC':
159
      $primaryKey = 'TaxonomicCoverage_extend__attr_id__exact';
160
      $primaryAttrName = 'id';
161
      $secondaryKeys = array('attr_system__exact','attr_scope__exact');
162
      $secondaryNodeNames = array('system','scope');
163
      break;
142 164
    case 'Institution':
143 165
      $primaryKey = 'attr_identifier__exact';
144 166
      $primaryAttrName = 'identifier';
......
146 168
  }
147 169

  
148 170
  if($primaryAttrName != '') {
149
    $def = "    $primaryAttrName" . "_val = None #ad hoc attr\n".
150
           "    for attr in node.attributes.keys():\n".
151
           "      aVal = node.attributes[attr].nodeValue\n".
152
           "      if attr == '$primaryAttrName':\n".
153
           "        $primaryAttrName" . "_val = aVal\n\n".
154
           "    if $primaryAttrName" . "_val != None:\n".
155
           "      q = $tName.objects.filter($primaryKey = $primaryAttrName" . "_val)\n".
156
           "      if len(q) > 0:\n".
157
           "        return q[0]\n".
158
           "      else:\n".
159
           "        return $tName()\n".
160
           "    else:\n".
161
           "      return $tName()\n";
171
    $def = "";
172
    foreach($secondaryNodeNames as $skey) {
173
      $def .= "    $skey" . "_val = None\n";
174
    }
175
    $def .= "    $primaryAttrName" . "_val = None #ad hoc attr\n".
176
            "    for attr in node.attributes.keys():\n".
177
            "      aVal = node.attributes[attr].nodeValue\n".
178
            "      if attr == '$primaryAttrName':\n".
179
            "        $primaryAttrName" . "_val = aVal\n";
180
    foreach($secondaryNodeNames as $skey) {
181
    $def .= "      if attr == '$skey':\n".
182
            "        $skey" . "_val = aVal\n";
183
    }
184
    $def .= "\n    if $primaryAttrName" . "_val != None:\n".
185
            "      q = $tName.objects.filter($primaryKey = $primaryAttrName" . "_val)\n";
186
    $i = 0;
187
    foreach($secondaryNodeNames as $skey) {
188
      $secondaryKeyName = $secondaryKeys[$i];
189
    $def .= "      if $skey" . "_val != None:\n".
190
            "        q = q.filter($secondaryKeyName = $skey" . "_val)\n";
191
      $i = $i + 1;
192
    }
193
    $def .= "      if len(q) > 0:\n".
194
            "        return q[0]\n".
195
            "      else:\n".
196
            "        return $tName()\n".
197
            "    else:\n".
198
            "      return $tName()\n";
162 199

  
163 200
  }
164 201

  

Also available in: Unified diff