Exemplo n.º 1
0
def edit_notice(request, notice_id):
    conversations = Conversation.objects.all().filter(
        receiver=request.user).order_by('-lastMessageTime')
    newMessages = 0
    for conversation in conversations:
        if conversation.is_read == False:
            newMessages += 1
    notice = get_object_or_404(Notice, pk=notice_id)
    start_date = jdatetime.GregorianToJalali(
        gmonth=notice.initiation_date.month,
        gyear=notice.initiation_date.year,
        gday=notice.initiation_date.day).getJalaliList()
    end_date = jdatetime.GregorianToJalali(
        gmonth=notice.expiration_date.month,
        gyear=notice.expiration_date.year,
        gday=notice.expiration_date.day).getJalaliList()
    if request.method == 'GET':
        form = NoticeForm(instance=notice,
                          initial={
                              'start_date': gdate_to_str(start_date),
                              'end_date': gdate_to_str(end_date),
                              'attachment': None
                          })
        return render(request, 'manager/manager-dashboard-notices-edit.html', {
            'new_messages': newMessages,
            'form': form,
            'notice': notice,
        })
    else:
        form = NoticeForm(request.POST, request.FILES)
        if form.is_valid():
            notice.title = form.cleaned_data['title']
            notice.notice_text = form.cleaned_data['notice_text']
            notice.initiation_date = jdate_to_date(
                form.cleaned_data['start_date'])
            notice.expiration_date = jdate_to_date(
                form.cleaned_data['end_date'])

            clear_attachment = request.POST.get('clear_attachment', None)

            if clear_attachment:
                if request.POST['clear_attachment']:
                    notice.attachment = None

            notice.attachment = form.cleaned_data['attachment']
            notice.save()

            return HttpResponseRedirect('/manager/notices/')
        else:
            return render(request,
                          'manager/manager-dashboard-notices-edit.html', {
                              'new_messages': newMessages,
                              'form': form,
                              'notice': notice,
                          })
Exemplo n.º 2
0
    def test_start_notif_post(self):

        User.objects.create_user(email='*****@*****.**', password='******', is_doctor=False,
                                 name='Test_user',
                                 family_name='Test_family_user')

        self.client.login(email='*****@*****.**', password='******')
        med = self.set_up()
        from datetime import datetime, timedelta
        time = datetime.now() + timedelta(minutes=1)
        time_str = str(time)[11:16]

        date = localtime(now()).date()
        jdate = jdatetime.GregorianToJalali(date.year, date.month, date.day)
        jdate_str = str(jdate.jyear) + '-' + "%02d" % jdate.jmonth + '-' + "%02d" % jdate.jday
        data = {'med-starting_hour': time_str, 'med-starting_time': jdate_str}
        response = self.client.post(reverse('medicine_page:start_notif', args=(med.id, '0',)),
                                    data=data, follow=True)

        self.assertRedirects(response, reverse('medicine_page:medicines'))
        self.assertEqual(str(Medicine.objects.filter(id=med.id).get().starting_hour)[:5], time_str)
        self.assertEqual(Medicine.objects.filter(id=med.id).get().status, True)

        self.assertEqual(Medicine.objects.filter(id=med.id).get().starting_time,
                         jdatetime.date(jdate.jyear, jdate.jmonth, jdate.jday))
Exemplo n.º 3
0
def to_jorjean(miladi_date):
    date_time = miladi_date.split(' ')
    result_date = date_time[0].split('-')
    result_date = jdatetime.GregorianToJalali(int(result_date[0]),
                                              int(result_date[1]),
                                              int(result_date[2]))
    result_date = str(result_date.jyear) + "-" + add_zero(
        str(result_date.jmonth)) + "-" + add_zero(str(result_date.jday))
    return result_date + "T" + date_time[1][0:8]
