def accreds_renew(request, pk): """Renew an accreds""" accreds = [get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(','))] multi_obj = len(accreds) > 1 for accred in accreds: if not accred.rights_can('EDIT', request.user): raise Http404 if request.method == 'POST': for accred in accreds: accred.renewal_date = now() accred.save() AccreditationLog(accreditation=accred, who=request.user, type='renewed').save() from notifications.utils import unotify_people unotify_people('Accreds.Warning', accred) if multi_obj: messages.success(request, _(u'Accréditations renouvelées !')) else: messages.success(request, _(u'Accréditation renouvelée !')) return redirect('units.views.accreds_list') return render(request, 'units/accreds/renew.html', {'accreds': accreds, 'multi_obj': multi_obj})
def switch_status_signal(self, request, old_status, dest_status): s = super(_AccountingError, self) if hasattr(s, 'switch_status_signal'): s.switch_status_signal(request, old_status, dest_status) if dest_status == '2_fixed': if request.POST.get('fix_errors'): if self.linked_line and not self.linked_line.deleted and self.linked_line.status == '2_error': from accounting_main.models import AccountingLineLogging old_status = self.linked_line.status self.linked_line.status = '1_validated' self.linked_line.save() AccountingLineLogging(who=request.user, what='state_changed', object=self.linked_line, extra_data=json.dumps({'old': unicode(self.linked_line.MetaState.states.get(old_status)), 'new': unicode(self.linked_line.MetaState.states.get('1_validated'))})).save() unotify_people(u'AccountingLine.{}.error'.format(self.costcenter.unit), self.linked_line) notify_people(request, u'AccountingLine.{}.fixed'.format(self.costcenter.unit), 'accounting_line_fixed', self.linked_line, self.linked_line.build_group_members_for_compta_everyone()) unotify_people(u'AccountingError.{}.created'.format(self.costcenter.unit), self) notify_people(request, u'AccountingError.{}.fixed'.format(self.costcenter.unit), 'accounting_error_fixed', self, self.build_group_members_for_compta_everyone_with_messages())
def accreds_validate(request, pk): """Validate an accred""" accreds = [get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(','))] multi_obj = len(accreds) > 1 for accred in accreds: if not accred.rights_can('VALIDATE', request.user): raise Http404 if request.method == 'POST': for accred in accreds: accred.need_validation = False accred.save() accred.user.clear_rights_cache() AccreditationLog(accreditation=accred, who=request.user, type='validated').save() from notifications.utils import notify_people, unotify_people dest_users = accred.unit.users_with_access('ACCREDITATION', no_parent=True) notify_people(request, 'Accreds.Validated', 'accreds_validated', accred, dest_users) unotify_people('Accreds.ToValidate', accred) if multi_obj: messages.success(request, _(u'Accréditations validées !')) else: messages.success(request, _(u'Accréditation validée !')) return redirect('units.views.accreds_list') return render(request, 'units/accreds/validate.html', {'accreds': accreds, 'multi_obj': multi_obj})
def accreds_validate(request, pk): """Validate an accred""" accreds = [get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(','))] multi_obj = len(accreds) > 1 for accred in accreds: if not accred.rights_can('VALIDATE', request.user): raise Http404 if request.method == 'POST': for accred in accreds: accred.need_validation = False accred.save() accred.user.clear_rights_cache() AccreditationLog(accreditation=accred, who=request.user, type='validated').save() from notifications.utils import notify_people, unotify_people dest_users = accred.unit.users_with_access('ACCREDITATION', no_parent=True) notify_people(request, 'Accreds.Validated', 'accreds_validated', accred, dest_users) unotify_people('Accreds.ToValidate', accred) if multi_obj: messages.success(request, _(u'Accréditations validées !')) else: messages.success(request, _(u'Accréditation validée !')) return redirect('units-views-accreds_list') return render(request, 'units/accreds/validate.html', {'accreds': accreds, 'multi_obj': multi_obj})
def accreds_renew(request, pk): """Renew an accreds""" accreds = [get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(','))] multi_obj = len(accreds) > 1 for accred in accreds: if not accred.rights_can('EDIT', request.user): raise Http404 if request.method == 'POST': for accred in accreds: accred.renewal_date = now() accred.save() AccreditationLog(accreditation=accred, who=request.user, type='renewed').save() from notifications.utils import unotify_people unotify_people('Accreds.Warning', accred) if multi_obj: messages.success(request, _(u'Accréditations renouvelées !')) else: messages.success(request, _(u'Accréditation renouvelée !')) return redirect('units-views-accreds_list') return render(request, 'units/accreds/renew.html', {'accreds': accreds, 'multi_obj': multi_obj})
def switch_status_signal(self, request, old_status, dest_status): s = super(_AccountingError, self) if hasattr(s, 'switch_status_signal'): s.switch_status_signal(request, old_status, dest_status) if dest_status == '2_fixed': if request.POST.get('fix_errors'): if self.linked_line and not self.linked_line.deleted and self.linked_line.status == '2_error': from accounting_main.models import AccountingLineLogging old_status = self.linked_line.status self.linked_line.status = '1_validated' self.linked_line.save() AccountingLineLogging(who=request.user, what='state_changed', object=self.linked_line, extra_data=json.dumps({'old': str(self.linked_line.MetaState.states.get(old_status)), 'new': str(self.linked_line.MetaState.states.get('1_validated'))})).save() unotify_people(u'AccountingLine.{}.error'.format(self.costcenter.unit), self.linked_line) notify_people(request, u'AccountingLine.{}.fixed'.format(self.costcenter.unit), 'accounting_line_fixed', self.linked_line, self.linked_line.build_group_members_for_compta_everyone()) unotify_people(u'AccountingError.{}.created'.format(self.costcenter.unit), self) notify_people(request, u'AccountingError.{}.fixed'.format(self.costcenter.unit), 'accounting_error_fixed', self, self.build_group_members_for_compta_everyone_with_messages())
def accreds_delete(request, pk): """Delete an accred""" accreds = [ get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(',')) ] multi_obj = len(accreds) > 1 cannot_last_prez = False cannot_last_prez_accred = None for accred in accreds: if not accred.rights_can('DELETE', request.user): raise Http404 if accred.role.pk == settings.PRESIDENT_ROLE_PK and not accred.rights_can( 'INGORE_PREZ', request.user) and accred.unit.accreditation_set.filter( role__pk=settings.PRESIDENT_ROLE_PK, end_date=None).count() <= 1: cannot_last_prez = True cannot_last_prez_accred = accred if not cannot_last_prez and request.method == 'POST': for accred in accreds: accred.end_date = now() accred.save() from notifications.utils import unotify_people unotify_people('Accreds.ToValidate', accred) AccreditationLog(accreditation=accred, who=request.user, type='deleted').save() accred.user.clear_rights_cache() if multi_obj: messages.success(request, _(u'Accréditations supprimées !')) else: messages.success(request, _(u'Accréditation supprimée !')) return redirect('units-views-accreds_list') return render( request, 'units/accreds/delete.html', { 'accreds': accreds, 'cannot_last_prez': cannot_last_prez, 'multi_obj': multi_obj, 'cannot_last_prez_accred': cannot_last_prez_accred })
def accreds_delete(request, pk): """Delete an accred""" accreds = [get_object_or_404(Accreditation, pk=pk_, end_date=None) for pk_ in filter(lambda x: x, pk.split(','))] multi_obj = len(accreds) > 1 cannot_last_prez = False cannot_last_prez_accred = None for accred in accreds: if not accred.rights_can('DELETE', request.user): raise Http404 if accred.role.pk == settings.PRESIDENT_ROLE_PK and not accred.rights_can('INGORE_PREZ', request.user) and accred.unit.accreditation_set.filter(role__pk=settings.PRESIDENT_ROLE_PK, end_date=None).count() <= 1: cannot_last_prez = True cannot_last_prez_accred = accred if not cannot_last_prez and request.method == 'POST': for accred in accreds: accred.end_date = now() accred.save() from notifications.utils import unotify_people unotify_people('Accreds.ToValidate', accred) AccreditationLog(accreditation=accred, who=request.user, type='deleted').save() accred.user.clear_rights_cache() if multi_obj: messages.success(request, _(u'Accréditations supprimées !')) else: messages.success(request, _(u'Accréditation supprimée !')) return redirect('units.views.accreds_list') return render(request, 'units/accreds/delete.html', {'accreds': accreds, 'cannot_last_prez': cannot_last_prez, 'multi_obj': multi_obj, 'cannot_last_prez_accred': cannot_last_prez_accred})
def switch_status_signal(self, request, old_status, dest_status): from accounting_main.models import AccountingError, AccountingErrorLogging s = super(_AccountingLine, self) if hasattr(s, 'switch_status_signal'): s.switch_status_signal(request, old_status, dest_status) if dest_status == '2_error': if request.POST.get('error'): ae = AccountingError(initial_remark=request.POST.get('error'), linked_line=self, accounting_year=self.accounting_year, costcenter=self.costcenter) ae.save() AccountingErrorLogging(who=request.user, what='created', object=ae).save() notify_people(request, u'AccountingError.{}.created'.format(self.costcenter.unit), 'accounting_error_created', ae, ae.build_group_members_for_compta_everyone_with_messages()) unotify_people(u'AccountingLine.{}.fixed'.format(self.costcenter.unit), self) notify_people(request, u'AccountingLine.{}.error'.format(self.costcenter.unit), 'accounting_line_error', self, self.build_group_members_for_compta_everyone()) if dest_status == '1_validated': if old_status == '2_error': unotify_people(u'AccountingLine.{}.error'.format(self.costcenter.unit), self) notify_people(request, u'AccountingLine.{}.fixed'.format(self.costcenter.unit), 'accounting_line_fixed', self, self.build_group_members_for_compta_everyone()) if request.POST.get('fix_errors'): for error in self.accountingerror_set.filter(deleted=False).exclude(status='2_fixed'): old_status = error.status error.status = '2_fixed' error.save() AccountingErrorLogging(who=request.user, what='state_changed', object=error, extra_data=json.dumps({'old': unicode(error.MetaState.states.get(old_status)), 'new': unicode(error.MetaState.states.get('2_fixed'))})).save() unotify_people(u'AccountingError.{}.created'.format(self.costcenter.unit), error) notify_people(request, u'AccountingError.{}.fixed'.format(self.costcenter.unit), 'accounting_error_fixed', error, error.build_group_members_for_compta_everyone_with_messages())
def switch_status_signal(self, request, old_status, dest_status): from accounting_main.models import AccountingError, AccountingErrorLogging s = super(_AccountingLine, self) if hasattr(s, 'switch_status_signal'): s.switch_status_signal(request, old_status, dest_status) if dest_status == '2_error': if request.POST.get('error'): ae = AccountingError(initial_remark=request.POST.get('error'), linked_line=self, accounting_year=self.accounting_year, costcenter=self.costcenter) ae.save() AccountingErrorLogging(who=request.user, what='created', object=ae).save() notify_people(request, u'AccountingError.{}.created'.format(self.costcenter.unit), 'accounting_error_created', ae, ae.build_group_members_for_compta_everyone_with_messages()) unotify_people(u'AccountingLine.{}.fixed'.format(self.costcenter.unit), self) notify_people(request, u'AccountingLine.{}.error'.format(self.costcenter.unit), 'accounting_line_error', self, self.build_group_members_for_compta_everyone()) if dest_status == '1_validated': if old_status == '2_error': unotify_people(u'AccountingLine.{}.error'.format(self.costcenter.unit), self) notify_people(request, u'AccountingLine.{}.fixed'.format(self.costcenter.unit), 'accounting_line_fixed', self, self.build_group_members_for_compta_everyone()) if request.POST.get('fix_errors'): for error in self.accountingerror_set.filter(deleted=False).exclude(status='2_fixed'): old_status = error.status error.status = '2_fixed' error.save() AccountingErrorLogging(who=request.user, what='state_changed', object=error, extra_data=json.dumps({'old': str(error.MetaState.states.get(old_status)), 'new': str(error.MetaState.states.get('2_fixed'))})).save() unotify_people(u'AccountingError.{}.created'.format(self.costcenter.unit), error) notify_people(request, u'AccountingError.{}.fixed'.format(self.costcenter.unit), 'accounting_error_fixed', error, error.build_group_members_for_compta_everyone_with_messages())