コード例 #1
0
ファイル: views.py プロジェクト: onem-developer/reviews
    def get(self, request, id):
        item = get_object_or_404(Item, id=id)
        comments_count = Comment.objects.filter(item=item).count()

        menu_items = [
            MenuItem(description=item.item_description),
            MenuItem(description=u'Rating: {rating}'.format(
                rating=item.rating))
        ]

        menu_items.extend([
            MenuItem(
                description=u'Comments ({count})'.format(count=comments_count),
                method='GET',
                path=reverse('comment_list', args=[item.id]))
        ])

        # TODO: mention in the READ.ME file that the Rate options is only displayed
        # for an user who doesn't own the viewed item
        if item.item_owner != self.get_user():
            menu_items.extend([
                MenuItem(description=u'Rate',
                         method='GET',
                         path=reverse('rating', args=[item.id, item.rating]))
            ])

        content = Menu(body=menu_items, header=item.name)
        return self.to_response(content)
コード例 #2
0
ファイル: views.py プロジェクト: bogdanta/postdev
    def post(self, request):
        keyword = request.POST['keyword']
        # first check if keyword matches a post code
        if len(keyword) == 6:
            post = Post.objects.filter(code=keyword.lower())
            if post:
                return HttpResponseRedirect(
                    reverse('post_detail', args=[post[0].id]))

        # search in titles and post descriptions
        qs1 = Post.objects.filter(title__icontains=keyword).all()
        qs2 = Post.objects.filter(description__icontains=keyword).all()
        posts = qs1 | qs2

        menu_items = []
        if posts:
            if len(posts) == 1:
                return HttpResponseRedirect(
                    reverse('post_detail', args=[posts[0].id]))

            footer = u'Select an option'
            for post in posts:
                menu_items.append(
                    MenuItem(description=u'{}..'.format(post.title[:15]),
                             method='GET',
                             path=reverse('post_detail', args=[post.id])))
        else:
            menu_items.append(
                MenuItem(
                    description='There are no posts matching your keyword.'))
            footer = u'Reply MENU'
        content = Menu(body=menu_items, header='search', footer=footer)

        return self.to_response(content)
コード例 #3
0
ファイル: views.py プロジェクト: onem-developer/post-demo-app
    def get(self, request, id):
        post = get_object_or_404(Post, id=id)
        post.views += 1
        post.save()

        menu_items = []
        body_pre = [
            post.description, 'Author: {}'.format(post.user.username),
            'Expires in: {}'.format(human(post.expires_at)),
            'Code: {}'.format(post.code), 'Views: {}'.format(post.views)
        ]

        # check to see if we have notifications set in cache for this post
        if cache.get('new_post'):
            body_pre.insert(0, 'Post successfuly created!')
            cache.delete('new_post')
        elif cache.get('post_private'):
            body_pre.insert(0, 'Post marked as private!')
            cache.delete('post_private')
        elif cache.get('post_renewed'):
            body_pre.insert(0, 'Post successfuly renewed!')
            cache.delete('post_renewed')
        elif cache.get('msg_sent'):
            body_pre.insert(0, 'Your message successfuly sent!')
            cache.delete('msg_sent')
        elif cache.get('msg_not_sent'):
            body_pre.insert(0, 'Message was not sent, please try again later!')
            cache.delete('msg_sent')

        menu_items.extend([MenuItem(description=u'\n'.join(body_pre))])

        if post.user == self.get_user():
            # viewing user is the post owner
            menu_items.extend([
                MenuItem(description='Renew',
                         method='PUT',
                         path=reverse('post_detail', args=[post.id]) +
                         '?attr=renew'),
                MenuItem(description='Delete',
                         method='DELETE',
                         path=reverse('post_detail', args=[post.id]))
            ])
            if not post.is_private:
                menu_items.extend([
                    MenuItem(description='Make private',
                             method='PUT',
                             path=reverse('post_detail', args=[post.id]) +
                             '&attr=is_private')
                ])

        else:
            menu_items.extend([
                MenuItem(description='Send message',
                         method='GET',
                         path=reverse('send_msg', args=[post.id])),
            ])

        content = Menu(body=menu_items, header=post.title, footer='Reply MENU')

        return self.to_response(content)
