Changeset 3815c51 for telemeta/views/web.py
- Timestamp:
- 05/18/07 12:28:50 (6 years ago)
- Branches:
- master, crem, crem2, dev, dev2, diadems, forma, generic, instru_search, lam, nlivemulti, production, release/1.4.4, security, social, storage, test, video
- Children:
- 879d772
- Parents:
- aa5a73f
- git-author:
- olivier <> (05/18/07 12:28:50)
- git-committer:
- olivier <> (05/18/07 12:28:50)
- File:
-
- 1 edited
-
telemeta/views/web.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telemeta/views/web.py
r01bf9f7 r3815c51 102 102 'items': items}) 103 103 104 def __get_ dictionary_list(self):104 def __get_enumerations_list(self): 105 105 from django.db.models import get_models 106 106 models = get_models(telemeta.models) 107 107 108 dictionaries = []108 enumerations = [] 109 109 for model in models: 110 if getattr(model, "is_ dictionary", False):111 dictionaries.append({"name": model._meta.verbose_name_plural,110 if getattr(model, "is_enumeration", False): 111 enumerations.append({"name": model._meta.verbose_name_plural, 112 112 "id": model._meta.module_name}) 113 return dictionaries113 return enumerations 114 114 115 115 def __get_admin_context_vars(self): 116 return {" dictionaries": self.__get_dictionary_list()}116 return {"enumerations": self.__get_enumerations_list()} 117 117 118 118 def admin_index(self, request): 119 119 return render_to_response('admin.html', self. __get_admin_context_vars()) 120 120 121 def __get_ dictionary(self, id):121 def __get_enumeration(self, id): 122 122 from django.db.models import get_models 123 123 models = get_models(telemeta.models) … … 130 130 131 131 return model 132 133 132 134 def edit_ dictionary(self, request, dictionary_id):133 def edit_enumeration(self, request, enumeration_id): 135 134 136 dictionary = self.__get_dictionary(dictionary_id)137 if dictionary== None:135 enumeration = self.__get_enumeration(enumeration_id) 136 if enumeration == None: 138 137 raise Http404 139 138 140 139 vars = self.__get_admin_context_vars() 141 vars[" dictionary_id"] = dictionary._meta.module_name142 vars[" dictionary_name"] = dictionary._meta.verbose_name143 vars[" dictionary_name_plural"] = dictionary._meta.verbose_name_plural144 vars[" dictionary_values"] = dictionary.objects.all()145 return render_to_response(' dictionary_edit.html', vars)140 vars["enumeration_id"] = enumeration._meta.module_name 141 vars["enumeration_name"] = enumeration._meta.verbose_name 142 vars["enumeration_name_plural"] = enumeration._meta.verbose_name_plural 143 vars["enumeration_values"] = enumeration.objects.all() 144 return render_to_response('enumeration_edit.html', vars) 146 145 147 def add_to_ dictionary(self, request, dictionary_id):146 def add_to_enumeration(self, request, enumeration_id): 148 147 149 dictionary = self.__get_dictionary(dictionary_id)150 if dictionary== None:148 enumeration = self.__get_enumeration(enumeration_id) 149 if enumeration == None: 151 150 raise Http404 152 151 153 dictionary_value = dictionary(value=request.POST['value'])154 dictionary_value.save()152 enumeration_value = enumeration(value=request.POST['value']) 153 enumeration_value.save() 155 154 156 return self.edit_ dictionary(request, dictionary_id)155 return self.edit_enumeration(request, enumeration_id) 157 156 158 def update_ dictionary(self, request, dictionary_id):157 def update_enumeration(self, request, enumeration_id): 159 158 160 dictionary = self.__get_dictionary(dictionary_id)161 if dictionary== None:159 enumeration = self.__get_enumeration(enumeration_id) 160 if enumeration == None: 162 161 raise Http404 163 162 164 163 if request.POST.has_key("remove"): 165 dictionary.objects.filter(id__in=request.POST['sel']).delete()164 enumeration.objects.filter(id__in=request.POST.getlist('sel')).delete() 166 165 167 return self.edit_ dictionary(request, dictionary_id)166 return self.edit_enumeration(request, enumeration_id) 168 167 169 def edit_ dictionary_value(self, request, dictionary_id, value_id):168 def edit_enumeration_value(self, request, enumeration_id, value_id): 170 169 171 dictionary = self.__get_dictionary(dictionary_id)172 if dictionary== None:170 enumeration = self.__get_enumeration(enumeration_id) 171 if enumeration == None: 173 172 raise Http404 174 173 175 174 vars = self.__get_admin_context_vars() 176 vars[" dictionary_id"] = dictionary._meta.module_name177 vars[" dictionary_name"] = dictionary._meta.verbose_name178 vars[" dictionary_name_plural"] = dictionary._meta.verbose_name_plural179 vars[" dictionary_record"] = dictionary.objects.get(id__exact=value_id)180 return render_to_response(' dictionary_edit_value.html', vars)175 vars["enumeration_id"] = enumeration._meta.module_name 176 vars["enumeration_name"] = enumeration._meta.verbose_name 177 vars["enumeration_name_plural"] = enumeration._meta.verbose_name_plural 178 vars["enumeration_record"] = enumeration.objects.get(id__exact=value_id) 179 return render_to_response('enumeration_edit_value.html', vars) 181 180 182 def update_ dictionary_value(self, request, dictionary_id, value_id):181 def update_enumeration_value(self, request, enumeration_id, value_id): 183 182 184 183 if request.POST.has_key("save"): 185 dictionary = self.__get_dictionary(dictionary_id)186 if dictionary== None:184 enumeration = self.__get_enumeration(enumeration_id) 185 if enumeration == None: 187 186 raise Http404 188 187 189 record = dictionary.objects.get(id__exact=value_id)188 record = enumeration.objects.get(id__exact=value_id) 190 189 record.value = request.POST["value"] 191 190 record.save() 192 191 193 return self.edit_ dictionary(request, dictionary_id)192 return self.edit_enumeration(request, enumeration_id) 194 193 195 194 196 def media_item_edit(request, media_item_id):197 "Provide MediaItem object edition"198 199 media_item = MediaItem.objects.get(pk=media_item_id)200 dynprops = media_item.get_dynamic_properties()201 return render_to_response('media_item.html', {'media_item': media_item, 'dynprops' : dynprops})202 203 def media_item_update(request, media_item_id):204 "Handle MediaItem object edition form submission"205 206 media_item = MediaItem.objects.get(pk=media_item_id)207 media_item.author = request.POST['author']208 media_item.title = request.POST['title']209 media_item.save()210 211 pattern = re.compile(r'^dynprop_(\d+)$')212 for name, value in request.POST.items():213 match = pattern.search(name)214 if match:215 prop_id = match.groups()[0]216 prop = MediaItemPropertyDefinition.objects.get(pk=prop_id)217 telemeta.logger.debug("prop_id: " + prop_id + " ; " + "media_item_id: " +218 media_item_id + " ; value: " + value +219 " ; type:" + prop.type)220 media_item = MediaItem.objects.get(pk=media_item_id)221 property, created = MediaItemProperty.objects.get_or_create(222 media_item=media_item, definition=prop)223 224 if prop.type == 'text':225 property.value = value226 else:227 value = int(value)228 229 if value > 0:230 enum_item = MediaItemPropertyEnumerationItem.objects.get(pk=value)231 property.enum_item = enum_item232 else:233 property.enum_item = 0234 235 property.save()236 237 return media_item_edit(request, media_item_id)238 239 195 240 196
Note: See TracChangeset
for help on using the changeset viewer.
