From 7dd02ede5bfc49f86069529426bccc665c0618de Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Tue, 3 Dec 2019 12:24:43 +0100 Subject: [PATCH] =?UTF-8?q?-=20Bei=20Bereichen=20ein=20ModelMultupleChoice?= =?UTF-8?q?Field=20hinzugef=C3=BCgt,=20damit=20nur=20die=20Benutzer=20eine?= =?UTF-8?q?m=20Bereich=20hinzugef=C3=BCgt=20werden=20k=C3=B6nnen,=20die=20?= =?UTF-8?q?in=20der=20gleichen=20Agentur=20sind,=20wie=20der=20angemeldete?= =?UTF-8?q?=20User.=20Inkl.=20SPeichern=20und=20Update.=20TODO=20Next:=20D?= =?UTF-8?q?ie=20verf=C3=BCgbaren=20Choices=20so=20umbauen,=20dass=20man=20?= =?UTF-8?q?auch=20suchen=20kann.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- areas/forms.py | 15 ++- areas/models.py | 5 +- areas/templates/areas/areas_update.html | 5 +- areas/views.py | 24 ++-- .../__pycache__/settings.cpython-37.pyc | Bin 2916 -> 2936 bytes .../__pycache__/urls.cpython-37.pyc | Bin 1466 -> 1511 bytes digitaleagentur/settings.py | 1 + digitaleagentur/urls.py | 1 + users/static/users/js/demo/chart-area-demo.js | 118 ------------------ users/static/users/js/demo/chart-bar-demo.js | 111 ---------------- users/static/users/js/demo/chart-pie-demo.js | 35 ------ users/static/users/js/demo/datatables-demo.js | 4 - users/templates/users/base.html | 11 +- 13 files changed, 38 insertions(+), 292 deletions(-) delete mode 100644 users/static/users/js/demo/chart-area-demo.js delete mode 100644 users/static/users/js/demo/chart-bar-demo.js delete mode 100644 users/static/users/js/demo/chart-pie-demo.js delete mode 100644 users/static/users/js/demo/datatables-demo.js diff --git a/areas/forms.py b/areas/forms.py index 1646bc3..748b855 100644 --- a/areas/forms.py +++ b/areas/forms.py @@ -6,7 +6,6 @@ from dal import autocomplete from django.contrib.auth.models import User from django import forms - class AreaAddAreaForm(forms.ModelForm): class Meta: @@ -14,9 +13,15 @@ class AreaAddAreaForm(forms.ModelForm): labels = { "name" : "Bereichsname", "color" : "Farbe", - "desc" : "Kurze Beschreibung" - } - fields = ['name', 'color', 'desc'] + "desc" : "Kurze Beschreibung", + "usersfield" : "Zugeteilte Personen" + } + fields = ['name', 'color', 'desc', 'usersfield'] + def __init__(self, user, *args, **kwargs): + super().__init__(*args, **kwargs) - \ No newline at end of file + users_of_agency = User.objects.filter(profile__agency__pk=user.profile.agency.pk) + print(users_of_agency) + print(self.fields['usersfield']) + self.fields['usersfield'].queryset = users_of_agency \ No newline at end of file diff --git a/areas/models.py b/areas/models.py index 8bf8b27..7a52b58 100644 --- a/areas/models.py +++ b/areas/models.py @@ -5,7 +5,6 @@ from colorful.fields import RGBColorField from django.contrib.auth.models import User import datetime - ''' Model Areas @@ -24,9 +23,7 @@ class Areas(models.Model): name = models.CharField(max_length=200, blank=False) color = RGBColorField(colors=['#FFB900', '#E74856', '#0078D7', '#0099BC', '#7A7574'], default='#0099BC', blank=True) desc = models.TextField(max_length=3000, blank=True) - #usersfield = MultiSelectField(choices=(()), blank=True) - #usersfield = forms.ModelMultipleChoiceField(queryset=User.objects.all()) - #usersfield = forms.ModelChoiceField(queryset=User.objects.filter(profile__pk=1)) + usersfield = models.ManyToManyField(User, blank=True, related_name='users_in_area') created_area_by = models.ForeignKey(User, on_delete=models.PROTECT) created_area_date = models.DateField(default=datetime.date.today, blank=True) diff --git a/areas/templates/areas/areas_update.html b/areas/templates/areas/areas_update.html index c7d74ab..0e9c344 100644 --- a/areas/templates/areas/areas_update.html +++ b/areas/templates/areas/areas_update.html @@ -1,12 +1,13 @@ {% extends "users/base.html" %} +{% load static %} {% load crispy_forms_tags %} {% block content %}

Bereich aktualisieren


- {% csrf_token %} - {{ form|crispy }} + {% csrf_token %} + {{ form|crispy }}
  Abbrechen diff --git a/areas/views.py b/areas/views.py index 658fce7..ede32bb 100644 --- a/areas/views.py +++ b/areas/views.py @@ -54,23 +54,31 @@ class AreaDeleteView(LoginRequiredMixin, DeleteView): template_name = 'areas/area_confirm_delete.html' def get_context_data(self, **kwargs): - context = super(AreaDeleteView, self).get_context_data(**kwargs) + context = super(AreaDeleteView, self).get_context_data(**kwargs) context['active_link'] = 'areasmanagement' return context # Hier andere Nutzer ändern, wenn man Usersmanagement darf! class AreaUpdateView(LoginRequiredMixin, UpdateView): model = Areas - form_class= AreaAddAreaForm template_name = 'areas/areas_update.html' success_url = '/areas' + form_class = AreaAddAreaForm - def get_context_data(self, **kwargs): - context = super(AreaUpdateView, self).get_context_data(**kwargs) - context['active_link'] = 'areasmanagement' - return context + #def get_context_data(self, **kwargs): + # context = super(AreaUpdateView, self).get_context_data(**kwargs) + # users_of_agency = User.objects.filter(profile__agency__pk=self.request.user.profile.agency.pk) + # context['possible_users'] = users_of_agency + # context['active_link'] = 'areasmanagement' + # return context def form_valid(self, form): - # Send message to the site + # Send message to the site messages.success(self.request, f'Bereich aktualisiert!') - return super().form_valid(form) \ No newline at end of file + return super().form_valid(form) + + # Form wird geladen; Checkboxen werden vorbereitet und hier rausgerendert. + def get(self,request,*args, **kwargs): + # User ist der hier Aufgerufene, bzw. das Profil! + loggeduser = self.request.user + return render (request, self.template_name, {'form':self.form_class(loggeduser), 'active_link': 'areasmanagement'}) diff --git a/digitaleagentur/__pycache__/settings.cpython-37.pyc b/digitaleagentur/__pycache__/settings.cpython-37.pyc index da62a116fabfa5c0ec926fc8f9fb372e427f3e91..441e829b78aee9c2657e62640df8016e44761776 100644 GIT binary patch delta 282 zcmXwzyGjF57=-sMtA>pyW^>ux@5Xh#n`m4wg$S0C!fsGRoaL}Vv`A`w21%Pjd%HZ6 zmuIl_7;xYl=7)b^KHVSJJCo8jw7R|T>kG#)KK_n>NgYl#!^Df%f2N}(Y^IoIhFQAI zF|QU7X90^WDuWhFEVIHYYs!iQ>k~@}NH&mQlPxZ@%@ulFoyzkIIGd}HRD zkx&+r+=9bxq-Y_n$!N~A+=0to&Fd#LaLRR*Z>5OrN^ u@CZ#Fqeb)5@K2_J7>T4FG`M|Gk2k~cKD--srtfAD6HntWyFHG@uYLhRQ$!R1 delta 263 zcmXwwIZne+7=-<-$0ElDoW@ zlK7O3gQh~28g*i$Q$=H@jgo+-tkI%PhfTU{k<6A-CF}I)+f|S4h3_nUH&sT<273~+ zFIlwYEO|?Tn*)hBlp;q`;#kTPb??4bCd-_>xl-j+YMe=(fyA6kgP}C-t;L138A%8C Y&goyyN9s|{-`(M=dYXQF-D#YWUsWnSp#T5? diff --git a/digitaleagentur/__pycache__/urls.cpython-37.pyc b/digitaleagentur/__pycache__/urls.cpython-37.pyc index ad7acc70f8955b9b0ab9cc354d8dd9de3a4d6228..7839955f0f4a22c9f5dad5846f73af4f7b285e59 100644 GIT binary patch delta 133 zcmdnR{hXWEiIPx# delta 87 zcmaFPy^EXIiI 3) { - s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); - } - if ((s[1] || '').length < prec) { - s[1] = s[1] || ''; - s[1] += new Array(prec - s[1].length + 1).join('0'); - } - return s.join(dec); -} - -// Area Chart Example -var ctx = document.getElementById("myAreaChart"); -var myLineChart = new Chart(ctx, { - type: 'line', - data: { - labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], - datasets: [{ - label: "Earnings", - lineTension: 0.3, - backgroundColor: "rgba(78, 115, 223, 0.05)", - borderColor: "rgba(78, 115, 223, 1)", - pointRadius: 3, - pointBackgroundColor: "rgba(78, 115, 223, 1)", - pointBorderColor: "rgba(78, 115, 223, 1)", - pointHoverRadius: 3, - pointHoverBackgroundColor: "rgba(78, 115, 223, 1)", - pointHoverBorderColor: "rgba(78, 115, 223, 1)", - pointHitRadius: 10, - pointBorderWidth: 2, - data: [0, 10000, 5000, 15000, 10000, 20000, 15000, 25000, 20000, 30000, 25000, 40000], - }], - }, - options: { - maintainAspectRatio: false, - layout: { - padding: { - left: 10, - right: 25, - top: 25, - bottom: 0 - } - }, - scales: { - xAxes: [{ - time: { - unit: 'date' - }, - gridLines: { - display: false, - drawBorder: false - }, - ticks: { - maxTicksLimit: 7 - } - }], - yAxes: [{ - ticks: { - maxTicksLimit: 5, - padding: 10, - // Include a dollar sign in the ticks - callback: function(value, index, values) { - return '$' + number_format(value); - } - }, - gridLines: { - color: "rgb(234, 236, 244)", - zeroLineColor: "rgb(234, 236, 244)", - drawBorder: false, - borderDash: [2], - zeroLineBorderDash: [2] - } - }], - }, - legend: { - display: false - }, - tooltips: { - backgroundColor: "rgb(255,255,255)", - bodyFontColor: "#858796", - titleMarginBottom: 10, - titleFontColor: '#6e707e', - titleFontSize: 14, - borderColor: '#dddfeb', - borderWidth: 1, - xPadding: 15, - yPadding: 15, - displayColors: false, - intersect: false, - mode: 'index', - caretPadding: 10, - callbacks: { - label: function(tooltipItem, chart) { - var datasetLabel = chart.datasets[tooltipItem.datasetIndex].label || ''; - return datasetLabel + ': $' + number_format(tooltipItem.yLabel); - } - } - } - } -}); diff --git a/users/static/users/js/demo/chart-bar-demo.js b/users/static/users/js/demo/chart-bar-demo.js deleted file mode 100644 index 89ec2dd..0000000 --- a/users/static/users/js/demo/chart-bar-demo.js +++ /dev/null @@ -1,111 +0,0 @@ -// Set new default font family and font color to mimic Bootstrap's default styling -Chart.defaults.global.defaultFontFamily = 'Nunito', '-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif'; -Chart.defaults.global.defaultFontColor = '#858796'; - -function number_format(number, decimals, dec_point, thousands_sep) { - // * example: number_format(1234.56, 2, ',', ' '); - // * return: '1 234,56' - number = (number + '').replace(',', '').replace(' ', ''); - var n = !isFinite(+number) ? 0 : +number, - prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), - sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, - dec = (typeof dec_point === 'undefined') ? '.' : dec_point, - s = '', - toFixedFix = function(n, prec) { - var k = Math.pow(10, prec); - return '' + Math.round(n * k) / k; - }; - // Fix for IE parseFloat(0.55).toFixed(0) = 0; - s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); - if (s[0].length > 3) { - s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); - } - if ((s[1] || '').length < prec) { - s[1] = s[1] || ''; - s[1] += new Array(prec - s[1].length + 1).join('0'); - } - return s.join(dec); -} - -// Bar Chart Example -var ctx = document.getElementById("myBarChart"); -var myBarChart = new Chart(ctx, { - type: 'bar', - data: { - labels: ["January", "February", "March", "April", "May", "June"], - datasets: [{ - label: "Revenue", - backgroundColor: "#4e73df", - hoverBackgroundColor: "#2e59d9", - borderColor: "#4e73df", - data: [4215, 5312, 6251, 7841, 9821, 14984], - }], - }, - options: { - maintainAspectRatio: false, - layout: { - padding: { - left: 10, - right: 25, - top: 25, - bottom: 0 - } - }, - scales: { - xAxes: [{ - time: { - unit: 'month' - }, - gridLines: { - display: false, - drawBorder: false - }, - ticks: { - maxTicksLimit: 6 - }, - maxBarThickness: 25, - }], - yAxes: [{ - ticks: { - min: 0, - max: 15000, - maxTicksLimit: 5, - padding: 10, - // Include a dollar sign in the ticks - callback: function(value, index, values) { - return '$' + number_format(value); - } - }, - gridLines: { - color: "rgb(234, 236, 244)", - zeroLineColor: "rgb(234, 236, 244)", - drawBorder: false, - borderDash: [2], - zeroLineBorderDash: [2] - } - }], - }, - legend: { - display: false - }, - tooltips: { - titleMarginBottom: 10, - titleFontColor: '#6e707e', - titleFontSize: 14, - backgroundColor: "rgb(255,255,255)", - bodyFontColor: "#858796", - borderColor: '#dddfeb', - borderWidth: 1, - xPadding: 15, - yPadding: 15, - displayColors: false, - caretPadding: 10, - callbacks: { - label: function(tooltipItem, chart) { - var datasetLabel = chart.datasets[tooltipItem.datasetIndex].label || ''; - return datasetLabel + ': $' + number_format(tooltipItem.yLabel); - } - } - }, - } -}); diff --git a/users/static/users/js/demo/chart-pie-demo.js b/users/static/users/js/demo/chart-pie-demo.js deleted file mode 100644 index c393ac1..0000000 --- a/users/static/users/js/demo/chart-pie-demo.js +++ /dev/null @@ -1,35 +0,0 @@ -// Set new default font family and font color to mimic Bootstrap's default styling -Chart.defaults.global.defaultFontFamily = 'Nunito', '-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif'; -Chart.defaults.global.defaultFontColor = '#858796'; - -// Pie Chart Example -var ctx = document.getElementById("myPieChart"); -var myPieChart = new Chart(ctx, { - type: 'doughnut', - data: { - labels: ["Direct", "Referral", "Social"], - datasets: [{ - data: [55, 30, 15], - backgroundColor: ['#4e73df', '#1cc88a', '#36b9cc'], - hoverBackgroundColor: ['#2e59d9', '#17a673', '#2c9faf'], - hoverBorderColor: "rgba(234, 236, 244, 1)", - }], - }, - options: { - maintainAspectRatio: false, - tooltips: { - backgroundColor: "rgb(255,255,255)", - bodyFontColor: "#858796", - borderColor: '#dddfeb', - borderWidth: 1, - xPadding: 15, - yPadding: 15, - displayColors: false, - caretPadding: 10, - }, - legend: { - display: false - }, - cutoutPercentage: 80, - }, -}); diff --git a/users/static/users/js/demo/datatables-demo.js b/users/static/users/js/demo/datatables-demo.js deleted file mode 100644 index f2eecbf..0000000 --- a/users/static/users/js/demo/datatables-demo.js +++ /dev/null @@ -1,4 +0,0 @@ -// Call the dataTables jQuery plugin -$(document).ready(function() { - $('#dataTable').DataTable(); -}); diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 81ba7d8..7bafcda 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -14,9 +14,10 @@ - + + @@ -249,18 +250,18 @@ - - - + - + + +