| # | |
| # VIEWS | |
| # | |
| class AccountsStatisticsDetail(TemplateView): | |
| template_name = 'grow/accountsstatistics.html' | |
| def get_context_data(self, **kwargs): | |
| context = super().get_context_data(**kwargs) | |
| username = self.kwargs['username'] | |
| if username: | |
| context['username'] = username | |
| context['account_stats'] = ( | |
| AccountsStatistics.objects.filter(username__username=username)) | |
| context['general_info'] = ( | |
| AccountsStatistics.objects.select_related('username') | |
| .filter(username__username=username) | |
| .last()) | |
| return context | |
| class FollowersChartData(APIView): | |
| authentication_classes = [] | |
| permission_classes = [] | |
| def get(self, request, format=None): | |
| # I need to load do this query: | |
| # -> AccountsStatistics.objects.filter(username__username=username)) | |
| # username is undefined at this moment | |
| labels = [ | |
| "28/05", "29/05", "30/05", "31/05", "01/06", | |
| "02/06", "03/06", "04/06", "05/06", "06/06", | |
| "07/06"] | |
| default_items = [2500, 1510, 1527, 1555, 1690, 1750, | |
| 1801, 1870, 1960, 1953, 1930] | |
| data = { | |
| "labels": labels, | |
| "default": default_items, | |
| } | |
| return Response(data) | |
| # | |
| # template | |
| # | |
| <script> | |
| {% block jquery %} | |
| var endpoint = '/api/chart/data' | |
| jQuery.ajax({ | |
| method: "GET", | |
| url: endpoint, | |
| success: function(data) { | |
| labels = data.labels | |
| defaultData = data.default | |
| }, | |
| error: function(error_data) { | |
| console.log("error") | |
| console.log(error_data) | |
| } | |
| }) | |
| {% endblock %} | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment