Esempio n. 1
0
 def get_schedule(self, year=None, month=None, day=None):
     """
     Pobiera z IWM liste powiadomień z danego miesiąca.
     """
     params = {}
     if year is not None:
         if month is not None:
             if day is not None:
                 params['from'] = '%d-%02d-%02dT00:00:00' % (year, month, day)
                 params['to'] = '%d-%02d-%02dT23:59:59' % (year, month, day)
             else:
                 params['from'] = '%d-%02d-01T00:00:00' % (year, month)
                 params['to'] = '%d-%02d-31T23:59:59' % (year, month)
         else:
             params['from'] = '%d-01-01T00:00:00' % year
             params['to'] = '%d-12-31T00:00:00' % year
     params['operator'] = get_loggedin_user_id()
     #params['author'] = get_loggedin_user_id()
     try:
         data = iwm_call(notification_list_inmapping, params,
                     notification_list_outmapping)
     except IWMResponseError:
         redirect_to('/calendar/app/handle_error')
     schedule = defaultdict(list)
     for note in data:
         date = note['date']
         schedule[(date.year, date.month,
                   date.day)].append(((date.hour, date.minute), note))
     return schedule
Esempio n. 2
0
    def get_notes_alert(self):
        """
        Displays alert with current notes.
        """
        # sekunda dodana na wypadek dluzszej obslugi requestu (ryzyko podwojnego wyswietlenia okna)
        delta = datetime.timedelta(seconds = 1 + int(config.get('notification_interval', 300)))
        unregister = {"type" : "timer-unregister", "result" : {"name": "notifications_alert"}}

        try:
            from_dt = session['alert_from_dt']
        except KeyError:
            from_dt = datetime.datetime.now() - delta

        to_dt = datetime.datetime.now()

        params = {}
        params['from'] = from_dt.isoformat()
        params['to'] = to_dt.isoformat()
        params['recipient-type'] = 'OPERATOR'
        params['operator'] = get_loggedin_user_id()

        try:
            data = iwm_call(notification_list_inmapping, params,
                        notification_list_outmapping)
        except:
            return [unregister,
                    {
                        'type': 'window',
                        'result': {
                            'heading': u'Wystąpił błąd aplikacji',
                            'html': u'<pre>Wystąpił błąd podczas próby pobrania przypomnień.\n'
                            u'Pobieranie przypomnień zostało wyłączone.</pre>',
                            'width': 480,
                            'height': 320,
                            'scrollable': True,
                            'slotname': 'common-error-window',
                            'replace': True
                            }
                        }
                    ]

        output = []
        you = get_loggedin_user_id()
        for note in data:
            date = note['date']
            operator = note['operator']

            if from_dt < date <= to_dt and operator == you:
                note_json = self._get_alert_window()
                note_json['slotname'] = note_json['slotname'] % (note['id'])
                note_json['object']['result']['content'] = '<p><b>%s</b></p><p>%s</p>' % (
                                       date.strftime('%Y-%m-%d %H:%M:%S'), note['text'])

                output.append(
                              {
                               'type' : 'window',
                               'result': note_json
                               }
                              )

        session['alert_from_dt'] = to_dt
        session.save()
        return output
