コード例 #1
0
ファイル: rental.py プロジェクト: Lucius-THU/iRental-backend
def update(request, id):
    params = request.params
    user = request.user
    q = Q(id=id)
    if not user.isadmin():
        q &= Q(equipment__provider_id=user.id)
    r = RentalRequest.objects.filter(q)
    if not r.exists():
        raise ValueError('not found')
    if params['approved']:
        e = r[0].equipment
        if e.user is not None:
            raise ValueError('already rented')
        r.update(approved=True, rejected=False)
        e.user = r[0].user
        e.rent_until = r[0].rent_until
        e.save()
        RentalRecord.objects.create(
            **{
                'user': e.user,
                'equipment': e,
                'returned': False,
                'rented_at': utcnow()
            })
    else:
        r.update(approved=False, rejected=True)
    Notification.create(r[0].user, params.get('notification'))
    return JsonResponse({})
コード例 #2
0
ファイル: views.py プロジェクト: Lucius-THU/iRental-backend
def launch(request, id):
    e = get_equipment(request, id)
    if e is None:
        raise ValueError('not found')
    e.launched = True
    e.requesting = False
    e.save()
    Notification.create(e.provider, request.params.get('notification'))
    return JsonResponse({})
コード例 #3
0
ファイル: base.py プロジェクト: matts1/Kno
    def create(cls, *args, **kwargs):
        task = cls(*args, **kwargs)
        task.save()

        from misc.models import Search  # bidirectional import
        Notification.create(
            users=task.course.students,
            heading='New task created',
            text='{} created in {}'.format(task.name, task.course.name),
            url=reverse('viewtask', args=(task.id,))
        )
        Search.add_words(kwargs['name'], task.id, Task)
        return task
コード例 #4
0
ファイル: views.py プロジェクト: Lucius-THU/iRental-backend
def discontinue(request, id):
    e = get_equipment(request, id)
    if e is None:
        raise ValueError('not found')
    e.launched = False
    e.requesting = False
    e.user = None
    e.rent_until = None
    e.save()
    e.rentalrecord_set.update(returned=True)
    if request.user != e.provider:
        Notification.create(e.provider, request.params.get('notification'))
    return JsonResponse({})
コード例 #5
0
ファイル: assign.py プロジェクト: matts1/Kno
 def create(cls, task, user, bonus):
     sub = cls.objects.filter(user=user, task=task).first()
     if sub is None:
         sub = AssignSubmission(user=user, task=task, criteria=None, data=bonus['data'], mark=0)
     else:
         sub.data = bonus['data']
     sub.save()
     Notification.create(
         users=[task.course.teacher],
         heading='Task handed in',
         text='{} handed in for {}'.format(user.get_full_name(), task.name),
         url=reverse('viewtask', args=(task.id,))
     )
     return sub.on_submit(bonus)
コード例 #6
0
def update(request, id):
    params = request.params
    r = get_provider_reqs(request, id)
    if not r.exists():
        raise ValueError('not found')
    if params['approved']:
        r.update(approved=True, rejected=False)
        user = r[0].user
        user.group = 'provider'
        user.save()
    else:
        r.update(approved=False, rejected=True)
    Notification.create(r[0].user, params.get('notification'))
    return JsonResponse({})
コード例 #7
0
    def post(self, request, *args, **kwargs):
        #print(request.POST)
        movie = Movie.objects.get(pk=request.POST.get("movie_pk"))
        title = request.POST.get("title")
        body = request.POST.get("body")
        rating = request.POST.get("rating")
        author = self.request.user

        review = Review.create(movie=movie,
                               title=title,
                               body=body,
                               author=author,
                               rating=rating)
        review.save()

        notification = Notification.create(title="New review for ",
                                           movie=movie,
                                           inside=review)
        notification.save()

        all_followers = movie.all_followers()
        for follower in all_followers:
            if (notification not in follower.notifications.all()):
                follower.notifications.add(notification)
            if (follower.chat_id):
                telegram_bot_sendtext(
                    follower.chat_id,
                    "New review for " + notification.movie_title +
                    " with title " + notification.inside_title,
                    "https://empire-of-movies.herokuapp.com" +
                    notification.inside_link)

        return redirect(review)
コード例 #8
0
    def post(self, request, *args, **kwargs):
        #print(request.POST)
        current_movie = Movie.objects.get(pk=self.kwargs.get('movie_pk'))
        title = request.POST.get('title')
        body = request.POST.get('body')
        rating = request.POST.get('rating')
        author = self.request.user
        new_review = Review.create(movie=current_movie,
                                   title=title,
                                   body=body,
                                   rating=rating,
                                   author=author)
        new_review.save()
        reviews = Movie.objects.get(
            pk=self.kwargs.get('movie_pk')).review.all()
        sum = 0
        total = 0
        reviewer = []
        for review in reviews:
            author = review.author
            if author in reviewer:
                pass
            else:
                current_author_review = Review.objects.filter(
                    author=author).filter(movie=current_movie)
                current_sum = 0
                current_total = 0
                for current in current_author_review:
                    current_sum += current.rating
                    current_total += 1
                sum += current_sum / current_total
                total += 1
                reviewer.append(author)
        if (total == 0):
            current_movie.website_rating = None
            current_movie.save()
        else:
            current_movie.website_rating = round(sum / total, 1)
            current_movie.save()

        all_followers = current_movie.all_followers()
        title = "New review for"
        # print(new_review.get_absolute_url())
        notification = Notification.create(title=title,
                                           movie=current_movie,
                                           inside=new_review)
        notification.save()
        for follower in all_followers:
            if (notification not in follower.notifications.all()):
                follower.notifications.add(notification)
            if (follower.chat_id):
                telegram_bot_sendtext(
                    follower.chat_id,
                    "New review for " + notification.movie_title +
                    " with title " + notification.inside_title,
                    "https://empire-of-movies.herokuapp.com" +
                    notification.inside_link)

        return redirect(new_review)
コード例 #9
0
    def post(self, request, *args, **kwargs):
        #print(request.POST)
        super().post(request, *args, **kwargs)
        current_movie = Movie.objects.get(pk=self.kwargs.get('movie_pk'))
        all_followers = current_movie.all_followers()
        title = "New discussion for"
        # print(self.object.get_absolute_url())
        notification = Notification.create(title=title,
                                           movie=current_movie,
                                           inside=self.object)
        notification.save()
        for follower in all_followers:
            if (notification not in follower.notifications.all()):
                follower.notifications.add(notification)
            if (follower.chat_id):
                telegram_bot_sendtext(
                    follower.chat_id,
                    "New discussion for " + notification.movie_title +
                    " with title " + notification.inside_title,
                    "https://empire-of-movies.herokuapp.com" +
                    notification.inside_link)

        return redirect(self.object)