def clean(self): cleaned_data = self.cleaned_data if cleaned_data.get("log_name"): # Due to the fact that the beer name is used in file paths, we need to validate it to prevent "injection" # type attacks log_name = cleaned_data.get("log_name") if GravityLog.name_is_valid(log_name): cleaned_data['log_name'] = log_name else: raise forms.ValidationError( "Log name must only consist of letters, numbers, dashes, spaces, " + "and underscores") else: raise forms.ValidationError("Log name must be specified") try: linked_device = GravitySensor.objects.get( id=cleaned_data.get('device')) cleaned_data['device'] = linked_device except: raise forms.ValidationError("Invalid device ID specified!") if linked_device.assigned_brewpi_device is not None: raise forms.ValidationError( "This device is managed by a temperature controller - To create a log, go to " + "the controller's dashboard and start a new beer log there") return cleaned_data
def gravity_dashboard(request, sensor_id, log_id=None): try: active_device = GravitySensor.objects.get(id=sensor_id) except: messages.error( request, u"Unable to load gravity sensor with ID {}".format(sensor_id)) return redirect('gravity_list') log_create_form = forms.GravityLogCreateForm() manual_add_form = forms.ManualPointForm() if log_id is None: active_log = active_device.active_log or None available_logs = GravityLog.objects.filter( device_id=active_device.id ) # TODO - Do I want to exclude the active log? else: try: active_log = GravityLog.objects.get(id=log_id, device_id=active_device.id) except: # If we are given an invalid log ID, let's return an error & drop back to the (valid) dashboard messages.error(request, u'Unable to load log with ID {}'.format(log_id)) return redirect('gravity_dashboard', sensor_id=sensor_id) available_logs = GravityLog.objects.filter( device_id=active_device.id).exclude(id=log_id) if active_log is None: # TODO - Determine if we want to load some fake "example" data (similar to what brewpi-www does) log_file_url = "/data/gravity_fake.csv" else: log_file_url = active_log.data_file_url('base_csv') return render(request, template_name="gravity/gravity_dashboard.html", context={ 'active_device': active_device, 'log_create_form': log_create_form, 'active_log': active_log, 'temp_display_format': config.DATE_TIME_FORMAT_DISPLAY, 'column_headers': GravityLog.column_headers_to_graph_string('base_csv'), 'log_file_url': log_file_url, 'available_logs': available_logs, 'selected_log_id': log_id, 'manual_add_form': manual_add_form })
def gravity_dashboard(request, sensor_id, log_id=None): try: active_device = GravitySensor.objects.get(id=sensor_id) except ObjectDoesNotExist: messages.error(request, u"Unable to load gravity sensor with ID {}".format(sensor_id)) return redirect('gravity_list') if active_device.sensor_type == GravitySensor.SENSOR_TILT: if not bluetooth_loaded and active_device.tilt_configuration.connection_type == TiltConfiguration.CONNECTION_BLUETOOTH: messages.warning(request, 'Bluetooth packages for python have not been installed. Tilt support will not work. ' 'Click <a href=\"http://www.fermentrack.com/help/bluetooth/\">here</a> to learn how ' 'to resolve this issue.') log_create_form = forms.GravityLogCreateForm() manual_add_form = forms.ManualPointForm() if log_id is None: active_log = active_device.active_log or None available_logs = GravityLog.objects.filter(device_id=active_device.id) # TODO - Do I want to exclude the active log? else: try: active_log = GravityLog.objects.get(id=log_id, device_id=active_device.id) except ObjectDoesNotExist: # If we are given an invalid log ID, let's return an error & drop back to the (valid) dashboard messages.error(request, u'Unable to load log with ID {}'.format(log_id)) return redirect('gravity_dashboard', sensor_id=sensor_id) available_logs = GravityLog.objects.filter(device_id=active_device.id).exclude(id=log_id) if active_log is None: # TODO - Determine if we want to load some fake "example" data (similar to what brewpi-www does) log_file_url = "/data/gravity_fake.csv" else: log_file_url = active_log.data_file_url('base_csv') return render(request, template_name="gravity/gravity_dashboard.html", context={'active_device': active_device, 'log_create_form': log_create_form, 'active_log': active_log, 'temp_display_format': config.DATE_TIME_FORMAT_DISPLAY, 'column_headers': GravityLog.column_headers_to_graph_string('base_csv'), 'log_file_url': log_file_url, 'available_logs': available_logs, 'selected_log_id': log_id, 'manual_add_form': manual_add_form})