Exemplo n.º 4
0
def gregorian_to_jalali(_date, format_split='-'):
    """
        Convert Gregorian date to Jalali date into Template
    """
    if format_split == '-':
        text_date = "{0:04d}-{1:02d}-{2:02d}"

    elif format_split == '/':
        text_date = "{0:04d}/{1:02d}/{2:02d}"

    if isinstance(_date, str):
        _date = _date.strip()

        if len(_date) <= 11:
            _date = parser.parse(_date).date()

        else:
            _date = parser.parse(_date)

    if isinstance(_date, unicode):
        _date = str(_date).strip()

        if len(_date) <= 11:
            _date = parser.parse(_date).date()

        else:
            _date = parser.parse(_date)

    if isinstance(_date, datetime.datetime):
        with_time = True

    elif isinstance(_date, datetime.date):
        with_time = False

    year = _date.year
    month = _date.month
    day = _date.day
    date = jdatetime.GregorianToJalali(year, month, day)

    if with_time:
        _datetime = text_date.format(date.jyear, date.jmonth, date.jday)
        _datetime += ' {0:02d}:{1:02d}:{2:02d}'.format(_date.hour,
                                                       _date.minute,
                                                       _date.second)

        return _datetime

    else:
        _date = text_date.format(date.jyear, date.jmonth, date.jday)

        return _date
Exemplo n.º 5
0
 def __get_persian_date__(self):
     year, month, day = self.date
     year = int(year)
     month = int(month)
     day = int(day)
     jd = jdatetime.GregorianToJalali(year, month, day)
     year = str(jd.jyear)
     month = str(jd.jmonth)
     day = str(jd.jday)
     self.jdate = [jd.jyear, jd.jmonth, jd.jday]
     month_dict = {
         1: u'فروردین',
         2: u'اردیبهشت',
         3: u'خرداد',
         4: u'تیر',
         5: u'مرداد',
         6: u'شهریور',
         7: u'مهر',
         8: u'آبان',
         9: u'آذر',
         10: u'دی',
         11: u'بهمن',
         12: u'اسفند',
     }
     day_dict = {
         0: u'یکشنبه',
         1: u'دوشنبه',
         2: u'سه شنبه',
         3: u'چهارشنبه',
         4: u'پنجشنبه',
         5: u'جمعه',
         6: u'شنبه',
         7: u'یکشنبه'
     }
     dic = u'۰۱۲۳۴۵۶۷۸۹'
     y = ''.join([dic[int(i)] for i in year])
     d = ''.join([dic[int(i)] for i in day])
     self.persian_date = day_dict[
         self.num_day] + u'\n' + d + u' ' + month_dict[int(
             month)] + u' ' + y
     ph, pm, ps = self.time
     self.persian_time = u''.join(
         [dic[int(i)] for i in ph]) + self.clockwork + u''.join([
             dic[int(i)] for i in pm
         ]) + self.clockwork + u''.join([dic[int(i)] for i in ps])
Exemplo n.º 6
0
    def test_start_notif_failure_post(self):
        User.objects.create_user(email='*****@*****.**', password='******', is_doctor=False,
                                 name='Test_user',
                                 family_name='Test_family_user')

        self.client.login(email='*****@*****.**', password='******')
        med = self.set_up()
        from datetime import datetime, timedelta
        time = datetime.now() - timedelta(minutes=1)
        time_str = str(time)[11:16]

        date = localtime(now()).date()
        jdate = jdatetime.GregorianToJalali(date.year, date.month, date.day)
        jdate_str = str(jdate.jyear) + '-' + "%02d" % jdate.jmonth + '-' + "%02d" % jdate.jday
        data = {'med-starting_hour': time_str, 'med-starting_time': jdate_str}
        response = self.client.post(reverse('medicine_page:start_notif', args=(med.id, '0',)),
                                    data=data, follow=True)
        self.assertEqual(response.status_code, 200)
        for med, form in response.context['meds']:
            self.assertTrue('med-starting_hour' in form.errors[0])
