def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) gentity_id = kwargs.pop('gentity_id', None) super(GentityFileForm, self).__init__(*args, **kwargs) if user and not user.is_superuser: perms = user.get_rows_with_permission(Station(), 'edit') ids = [p.object_id for p in perms] self.fields["gentity"].queryset = Station.objects.filter( id__in=ids) if gentity_id: self.fields["gentity"].queryset = Station.objects.filter( id=gentity_id)
def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) gentity_id = kwargs.pop('gentity_id', None) instrument_id = kwargs.pop('instrument_id', None) super(TimeseriesForm, self).__init__(*args, **kwargs) if user and not user.is_superuser: perms = user.get_rows_with_permission(Station(), 'edit') ids = [p.object_id for p in perms] self.fields["gentity"].queryset = Station.objects.filter( id__in=ids) perms = user.get_rows_with_permission(Instrument(), 'edit') ids = [p.object_id for p in perms] self.fields["instrument"].queryset = Instrument.objects.filter( id__in=ids) if gentity_id: self.fields["gentity"].queryset = Station.objects.filter( id=gentity_id) self.fields["instrument"].queryset = Instrument.objects.filter( station__id=gentity_id) if instrument_id: self.fields["instrument"].queryset = Instrument.objects.filter( id=instrument_id) self.fields["instrument"].empty_label = None