Пример #1
0
 def action_timestamps_days_pdf(self, request, queryset):
     context = self.get_timestamps_days(request, queryset)
     # Add report preferences from AdminOptions
     context.update(get_admin_options(self.__class__.__name__,
                                      sys._getframe().f_code.co_name))
     # Save locale and restore it after getting the days names
     old_locale = locale.getlocale(locale.LC_TIME)
     if context.get('locale'):
         # Format days headers
         locale.setlocale(locale.LC_TIME, context['locale'])
     context['days'] = [date.strftime('%a') for date in context['dates']]
     locale.setlocale(locale.LC_TIME, old_locale)
     # Split visible_columns in multiple values
     visible_columns = context['visible_columns']
     context['visible_columns'] = (
         [column.strip() for column in visible_columns.split(',')]
         if visible_columns else None)
     # Format dates
     if context.get('format_date'):
         context['dates'] = [date.strftime(context['format_date'])
                             for date in context['dates']]
     response = xhtml2pdf_render_from_template_response(
         response=TemplateResponse(request,
                                   'work/timestamps_days/pdf.html',
                                   context),
         filename='')
     return response
Пример #2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if 'description' not in context:
            context['description'] = ''

        activity_date = (datetime.datetime.fromtimestamp(
            int(context['datetime'])).replace(hour=0,
                                              minute=0,
                                              second=0,
                                              microsecond=0))
        activity_query = Activity.objects.filter(
            contract_id=int(context['contract_id']),
            date=activity_date)
        if activity_query:
            # Look for existing activity
            activity = activity_query[0]
        else:
            # No existing activity, create a new one
            activity = Activity.objects.create(
                contract_id=int(context['contract_id']),
                date=activity_date)
        # Add Activity extra to activity
        context.update(get_admin_options(self.__class__.__name__,
                                         sys._getframe().f_code.co_name))
        # Get the already used rooms for extras
        extra_used_rooms = [room[0]
                            for room
                            in ActivityRoom.objects.filter(
                                activity_id=activity.pk,
                                service_id=int(context['extras_service_id']),
                                room__building__extras=True)
                            .values_list('room')]
        # Get the all the existing rooms for extras
        extra_rooms = [room[0]
                       for room
                       in Room.objects.filter(
                           building__structure_id=context['structure_id'],
                           building__extras=True)
                       .order_by('name')
                       .values_list('id')]
        # Get the free rooms for extras
        extra_free_rooms = list(set(extra_rooms) - set(extra_used_rooms))
        if extra_free_rooms:
            # Assign the ActivityRoom to the first available extra room
            activity = ActivityRoom.objects.create(
                activity_id=activity.pk,
                room_id=extra_free_rooms[0],
                service_id=int(context['extras_service_id']),
                service_qty=int(context['service_qty']),
                description=urllib.parse.unquote_plus(
                    context['description'].replace('\\n', '\n')))
            # Add closing status (to check for transmission errors)
            self.add_status(context)
        else:
            # No available extra rooms to work with
            context['status'] = 'NO ROOMS'
        # Return timestamp id
        context['activity_id'] = activity.pk
        return context
Пример #3
0
 def action_timestamps_hours_csv(self, request, queryset):
     # Export data to CSV format
     context = self.get_timestamps_hours(request, queryset)
     # Add report preferences from AdminOptions
     context.update(get_admin_options(self.__class__.__name__,
                                      sys._getframe().f_code.co_name))
     return self.do_export_data_to_csv(
         data=context['results'],
         fields_map=TimestampHoursExport.fields_map,
         filename='timestamps_hours')
Пример #4
0
 def action_daily_activities_html(self, request, queryset):
     context = self.get_daily_activities(request, queryset)
     # Add report preferences from AdminOptions
     context.update(
         get_admin_options(self.__class__.__name__,
                           sys._getframe().f_code.co_name))
     response = TemplateResponse(request,
                                 'work/activities_daily/admin.html',
                                 context)
     return response
Пример #5
0
 def action_timestamps_hours_html(self, request, queryset):
     context = self.get_timestamps_hours(request, queryset)
     # Add report preferences from AdminOptions
     context.update(get_admin_options(self.__class__.__name__,
                                      sys._getframe().f_code.co_name))
     # Split visible_columns in multiple values
     visible_columns = context['visible_columns']
     context['visible_columns'] = (
         [column.strip() for column in visible_columns.split(',')]
         if visible_columns else None)
     response = TemplateResponse(request,
                                 'work/timestamps_hours/admin.html',
                                 context)
     return response
Пример #6
0
 def action_timestamps_days_csv(self, request, queryset):
     # Export data to CSV format
     context = self.get_timestamps_days(request, queryset)
     # Add report preferences from AdminOptions
     context.update(get_admin_options(self.__class__.__name__,
                                      sys._getframe().f_code.co_name))
     return self.do_export_data_to_csv(
         data=context['results'],
         fields_map=dict(
             **TimestampDaysExport.fields_map,
             **dict([(datetime.date.fromordinal(day).strftime(
                     # Format dates headers
                     context.get('format_date', '%F')), day)
                     for day in context['ordinals']])),
         filename='timestamps_days')
Пример #7
0
 def action_monthly_activities_html(self, request, queryset):
     context = self.get_monthly_activities(request, queryset)
     # Add report preferences from AdminOptions
     context.update(
         get_admin_options(self.__class__.__name__,
                           sys._getframe().f_code.co_name))
     # Format dates
     if context.get('format_date'):
         context['dates'] = dict([
             (key, date.strftime(context['format_date']))
             for key, date in context['dates'].items()
         ])
     response = TemplateResponse(request,
                                 'work/activities_monthly/admin.html',
                                 context)
     return response
Пример #8
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     # Add report preferences from AdminOptions
     context.update(get_admin_options(self.__class__.__name__,
                                      sys._getframe().f_code.co_name))
     # Split visible_columns in multiple values
     visible_columns = context['visible_columns']
     context['visible_columns'] = (
         [column.strip() for column in visible_columns.split(',')]
         if visible_columns else None)
     if self.request.user.is_authenticated:
         obj_login = Login.objects.get(username=self.request.user)
         context['page_title'] = (pgettext_lazy(
             'TimeStampLoginView',
             'Welcome {EMPLOYEE}').format(
             EMPLOYEE=obj_login.contract.employee), )
         context['last_logins'] = Timestamp.objects.filter(
             contract=obj_login.contract).order_by(
             '-date', '-time')[:int(context['last_logins_count'])]
     else:
         context['page_title'] = (pgettext_lazy(
             'TimeStampLoginView',
             'Login to register your presence'), )
     return context