Exemplo n.º 7
0
    def test_add_med_post(self):

        User.objects.create_user(email='*****@*****.**', password='******', is_doctor=False,
                                 name='Test_user',
                                 family_name='Test_family_user')

        self.client.login(email='*****@*****.**', password='******')
        self.pre_set()
        from datetime import datetime, timedelta
        time = datetime.now() + timedelta(minutes=1)
        time_str = str(time)[11:16]

        date = localtime(now()).date()
        jdate = jdatetime.GregorianToJalali(date.year, date.month, date.day)
        jdate_str = str(jdate.jyear) + '-' + "%02d" % jdate.jmonth + '-' + "%02d" % jdate.jday
        data = {'self-med-name': 'anti-human2', 'self-med-total_dosage': 200, 'self-med-dosage_every_time': 10,
                'self-med-time_interval': 1, 'self-med-starting_hour': time_str, 'self-med-starting_time': jdate_str}
        response = self.client.post(reverse('medicine_page:add_med', ),
                                    data=data, follow=True)

        self.assertRedirects(response, reverse('medicine_page:medicines'))
        self.assertEqual(SelfAddedMedicine.objects.count(), 1)
Exemplo n.º 8
0
    def formatday(self, day, events):
        events_per_day = events.filter(date__day=day)
        d = ''
        for event in events_per_day:
            d += f'<li> {event.get_html_url} </li>'

        if day != 0:
            hijri_date = convert.Gregorian(day=day,
                                           month=self.month,
                                           year=self.year).to_hijri()
            jd = jdatetime.date.fromgregorian(day=day,
                                              month=self.month,
                                              year=self.year)

            jal_month = jdatetime.GregorianToJalali(self.year, self.month, 15)
            jal_month = jdatetime.datetime(jal_month.jyear, jal_month.jmonth,
                                           jal_month.jday).strftime(' | %B %Y')

            hij_month = convert.Gregorian(self.year, self.month, 15).to_hijri()
            hij_month = convert.Hijri(hij_month.year, hij_month.month,
                                      hij_month.day)

            return f"<span id='jal-month' style='display: none;'>{jal_month}</span><span id='hij-month' style='display:none;'> | {hij_month.month_name()} {hij_month.year}</span><td title='{self.year}-{self.month}-{day} gregorian and {jd.year}-{jd.month}-{jd.day} shamsi and {hijri_date.year}-{hijri_date.month}-{hijri_date.day} ghamari' id='{self.year}-{self.month}-{day}'><span class='{day} date'>{day}</span><br><span class='{jd.day} jalali-day'>{jd.day}ش</span><br><span class='hijri-date {hijri_date.day}'>{hijri_date.day}ه</span><ul> {d} </ul></td>"
        return '<td></td>'
Exemplo n.º 9
0
 def get_date(self, id, lang=''):
     ''' return tweet post date time
     '''
     try:
         status = self.__get_status(id)
         status_date = status.created_at
         date = jdatetime.GregorianToJalali(
             status_date.year, status_date.month, status_date.day)
         if status.lang == 'fa' or lang == 'fa':
             return {
                 'code': '1',
                 'data': {
                     'year': date.jyear,
                     'month': date.jmonth,
                     'day': date.jday,
                     'time': status_date.strftime('%H:%M')
                 },
                 'message': None
             }
         else:
             return {
                 'code': '1',
                 'data': {
                     'year': date.gyear,
                     'month': date.gmonth,
                     'day': date.gday,
                     'time': status_date.strftime('%H:%M')
                 },
                 'message': None
             }
     except AttributeError:
         return {
             'code': '2',
             'data': None,
             'message': "Not Found! - Attribute Error!"
         }
Exemplo n.º 10
0
# -*- coding: utf-8 -*-
Exemplo n.º 11
0
 def find_jdate(year, month, day):
     jdate = jdatetime.GregorianToJalali(year, month, day)
     jdate = jdatetime.date(jdate.jyear, jdate.jmonth, jdate.jday)
     return jdate.year, jdate.month, jdate.day, jdate.weekday()