Esempio n. 3
0
 def add_note(self):
     """
     Display the new note form.
     """
     
     date_error = request.params.get('date_error') and u'Nie można wybrać przeszłej daty' or []
     time_error = request.params.get('time_error') and u'Nie mozna wybrać przeszłej godziny' or []
     time = request.params.get('time', (datetime.datetime.now() + datetime.timedelta(hours=1)).strftime('%H:%M'))
     text = request.params.get('text', '')
     year, month, day = self.get_year_month_day()
     application = request.params.get('application', '')
     if application:
         recipient_field = {
             'widget': 'char',
             'name': 'task-short-id',
             'label': u'Wniosek',
             'value': application,
             'readonly': True,
         }
     else:
         operators = _get_consultants()
         recipient = get_loggedin_user_id()
         for operator in operators:
             if operator['value'] == recipient:
                 operator['selected'] = True
             else:
                 operator['selected'] = False
         recipient_field = {
             'widget': 'choice',
             'name': 'operator',
             'label': 'Adresat',
             'value': operators,
         }
     result = {
         'heading': u'Nowe przypomnienie',
         'width': 305,
         'height': 324,
         'slotname': 'calendar-add',
         'replace': True,
         'object': {
             'type': 'form',
             'result': {
                 'buttons': [
                     {
                         'label': u'Dodaj',
                         'link': {
                             'url': '/calendar/app/really_add_note',
                             'slot': 'internal',
                         },
                         'hide_window_onselect': True,
                     },
                     {
                         'label': u'Rezygnuj',
                         'link': {
                             'url': '/calendar/app/cancel',
                             'slot': 'internal',
                             'validation': False,
                         },
                         'hide_window_onselect': True,
                     }
                 ],
                 'formdefs': [
                     recipient_field,
                     {
                         'widget': 'datepicker',
                         'name': 'date',
                         'label': 'Data',
                         'value': '%d-%d-%d' % (day, month, year),
                         'error': date_error,
                     },
                     {
                         'widget': 'char',
                         'name': 'time',
                         'label': 'Godzina',
                         'value': time,
                         'validator': {
                             'type': 'regexp',
                             'value': r'[012]?\d:[012345]?\d',
                             'error_message': u'Błędna godzina',
                         },
                         'error': time_error
                     },
                     {
                         'widget': 'textarea',
                         'name': 'text',
                         'label': 'Treść powiadomienia',
                         'value': text,
                         'width': 255,
                         'height': 150,
                         'hidelabel': True,
                         'required': True,
                     },
                 ],
             },
         },
     }
     return result
Esempio n. 4
0
    def calendar_notes(self):
        my_id = get_loggedin_user_id()
        year, month, day = self.get_year_month_day()
        schedule = self.get_schedule(year, month, day)
        data = []
        for time, note in schedule[(year, month, day)]:
            html = u''
            author_id = note['author'].get('id', '')
            recipient_id = note.get('operator', '')
            application_id = note.get('application', '')
            if my_id not in (author_id, recipient_id):
                continue
            author_name = u' '.join(x for x in [
                note['author'].get('first-name', ''),
                note['author'].get('last-name', ''),
            ] if x) or note['author'].get('id', '')
            if author_name and author_id != my_id:
                html += '<b class="author">%s</b><br/>' % cgi.escape(author_name)
            if application_id:
                html += 'Wniosek: <i class="application">%s</i><br/>' % cgi.escape(application_id)
                url = '/wnioski/formz/application_proxy?task-short-id=%s' % application_id
                style = 'calendar-note-row'
            else:
                url = None
                style = 'calendar-note-row-nolink'
            if recipient_id != my_id:
                if style == 'calendar-note-row':
                    style = 'calendar-note-row-own-link'
                else:
                    style = 'calendar-note-row-own'
                html += '<b class="recipient">%s</b><br/>' % cgi.escape(note.get('operator', ''))
            html += u'<div class="calendar-note-text">%s</div>' % cgi.escape(note['text'])
            data.append({
                'icon': {
                    'icon': 'icon-note_delete',
                    'url': '/calendar/app/delete_note?id=%s' % note['id'],
                    'slot': 'internal',
                },
                'time': '%02d:%02d' % time,
                'desc': html,
                '__params__': {
                    'uid': note['id'],
                    'style': style,
                },
            })
            if url:
                data[-1]['__params__']['link'] = {
                    'url': url,
                    'slot': 'internal',
                }
        if datetime.date(year=year, month=month, day=day)>=datetime.date.today():
            data.append({
                'icon': {
                    'icon': 'icon-add',
                    'slot': 'internal',
                    'url': '/calendar/app/add_note?year=%d&month=%d&day=%d' % (year, month, day),
                },
                'time': '',
                'desc': u'Dodaj przypomnienie',
                '__params__': {
                    'slot': 'internal',
                    'url': '/calendar/app/add_note?year=%d&month=%d&day=%d' % (year, month, day),
                }
            })
        result = {
            "autoexpand_column": "desc",
            "columns": [
                {
                    'id': 'time',
                    'title': u'Czas',
                    'width': '40',
#                    'renderer': 'text',
                    'fixed': 'true',
                },
                {
                    'id': 'desc',
                    'title': u'Opis',
                    'width': '0',
#                    'renderer': 'text',
                },
                {
                    'id': 'icon',
                    'title': '',
                    'width': '24',
                    'renderer': 'icon',
                    'fixed': 'true',
                },
            ],
            "groups": [
                {
                    'rowspan': 1,
                    'colspan': 3,
                    'title': '<b>%d %s %d</b>' % (day, MONTHS[month].title(), year),
                    'row': 0,
                    'column': 0,
                }
            ],
            "data": data,
        }
        return result