From: Emilie Date: Thu, 29 Dec 2016 17:24:23 +0000 (+0100) Subject: [Timesheet] : user dashboard + create form X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1af7db3f8415b087306e11f5f9b6a2ccd6bb81d7;p=mezzo.git [Timesheet] : user dashboard + create form --- diff --git a/app/organization/network/admin.py b/app/organization/network/admin.py index 87ecff89..b815fd91 100644 --- a/app/organization/network/admin.py +++ b/app/organization/network/admin.py @@ -150,7 +150,16 @@ class PersonActivityInline(StackedDynamicInlineAdmin): fk_name = 'person' filter_horizontal = ['organizations', 'employers', 'teams', 'projects', 'supervisors', 'phd_directors', ] - + # fields = () + # + # fields = (('monday_am','monday_pm'), 'weekly_hour_volume') + + # def __init__(self, *args, **kwargs): + # super(PersonActivityInline, self).__init__(*args, **kwargs) + # # print(self.model._meta.get_fields()) + # self.fields = self.model._meta.get_fields() + # print(self.fields) + # # self.fields.append(('monday_am', 'monday_pm')) class PersonPlaylistInline(TabularDynamicInlineAdmin): diff --git a/app/organization/network/forms.py b/app/organization/network/forms.py index db8eef8c..6bdd5043 100644 --- a/app/organization/network/forms.py +++ b/app/organization/network/forms.py @@ -33,7 +33,8 @@ from organization.network.models import (Person, OrganizationLinked, OrganizationLinkedInline, OrganizationLinkedBlockInline, - Organization) + Organization, + PersonActivityTimeSheet) from organization.pages.models import Page, CustomPage @@ -83,3 +84,11 @@ class OrganizationLinkedForm(forms.ModelForm): class Meta: model = OrganizationLinkedInline fields = ('organization',) + + +class PersonActivityTimeSheetForm(forms.ModelForm): + + class Meta: + model = PersonActivityTimeSheet + fields = ('__all__') + # PersonActivityTimeSheetviewfields = ['pub_date', 'headline', 'content', 'reporter'] diff --git a/app/organization/network/urls.py b/app/organization/network/urls.py index a0a5823f..e139349f 100644 --- a/app/organization/network/urls.py +++ b/app/organization/network/urls.py @@ -31,11 +31,12 @@ from mezzanine.conf import settings from organization.network.views import * urlpatterns = [ + url(r'^person/(?P.*)/timesheet/(?P[0-9]{4})/(?P[0-9]{2})/create/$', TimeSheetCreateView.as_view(), name="organization-network-timesheet-create-view"), + url(r'^person/(?P.*)/timesheet/dashboard/$', PersonActivityTimeSheetListView.as_view(), name="organization-network-timesheet-list-view" ), url(r'^person/(?P.*)/$', PersonDetailView.as_view(), name="organization-network-person-detail"), url("^person-list-block-autocomplete/$", permission_required('person.can_edit')(PersonListBlockAutocompleteView.as_view()), name='person-list-block-autocomplete'), url("^person-autocomplete/$", permission_required('person.can_edit')(PersonListView.as_view()), name='person-autocomplete'), url("^network/$", OrganizationListView.as_view(), name='network'), url("^organization-linked-list-autocomplete/$", permission_required('organization.can_edit')(OrganizationLinkedListView.as_view()), name='organization-linked-list-autocomplete'), url("^organization-linked-autocomplete/$", permission_required('organization.can_edit')(OrganizationLinkedView.as_view()), name='organization-linked-autocomplete'), - ] diff --git a/app/organization/network/views.py b/app/organization/network/views.py index 0c6d166b..c91c2947 100644 --- a/app/organization/network/views.py +++ b/app/organization/network/views.py @@ -20,10 +20,12 @@ # along with this program. If not, see . from django.shortcuts import render +from django.views.generic.edit import CreateView from dal import autocomplete from organization.network.models import * from organization.core.views import * - +from datetime import date +from organization.network.forms import * class PersonListView(ListView): @@ -115,3 +117,39 @@ class OrganizationLinkedView(autocomplete.Select2QuerySetView): if self.q: qs = qs.filter(name__istartswith=self.q) return qs + + +class TimeSheetCreateView(CreateView): + model = PersonActivityTimeSheet + template_name='network/person_activity_timesheet/person_activity_timesheet_create.html' + context_object_name = 'timesheet' + form_class = PersonActivityTimeSheetForm + + def get_initial(self): + initial = super(TimeSheetCreateView, self).get_initial() + initial['activity'] = PersonActivity.objects.filter(person__slug=self.kwargs['slug']).first() + initial['month'] = self.kwargs['month'] + initial['year'] = self.kwargs['year'] + return initial + + def get_context_data(self, **kwargs): + context = super(TimeSheetCreateView, self).get_context_data(**kwargs) + context.update(self.kwargs) + return context + + +class PersonActivityTimeSheetListView(ListView): + model = PersonActivityTimeSheet + template_name='network/person_activity_timesheet/person_activity_timesheet_list.html' + context_object_name = 'timesheet' + + def get_queryset(self): + if 'slug' in self.kwargs: + return PersonActivityTimeSheet.objects.filter(activity__person__slug__exact=self.kwargs['slug']) + + def get_context_data(self, **kwargs): + context = super(PersonActivityTimeSheetListView, self).get_context_data(**kwargs) + context['current_month'] = date.today().month + context['current_year'] = date.today().year + context.update(self.kwargs) + return context diff --git a/app/templates/network/person_activity_timesheet/includes/person_activity_timesheet_inline.html b/app/templates/network/person_activity_timesheet/includes/person_activity_timesheet_inline.html new file mode 100644 index 00000000..3cbd38cb --- /dev/null +++ b/app/templates/network/person_activity_timesheet/includes/person_activity_timesheet_inline.html @@ -0,0 +1 @@ +{{ object }} diff --git a/app/templates/network/person_activity_timesheet/person_activity_timesheet_create.html b/app/templates/network/person_activity_timesheet/person_activity_timesheet_create.html new file mode 100644 index 00000000..1b9cd62a --- /dev/null +++ b/app/templates/network/person_activity_timesheet/person_activity_timesheet_create.html @@ -0,0 +1,25 @@ +{% extends "pages/page.html" %} +{% load i18n mezzanine_tags keyword_tags pages_tags organization_tags %} + +{% block meta_title %}{% trans "Timesheet" %}{% endblock %} + +{% block page_class %} + time_sheet +{% endblock %} + +{% block page_title %} +

{% trans "Timesheet" %}

+{% endblock %} + +{% block page_content %} + + Back to dashboard + +
+ {% csrf_token %} + {{ form.as_p }} + +
+ + +{% endblock %} diff --git a/app/templates/network/person_activity_timesheet/person_activity_timesheet_list.html b/app/templates/network/person_activity_timesheet/person_activity_timesheet_list.html new file mode 100644 index 00000000..30a2295a --- /dev/null +++ b/app/templates/network/person_activity_timesheet/person_activity_timesheet_list.html @@ -0,0 +1,30 @@ +{% extends "pages/page.html" %} +{% load i18n mezzanine_tags keyword_tags pages_tags organization_tags %} + +{% block meta_title %}{% trans "Timesheet" %}{% endblock %} + +{% block page_class %} + time_sheet +{% endblock %} + +{% block page_title %} +

{% trans "Timesheet" %}

+{% endblock %} + +{% block page_content %} + + Declare this month + + {% if person_activity_timesheet %} + + {% for pat in person_activity_timesheet %} + {% include "network/person_activity_timesheet/includes/person_activity_timesheet_inline.html" with object=pat %} + {% endfor %} + + {% else %} + +

{% trans "No timesheet." %}

+ + {% endif %} + +{% endblock %}