コード例 #4
0
    def get(self, request, **kwargs):
        try:
            event = Event.objects.filter(id=kwargs['id'])[0]
        except IndexError:
            return self.to_response(
                Menu([MenuItem(description='Event unavailable')],
                     header='Unavailable',
                     footer='Reply MENU'))

        menu_items = [
            MenuItem(description='Edit description: {}'.format(
                truncatechars(event.description, 30)),
                     method='POST',
                     path=reverse('edit_event',
                                  args=(event.id, 'description'))),
            MenuItem(description='Edit starting date time: {date_time}'.format(
                date_time='{:%d-%m-%Y %H:%M}'.format(event.start_datetime)),
                     method='POST',
                     path=reverse('edit_event',
                                  args=(event.id, 'start_datetime'))),
            MenuItem(description='Edit ending date time: {date_time}'.format(
                date_time='{:%d-%m-%Y %H:%M}'.format(event.end_datetime)),
                     method='POST',
                     path=reverse('edit_event',
                                  args=(event.id, 'end_datetime'))),
            MenuItem(description='Delete',
                     method='DELETE',
                     path=reverse('edit_event', args=(event.id, 'delete')))
        ]
        content = Menu(body=menu_items, header='edit/delete')
        return self.to_response(content)
コード例 #5
0
    def get(self, request, id):
        try:
            event = Event.objects.filter(id=id)[0]
        except IndexError:
            return self.to_response(
                Menu([
                    MenuItem(description='Event unavailable'),
                ],
                     header='unavailable',
                     footer='Reply MENU'))

        menu_items = [
            MenuItem(description='Description: {}'.format(event.description)),
            MenuItem(description='Starting {date_time}'.format(
                date_time='{:%d-%m-%Y at %H:%M}'.format(
                    event.start_datetime))),
            MenuItem(description='Ending {date_time}'.format(
                date_time='{:%d-%m-%Y at %H:%M}'.format(event.end_datetime)))
        ]
        header = 'details'
        footer = 'Reply BACK/MENU'
        user = self.get_user()
        if user.is_staff:
            menu_items.append(
                MenuItem(description='Edit/Delete',
                         method='GET',
                         path=reverse('edit_event', args=(event.id, 'edit'))))
            header = 'admin menu'
            footer = None
        content = Menu(body=menu_items, header=header, footer=footer)
        return self.to_response(content)
コード例 #6
0
ファイル: views.py プロジェクト: bogdanta/contact_form
    def post(self, request):
        if self.get_user().is_admin:
            company_profile = AppAdmin.objects.get_or_create(
                admin_id=self.get_user().id,
                app_name=request.POST['app_name'].lower(),
                company_email=request.POST['company_email'],
                email_token=request.POST['email_token'])
            return self.to_response(
                Menu(body=[
                    MenuItem('Your business details have been updated!')
                ],
                     header='setup',
                     footer='Reply MENU'))
        else:
            user = self.get_user()
            if not user.email:
                user.email = request.POST['user_email']
                user.save()

            qs = AppAdmin.objects.filter(app_name=settings.APP_NAME)

            headers = {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'X-Postmark-Server-Token': qs[0].email_token
            }
            body = {
                'To':
                qs[0].company_email,
                'From':
                qs[0].
                company_email,  # `From:` field needs to be a registered Sender signature
                'Subject':
                'Inquiry from: {user_email}'.format(
                    user_email=request.POST.get('user_email', user.email)),
                'TextBody':
                request.POST['user_message']
            }

            send_email = requests.post(settings.API_URL,
                                       headers=headers,
                                       json=body)

            if send_email.status_code == 200:
                result_msg = u'Your email was successfully sent! You will shortly receive a response to your inquiry!'
            else:
                result_msg = u'An error occured. Please try again later!'

            return self.to_response(
                Menu(body=[MenuItem(description=result_msg)],
                     header='contact',
                     footer='--Reply MENU'))
コード例 #7
0
    def get(self, request, category):
        all_events = (Event.objects.annotate(
            year=ExtractYear('start_datetime')).annotate(
                start_week=ExtractWeek('start_datetime')))
        today = datetime.datetime.today()
        current_year = today.isocalendar()[0]
        current_week = today.isocalendar()[1]

        events = []
        if category == 'current_week':
            for event in all_events:
                if event.year == current_year and event.start_week == current_week:
                    events.append(event)
        elif category == 'future_events':
            for event in all_events:
                if (event.year == current_year and event.start_week >
                        current_week) or event.year > current_year:
                    events.append(event)
        else:
            for event in all_events:
                if (event.year == current_year and event.start_week <
                        current_week) or event.year < current_year:
                    events.append(event)
        menu_items = []
        for event in events:
            menu_items.append(
                MenuItem(description=truncatechars(event.description, 30),
                         method='GET',
                         path=event.get_absolute_url()))
        content = Menu(body=menu_items, header='menu')
        return self.to_response(content)
コード例 #8
0
 def post(self, request):
     keyword = request.POST['keyword']
     events = Event.objects.filter(Q(description__icontains=keyword))
     if not events:
         form_items = [
             FormItem(type=FormItemType.string,
                      name='keyword',
                      description='No results found. Please try again '
                      'with different keywords',
                      header='search',
                      footer='Reply keywords')
         ]
         content = Form(body=form_items,
                        method='POST',
                        path=reverse('search_wizard'),
                        meta=FormMeta(skip_confirmation=True))
     else:
         menu_items = []
         for event in events:
             menu_items.append(
                 MenuItem(description=truncatechars(event.description, 30),
                          method='GET',
                          path=event.get_absolute_url()))
         content = Menu(body=menu_items,
                        header='search: {}'.format(keyword))
     return self.to_response(content)
コード例 #9
0
ファイル: views.py プロジェクト: lasimion/django-omdb-ONEmSDK
    def post(self, request):
        keyword = request.POST['keyword']
        response = self.get_page_data(keyword)
        if response['Response'] == 'False':
            return self.to_response(
                Form(body=[
                    FormItemContent(type=FormItemContentType.string,
                                    name='result',
                                    description='No results',
                                    header='{keyword} SEARCH'.format(
                                        keyword=keyword.title()),
                                    footer='send BACK and search again')
                ],
                     method='GET',
                     path=reverse('home'),
                     meta=FormMeta(confirmation_needed=False,
                                   completion_status_in_header=False,
                                   completion_status_show=False)))

        body = []
        for result in response['Search']:
            body.append(
                MenuItem(type=MenuItemType.option,
                         description=u'{title} - {year}'.format(
                             title=result['Title'], year=result['Year']),
                         method='GET',
                         path=reverse('movie_detail',
                                      args=[result['imdbID']])))

        return self.to_response(
            Menu(body=body,
                 header='{keyword} SEARCH'.format(keyword=keyword.title()),
                 footer='Select result'))
コード例 #10
0
ファイル: views.py プロジェクト: onem-developer/reviews
 def get(self, request, id):
     # TODO: if viewing user is the comment owner - offer the option to
     # edit/delete the comment
     comment = get_object_or_404(Comment, id=id)
     content = Menu(body=[MenuItem(description=comment.text)],
                    header='comment',
                    footer='MENU')
     return self.to_response(content)
コード例 #11
0
ファイル: views.py プロジェクト: lasimion/django-omdb-ONEmSDK
 def get(self, request):
     body = [
         MenuItem(type=MenuItemType.option,
                  description='Search',
                  method='GET',
                  path=reverse('search_wizard'))
     ]
     user = self.get_user()
     history_count = user.history_set.count()
     if history_count:
         body.append(
             MenuItem(type=MenuItemType.option,
                      description='History ({count})'.format(
                          count=history_count),
                      method='GET',
                      path=reverse('history')), )
     return self.to_response(Menu(body=body, header='menu'))
コード例 #12
0
ファイル: views.py プロジェクト: bogdanta/postdev
    def get(self, request, post_id=None):
        user = self.get_user()
        if user.username == '':
            form_items = [
                FormItemContent(type=FormItemContentType.string,
                                name='username',
                                description='Please choose a username',
                                header='MENU',
                                footer='Send username')
            ]
            content = Form(body=form_items,
                           method='POST',
                           path=reverse('home'),
                           meta=FormMeta(confirmation_needed=False,
                                         completion_status_in_header=False,
                                         completion_status_show=False))
        else:
            menu_items = [
                MenuItem(description='Add post',
                         method='GET',
                         path=reverse('add_post')),
                MenuItem(description='Search',
                         method='GET',
                         path=reverse('search_wizard')),
                MenuItem(description='My posts',
                         method='GET',
                         path=reverse('my_posts'))
            ]

            posts = Post.objects.exclude(user=self.get_user()).exclude(
                is_private=True).order_by('-created_at').all()[:3]
            if posts:
                for post in posts:
                    menu_items.append(
                        MenuItem(description=u'{}..'.format(post.title[:17]),
                                 method='GET',
                                 path=reverse('post_detail', args=[post.id])))

            content = Menu(body=menu_items)

        return self.to_response(content)
コード例 #13
0
ファイル: views.py プロジェクト: onem-developer/reviews
    def get(self, request):
        menu_items = []
        # check if an item has just been rated
        rating_added = cache.get('rating_added')
        if rating_added:
            menu_items.append(
                MenuItem(description='Rating of {value} was added to {item}'.
                         format(value=rating_added['rating_value'],
                                item=rating_added['rated_item'])))
            cache.set('rating_added', None)

        items = Item.objects.all()  # local sqlite DB is already populated
        menu_items.extend([
            MenuItem(description=item.name,
                     method='GET',
                     path=reverse('item_detail', args=[item.id]))
            for item in items
        ])

        content = Menu(body=menu_items, header=u'REVIEWS HOME')
        return self.to_response(content)
コード例 #14
0
ファイル: views.py プロジェクト: onem-developer/post-demo-app
    def get(self, request):
        menu_items = []

        if cache.get('post_deleted'):
            menu_items.extend(
                [MenuItem(description='Post successfuly deleted!')])

        posts = Post.objects.filter(
            user=self.get_user()).order_by('-created_at')
        if posts:
            for post in posts:
                menu_items.append(
                    MenuItem(description=u'{}..'.format(post.title[:15]),
                             method='GET',
                             path=reverse('post_detail', args=[post.id])))
        else:
            menu_items.append(
                MenuItem(description='You currently have no posts.'))
        content = Menu(body=menu_items, footer='Reply MENU')

        return self.to_response(content)
コード例 #15
0
ファイル: views.py プロジェクト: onem-developer/reviews
    def get(self, request, id):
        menu_items = [
            MenuItem(description='Add comment',
                     method='GET',
                     path=reverse('add_comment', args=[id]))
        ]

        item = Item.objects.get(id=id)
        comments = Comment.objects.filter(item=item)
        if comments:
            for comment in comments:
                menu_items.append(
                    MenuItem(description=u'{}..'.format(comment.text[:18]),
                             method='GET',
                             path=reverse('comment_detail',
                                          args=[comment.id])))
        else:
            menu_items.append(
                MenuItem(description='This item has no comments yet.'))
        content = Menu(body=menu_items, footer='Reply MENU')

        return self.to_response(content)
コード例 #16
0
ファイル: views.py プロジェクト: lasimion/django-omdb-ONEmSDK
    def get(self, requset):
        user = self.get_user()
        history = user.history_set.order_by('-datetime')
        body = []
        for movie in history:
            body.append(
                MenuItem(type=MenuItemType.option,
                         description=u'{title} - {year}'.format(
                             title=movie.title, year=movie.year),
                         method='GET',
                         path=reverse('movie_detail', args=[movie.omdb_id])))

        return self.to_response(
            Menu(body=body, header='history', footer='Select from history'))
コード例 #17
0
    def get(self, request):
        all_events = (Event.objects.annotate(
            year=ExtractYear('start_datetime')).annotate(
                start_week=ExtractWeek('start_datetime')))
        today = datetime.datetime.today()
        current_year = today.isocalendar()[0]
        current_week = today.isocalendar()[1]

        this_week_events = []
        future_events = []
        past_events = []
        for event in all_events:
            if event.year == current_year and event.start_week == current_week:
                this_week_events.append(event)
            elif (event.year == current_year and event.start_week >
                  current_week) or event.year > current_year:
                future_events.append(event)
            else:
                past_events.append(event)

        menu_items = [
            MenuItem(description='Search',
                     method='GET',
                     path=reverse('search_wizard'))
        ]
        if not this_week_events:
            menu_items.append(MenuItem(description='No events this week'))
        else:
            menu_items.append(
                MenuItem(description='This week events ({})'.format(
                    len(this_week_events)),
                         method='GET',
                         path=reverse('events', args=('current_week', ))))
        if not future_events:
            menu_items.append(MenuItem(description='No future events'))
        else:
            menu_items.append(
                MenuItem(description='Future evens ({})'.format(
                    len(future_events)),
                         method='GET',
                         path=reverse('events', args=('future_events', ))))
        if not past_events:
            menu_items.append(MenuItem(description='No past events'))
        else:
            menu_items.append(
                MenuItem(description='Past evens ({})'.format(
                    len(past_events)),
                         method='GET',
                         path=reverse('events', args=('past_events', ))))
        user = self.get_user()
        if user.is_staff:
            menu_items.insert(
                0,
                MenuItem(description='Add event',
                         method='GET',
                         path=reverse('add_event')))

        # check to see if we have notifications set in cache
        if cache.get('event_added'):
            menu_items.insert(0,
                              MenuItem(description='Event added successfully'))
            cache.delete('event_added')
        if cache.get('event_edited'):
            menu_items.insert(
                0, MenuItem(description='Event edited successfully'))
            cache.delete('event_edited')
        if cache.get('event_deleted'):
            menu_items.insert(
                0, MenuItem(description='Event deleted successfully'))
            cache.delete('event_deleted')
        content = Menu(body=menu_items, header='menu')
        return self.to_response(content)