コード例 #1
0
ファイル: views.py プロジェクト: drellano/django-dash
def edit_widget_data(request, layout_uid, workspace=None):
    """
    Externally edit widget data on the dashboard
    """

    username = request.META['HTTP_USERNAME']
    password = request.META['HTTP_PASSWORD']
    user = authenticate(username=username, password=password)
    workspace_id = None
    try:
        if user.is_authenticated():
            try:
                dashboard_settings = DashboardSettings.objects.get(layout_uid=layout_uid)
                user_id = dashboard_settings.user_id

                if workspace:
                    workspace_obj = DashboardWorkspace._default_manager.get(
                                        slug=workspace,
                                        user=user_id,
                                        layout_uid=layout_uid
                                        )
                    workspace_id = workspace_obj.id

                data = json.loads(request.body)
                title = data["title"]
                obj = DashboardEntry.objects.get(plugin_data__contains=title,
                                                 layout_uid=layout_uid, workspace_id=workspace_id)
            except ObjectDoesNotExist as e:
                return HttpResponse(str(e))

            if request.method == 'POST':
                plugin = obj.get_plugin(fetch_related_data=True)
                obj.plugin_data = request.body
                obj.save()
                messages.info(request, ('The dashboard widget "{0}" was edited'
                                        'successfully.').format(plugin.name))
            return HttpResponse(plugin.name+' plugin: '+obj.plugin_uid+' was successfully updated...')
    except AttributeError as e:
        return HttpResponse(str(e))
コード例 #2
0
ファイル: dash_plugins.py プロジェクト: GMcD/django-dash
    def post_processor(self):
        """
        If no text available, use dummy.
        """
        key = '{0}-{1}-{2}'.format(self.layout_uid, self.placeholder_uid, self.uid)
        self.data.weather_data_json = cache.get(key)

        if not self.data.weather_data_json:

            if self.data.public_ip:
                api_endpoint_url = API_ENDPOINT_URL.format(API_KEY, 'json', self.data.public_ip)

                try:
                    data = str(urlopen(api_endpoint_url).read())

                    self.data.weather_data_json = json.loads(data)

                    cache.set(key, self.data.weather_data_json, int(self.data.cache_for))
                except Exception as e:
                    if DEBUG:
                        logger.debug(e)

        if self.data.weather_data_json:
            data = self.data.weather_data_json['data']

            try:
                current_condition = data['current_condition'][0]
            except:
                current_condition = None

            if current_condition:
                self.data.current_cloudcover = current_condition['cloudcover']
                self.data.current_humidity = current_condition['humidity']
                self.data.current_pressure = current_condition['pressure']
                self.data.current_visibility = current_condition['visibility']
                self.data.current_temp_c = current_condition['temp_C']

                try:
                    self.data.current_weather_desc = current_condition['weatherDesc'][0]['value']
                except Exception as e:
                    pass

                try:
                    self.data.current_weather_icon_url = current_condition['weatherIconUrl'][0]['value']
                except Exception as e:
                    pass

            try:
                weather = data['weather'][0]
            except:
                weather = None

            if weather:
                self.data.temp_max_c = weather['tempMaxC']
                self.data.temp_min_c = weather['tempMinC']
                self.data.windspeed_kmph = weather['windspeedKmph']
                self.data.wind_dir_16_point = weather['winddir16Point']

                try:
                    self.data.weather_desc = weather['weatherDesc'][0]['value']
                except Exception as e:
                    pass

                try:
                    self.data.weather_icon_url = weather['weatherIconUrl'][0]['value']
                except Exception as e:
                    pass
コード例 #3
0
ファイル: dash_plugins.py プロジェクト: ykkwon/django-dash
    def post_processor(self):
        """
        If no text available, use dummy.
        """
        key = '{0}-{1}-{2}'.format(self.layout_uid, self.placeholder_uid,
                                   self.uid)
        self.data.weather_data_json = cache.get(key)

        if not self.data.weather_data_json:

            if self.data.public_ip:
                api_endpoint_url = API_ENDPOINT_URL.format(
                    API_KEY, 'json', self.data.public_ip)

                try:
                    data = str(urlopen(api_endpoint_url).read())

                    self.data.weather_data_json = json.loads(data)

                    cache.set(key, self.data.weather_data_json,
                              int(self.data.cache_for))
                except Exception as e:
                    if DEBUG:
                        logger.debug(e)

        if self.data.weather_data_json:
            data = self.data.weather_data_json['data']

            try:
                current_condition = data['current_condition'][0]
            except:
                current_condition = None

            if current_condition:
                self.data.current_cloudcover = current_condition['cloudcover']
                self.data.current_humidity = current_condition['humidity']
                self.data.current_pressure = current_condition['pressure']
                self.data.current_visibility = current_condition['visibility']
                self.data.current_temp_c = current_condition['temp_C']

                try:
                    self.data.current_weather_desc = current_condition[
                        'weatherDesc'][0]['value']
                except Exception as e:
                    pass

                try:
                    self.data.current_weather_icon_url = current_condition[
                        'weatherIconUrl'][0]['value']
                except Exception as e:
                    pass

            try:
                weather = data['weather'][0]
            except:
                weather = None

            if weather:
                self.data.temp_max_c = weather['tempMaxC']
                self.data.temp_min_c = weather['tempMinC']
                self.data.windspeed_kmph = weather['windspeedKmph']
                self.data.wind_dir_16_point = weather['winddir16Point']

                try:
                    self.data.weather_desc = weather['weatherDesc'][0]['value']
                except Exception as e:
                    pass

                try:
                    self.data.weather_icon_url = weather['weatherIconUrl'][0][
                        'value']
                except Exception as e:
                    pass