def date_add (request, topic_map, entity_id, assertion_id): entity = get_topic_or_404(Entity, entity_id) assertion = entity.get_assertion(assertion_id) if assertion is None: raise Http404 authority = assertion.authority if authority != request.user.eats_user.get_current_authority(): raise Http404 calendar_choices = create_choice_list( topic_map, Calendar.objects.filter_by_authority(authority)) date_period_choices = create_choice_list( topic_map, DatePeriod.objects.filter_by_authority(authority)) date_type_choices = create_choice_list( topic_map, DateType.objects.filter_by_authority(authority)) if request.method == 'POST': form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices, request.POST) if form.is_valid(): date_id = form.save(assertion) if '_continue' in form.data: redirect_ids = {'assertion_id': assertion_id, 'date_id': date_id, 'entity_id': entity_id} redirect_url = reverse('date-change', kwargs=redirect_ids) else: redirect_ids = {'entity_id': entity_id} redirect_url = reverse('entity-change', kwargs=redirect_ids) return HttpResponseRedirect(redirect_url) else: form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices) context_data = {'form': form} return render_to_response('eats/edit/date_add.html', context_data, context_instance=RequestContext(request))
def date_add (request, topic_map, entity_id, assertion_id): entity = get_topic_or_404(Entity, entity_id) assertion = entity.get_assertion(assertion_id) if assertion is None: raise Http404 authority = assertion.authority if authority != request.user.eats_user.get_current_authority(): raise Http404 calendar_choices = create_choice_list( topic_map, Calendar.objects.filter_by_authority(authority)) date_period_choices = create_choice_list( topic_map, DatePeriod.objects.filter_by_authority(authority)) date_type_choices = create_choice_list( topic_map, DateType.objects.filter_by_authority(authority)) if request.method == 'POST': form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices, request.POST) if form.is_valid(): date_id = form.save(assertion) if '_continue' in form.data: redirect_ids = {'assertion_id': assertion_id, 'date_id': date_id, 'entity_id': entity_id} redirect_url = reverse('date-change', kwargs=redirect_ids) else: redirect_ids = {'entity_id': entity_id} redirect_url = reverse('entity-change', kwargs=redirect_ids) return redirect(redirect_url) else: form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices) context_data = {'form': form} return render(request, 'eats/edit/date_add.html', context_data)
def __init__(self, topic_map, model, data=None, instance=None, **kwargs): super(AuthorityForm, self).__init__(topic_map, model, data=data, instance=instance, **kwargs) self.fields['calendars'].choices = create_choice_list( topic_map, Calendar.objects.all())[1:] self.fields['date_periods'].choices = create_choice_list( topic_map, DatePeriod.objects.all())[1:] self.fields['date_types'].choices = create_choice_list( topic_map, DateType.objects.all())[1:] self.fields['entity_relationship_types'].choices = create_choice_list( topic_map, EntityRelationshipType.objects.all())[1:] self.fields['entity_types'].choices = create_choice_list( topic_map, EntityType.objects.all())[1:] self.fields['languages'].choices = create_choice_list( topic_map, Language.objects.all())[1:] self.fields['name_types'].choices = create_choice_list( topic_map, NameType.objects.all())[1:] self.fields['name_part_types'].choices = create_choice_list( topic_map, NamePartType.objects.all())[1:] self.fields['scripts'].choices = create_choice_list( topic_map, Script.objects.all())[1:] self.fields['editors'].choices = [(editor.user.pk, editor.user.username) for editor in EATSUser.objects.all()]
def formset (self): entity_type_choices = create_choice_list( self.topic_map, EntityType.objects.filter_by_authority( self.authority)) data = {'entity_type_choices': entity_type_choices, 'prefix': 'entity_types'} return self._create_formset(EntityTypeFormSet, data)
def formset (self): name_type_choices = create_choice_list( self.topic_map, NameType.objects.filter_by_authority( self.authority)) language_choices = create_choice_list( self.topic_map, Language.objects.filter_by_authority( self.authority)) script_choices = create_choice_list( self.topic_map, Script.objects.filter_by_authority(self.authority)) name_part_type_choices = create_choice_list( self.topic_map, NamePartType.objects.filter_by_authority( self.authority)) data = {'prefix': 'names', 'name_type_choices': name_type_choices, 'language_choices': language_choices, 'script_choices': script_choices, 'name_part_type_choices': name_part_type_choices} return self._create_formset(NameFormSet, data)
def date_change (request, topic_map, entity_id, assertion_id, date_id): entity = get_topic_or_404(Entity, entity_id) assertion = entity.get_assertion(assertion_id) if assertion is None: raise Http404 date = assertion.get_date(date_id) if date is None: raise Http404 authority = assertion.authority if authority != request.user.eats_user.get_current_authority(): raise Http404 calendar_choices = create_choice_list( topic_map, Calendar.objects.filter_by_authority(authority)) date_period_choices = create_choice_list( topic_map, DatePeriod.objects.filter_by_authority(authority)) date_type_choices = create_choice_list( topic_map, DateType.objects.filter_by_authority(authority)) if request.method == 'POST': form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices, request.POST, instance=date) redirect_ids = {'entity_id': entity_id} redirect_url = reverse('entity-change', kwargs=redirect_ids) if '_delete' in form.data: form.delete() return HttpResponseRedirect(redirect_url) if form.is_valid(): date_id = form.save() if '_continue' in form.data: redirect_ids['assertion_id'] = assertion_id redirect_ids['date_id'] = date_id redirect_url = reverse('date-change', kwargs=redirect_ids) return HttpResponseRedirect(redirect_url) else: form = DateForm(topic_map, calendar_choices, date_period_choices, date_type_choices, instance=date) context_data = {'form': form} return render_to_response('eats/edit/date_change.html', context_data, context_instance=RequestContext(request))
def __init__ (self, topic_map, model, data=None, instance=None, **kwargs): super(AuthorityForm, self).__init__(topic_map, model, data=data, instance=instance, **kwargs) self.fields['calendars'].choices = create_choice_list( topic_map, Calendar.objects.all())[1:] self.fields['date_periods'].choices = create_choice_list( topic_map, DatePeriod.objects.all())[1:] self.fields['date_types'].choices = create_choice_list( topic_map, DateType.objects.all())[1:] self.fields['entity_relationship_types'].choices = create_choice_list( topic_map, EntityRelationshipType.objects.all())[1:] self.fields['entity_types'].choices = create_choice_list( topic_map, EntityType.objects.all())[1:] self.fields['languages'].choices = create_choice_list( topic_map, Language.objects.all())[1:] self.fields['name_types'].choices = create_choice_list( topic_map, NameType.objects.all())[1:] self.fields['name_part_types'].choices = create_choice_list( topic_map, NamePartType.objects.all())[1:] self.fields['scripts'].choices = create_choice_list( topic_map, Script.objects.all())[1:] self.fields['editors'].choices = [(editor.user.pk, editor.user.username) for editor in EATSUser.objects.all()]
def _create_form_fields (self, post_data, instance_data): """Creates dynamic fields to accomodate the post/instance data. :param post_data: POSTed data :type post_data: dictionary :param instance_data: `Language` instance data :type instance_data: dictionary """ name_part_type_choices = create_choice_list( self.topic_map, NamePartType.objects.all()) data = post_data or instance_data count = 2 for name in data: if name.startswith(self.npt_base_name): count += 1 count = max(count, 3) for i in range(count): self.fields[self.npt_base_name + str(i)] = forms.ChoiceField( choices=name_part_type_choices, required=False, label='Name part type %s' % str(i+1))
def _create_form_fields(self, post_data, instance_data): """Creates dynamic fields to accomodate the post/instance data. :param post_data: POSTed data :type post_data: dictionary :param instance_data: `Language` instance data :type instance_data: dictionary """ name_part_type_choices = create_choice_list(self.topic_map, NamePartType.objects.all()) data = post_data or instance_data count = 2 for name in data: if name.startswith(self.npt_base_name): count += 1 count = max(count, 3) for i in range(count): self.fields[self.npt_base_name + str(i)] = forms.ChoiceField( choices=name_part_type_choices, required=False, label='Name part type %s' % str(i + 1))