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 da62a11..441e829 100644 Binary files a/digitaleagentur/__pycache__/settings.cpython-37.pyc and b/digitaleagentur/__pycache__/settings.cpython-37.pyc differ diff --git a/digitaleagentur/__pycache__/urls.cpython-37.pyc b/digitaleagentur/__pycache__/urls.cpython-37.pyc index ad7acc7..7839955 100644 Binary files a/digitaleagentur/__pycache__/urls.cpython-37.pyc and b/digitaleagentur/__pycache__/urls.cpython-37.pyc differ diff --git a/digitaleagentur/settings.py b/digitaleagentur/settings.py index 41116c1..8891e52 100644 --- a/digitaleagentur/settings.py +++ b/digitaleagentur/settings.py @@ -32,6 +32,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'django_select2', 'users.apps.UsersConfig', 'areas.apps.AreasConfig', 'tasks.apps.TasksConfig', diff --git a/digitaleagentur/urls.py b/digitaleagentur/urls.py index c202d41..5877f62 100644 --- a/digitaleagentur/urls.py +++ b/digitaleagentur/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ path('password-reset-complete/', auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), name='password_reset_complete'), path('register/', AgencyCreateView.as_view(template_name='users/register.html'), name='register'), path('register/done', views.registerdone, name='register-done'), + path('select2/', include('django_select2.urls')), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/users/static/users/js/demo/chart-area-demo.js b/users/static/users/js/demo/chart-area-demo.js deleted file mode 100644 index 0bb9c4d..0000000 --- a/users/static/users/js/demo/chart-area-demo.js +++ /dev/null @@ -1,118 +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); -} - -// 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 @@ - - - + - + + +