def test_daily_to_rss_feed(self):
        daily = Daily(url='an url')

        daily_entry = DailyEntry(date='2015-12-28', type='reading', subject='a book about bonsai')
        daily.add_entry(daily_entry)

        daily_entry = DailyEntry(date='2015-12-30', type='studying', subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily_entry.add_reference(source='http://somewhere/blog.html', type='blog')
        daily.add_entry(daily_entry)

        expected_rss = '''<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Daily Activity Log: an url</title>
    <link>an url</link>
    <description>RSS feed generated from: an url</description>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>python-feedgen</generator>
    <language>en</language>
    <item>
      <title>studying: a book about trees</title>
      <description>&lt;a href=\'http://somewhere\'&gt;source&lt;/a&gt;&lt;br/&gt;&lt;a href=\'http://somewhere/blog.html\'&gt;blog&lt;/a&gt;&lt;br/&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:00:00 +0000</pubDate>
    </item>
    <item>
      <title>reading: a book about bonsai</title>
      <pubDate>Mon, 28 Dec 2015 00:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>
'''

        rss = daily_to_rss(daily)

        self.assertEqual(expected_rss, exclude_tag('lastBuildDate', rss))
    def test_when_daily_is_found_returns_rss(self):
        daily = Daily(url='an url')
        daily_entry = DailyEntry(date='2015-12-30', type='reading', subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily.add_entry(daily_entry)

        when(self.repository).find_by('an url').thenReturn(daily)

        status, message = self.action.execute('an url')

        self.assertEqual('ok', status)
        self.assertTrue(message.startswith("<rss "))
    def find_by(self, url):
        body = self.__body_from(url)
        events = self.__xml_from(body)

        if events is None:
            return None

        daily = Daily(url=url)

        for event in events:
            daily.add_entry(self.__daily_entry_from(event))

        return daily
Пример #4
0
    def find_by(self, url):
        body = self.__body_from(url)
        events = self.__xml_from(body)

        if events is None:
            return None

        daily = Daily(url=url)

        for event in events:
            daily.add_entry(self.__daily_entry_from(event))

        return daily
Пример #5
0
    def post(self, user_id):
        data = request.get_json()

        # create daily record (id, weather_id, img_path, satis)
        img_path = 'https://project-lookmorning.s3.ap-northeast-2.amazonaws.com/dailylook/{}'.format(
            data['file_name'])
        satis = data['satis']
        dt = data['dt']
        city = data['city']

        weather = Weather.query.filter_by(city=city, datetime=dt).first()
        if weather:
            weather_id = weather.id
        else:
            pass

        new_daily = Daily(weather_id=weather_id,
                          img_path=img_path,
                          satis=satis)
        db.session.add(new_daily)
        db.session.commit()

        # create mydaily record (id, user_id, daily_id)
        daily_id = Daily.query.filter_by(img_path=img_path).first().id
        new_myDaily = MyDaily(user_id, daily_id)
        db.session.add(new_myDaily)
        db.session.commit()
Пример #6
0
def submit_daily(request):
    """ Team members submit daily questions for reminder.
        If daily record exists for today, update its content, else create a new record.
        Parameters: yesterday, today, problem, serious, spid.
    """
    spid = request.POST.get("spid", None)
    yesterday = request.POST.get("yesterday", "")
    today = request.POST.get("today", "")
    problem = request.POST.get("problem", "")
    serious = request.POST.get("serious", "3")
    try:
        sprint = Sprint.objects.get(pk=spid)
        product = sprint.product
        if not product.has_member(request.user):
            return HttpResponse('{"error":"%s"}' % _("Not a team member"))
        dailys = Daily.objects.filter(sprint=sprint, member=request.user)
        daily = None
        if len(dailys) > 0:
            daily = dailys[0]
            if daily.scrumdate.date() != datetime.now().date():
                daily = None
        if not daily:
            daily = Daily(product=product, sprint=sprint, member=request.user)
        daily.yesterday = yesterday
        daily.today = today
        daily.problem = problem
        daily.serious = int(serious)
        daily.save()
        return HttpResponseRedirect("/daily")
    #        return HttpResponse('{"status":"OK"}')
    except Exception, e:
        logger.exception(e)
        return render(request, "error", {"err": _("Save failed, retry later.")})
 def full_daily(self):
     daily = Daily(url=AN_URL)
     first_entry = DailyEntry("2015-06-23", "trying", "My daily activity log")
     first_entry.add_reference("http://somewhere.internet/page.html", "source")
     second_entry = DailyEntry("2015-06-20", "reading", "A new book")
     second_entry.add_reference("http://somewhere.internet/page2.html", "source")
     second_entry.add_reference("http://somewhere.internet/page2.html", "other source")
     third_entry = DailyEntry("2015-06-18", "watching", "A movie")
     daily.add_entry(first_entry)
     daily.add_entry(second_entry)
     daily.add_entry(third_entry)
     return daily
Пример #8
0
async def api_create_daily_record(id, request, *, feedback_time, feedback_way,
                                  support_type, td_num, who_feedback,
                                  issue_desc, deal_time, finished, deal_desc,
                                  time_cost):

    logging.info('---------------api create daily record------------------')
    user = request.__user__

    if user is None:
        raise APIPermissionError('Please signin first.')

    if not isinstance(eval(td_num), int):
        raise APIValueError('td_num', 'td_num should be "int"!')
    if not isinstance(eval(time_cost), float):
        raise APIValueError('time_cost', 'time_cost should be "float"!')

    args = [
        feedback_time, feedback_way, support_type, td_num, who_feedback,
        issue_desc, deal_time, finished, deal_desc, time_cost
    ]
    for arg in args:
        if not arg or not arg.strip():
            raise APIValueError('%s' % arg, 'empty!')

    if finished == '是':
        finished = True
    else:
        finished = False

    daily = Daily(work_id=user.work_id,
                  feedback_time=feedback_time,
                  feedback_way=feedback_way,
                  support_type=support_type,
                  td_num=td_num,
                  who_feedback=who_feedback,
                  issue_desc=issue_desc,
                  deal_time=deal_time,
                  finished=finished,
                  deal_desc=deal_desc,
                  time_cost=time_cost,
                  who=user.name)
    await daily.save()
    return daily
Пример #9
0
def submit_daily(request):
    """ Team members submit daily questions for reminder.
        If daily record exists for today, update its content, else create a new record.
        Parameters: yesterday, today, problem, serious, spid.
    """
    spid = request.POST.get('spid', None)
    yesterday = request.POST.get('yesterday', '')
    today = request.POST.get('today', '')
    problem = request.POST.get('problem', '')
    serious = request.POST.get('serious', '3')
    try:
        sprint = Sprint.objects.get(pk=spid)
        product = sprint.product
        if not product.has_member(request.user):
            return HttpResponse('{"error":"%s"}' % _('Not a team member'))
        dailys = Daily.objects.filter(sprint=sprint, member=request.user)
        daily = None
        if len(dailys) > 0:
            daily = dailys[0]
            if daily.scrumdate.date() != datetime.now().date():
                daily = None
        if not daily:
            daily = Daily(product=product, sprint=sprint, member=request.user)
        daily.yesterday = yesterday
        daily.today = today
        daily.problem = problem
        daily.serious = int(serious)
        daily.save()
        return HttpResponseRedirect('/daily')


#        return HttpResponse('{"status":"OK"}')
    except Exception, e:
        logger.exception(e)
        return render(request, 'error',
                      {"err": _('Save failed, retry later.')})
    def test_daily_to_rss_feed(self):
        daily = Daily(url='an url')

        daily_entry = DailyEntry(date='2015-12-28',
                                 type='reading',
                                 subject='a book about bonsai')
        daily.add_entry(daily_entry)

        daily_entry = DailyEntry(date='2015-12-30',
                                 type='studying',
                                 subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily_entry.add_reference(source='http://somewhere/blog.html',
                                  type='blog')
        daily.add_entry(daily_entry)

        expected_rss = '''<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Daily Activity Log: an url</title>
    <link>an url</link>
    <description>RSS feed generated from: an url</description>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>python-feedgen</generator>
    <language>en</language>
    <item>
      <title>studying: a book about trees</title>
      <description>&lt;a href=\'http://somewhere\'&gt;source&lt;/a&gt;&lt;br/&gt;&lt;a href=\'http://somewhere/blog.html\'&gt;blog&lt;/a&gt;&lt;br/&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:00:00 +0000</pubDate>
    </item>
    <item>
      <title>reading: a book about bonsai</title>
      <pubDate>Mon, 28 Dec 2015 00:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>
'''

        rss = daily_to_rss(daily)

        self.assertEqual(expected_rss, exclude_tag('lastBuildDate', rss))