def add_subscription(request, pk_screen, type_sub): screen = get_object_or_404(Screen, pk=pk_screen) if not request.user.is_superuser and screen.owner_group not in request.user.groups.all( ): return utils.denied(request) form = SubscriptionForm(request.POST or None) if type_sub == "U": form.fields["priority"].initial = 1 form.fields["priority"].widget = HiddenInput() if not request.user.is_superuser: form.fields["feed"].queryset = Feed.objects.filter( submitter_group__in=request.user.groups.all()) actuel = Subscription.objects.filter(screen=screen).filter( subscription_type=type_sub) print(actuel) form.fields["feed"].queryset = form.fields["feed"].queryset.exclude( pk__in=[feed.feed.pk for feed in actuel]) if form.is_valid(): if not type_sub == "N" and not type_sub == "U": return utils.denied(request) form.instance.subscription_type = type_sub form.instance.screen = screen form.save() return redirect(reverse("view_screen", args=[screen.pk])) return render(request, 'app/add_subscription.html', { "form": form, "screen": screen, "type_sub": type_sub })
def delete_subscription(request, pk_sub): subscription = get_object_or_404(Subscription, pk=pk_sub) if not request.user.is_superuser and subscription.screen.owner_group not in request.user.groups.all( ): return utils.denied(request) subscription.delete() return redirect(reverse("view_screen", args=[subscription.screen.pk]))
def reject_content(request, pk): form = RejectContentForm(request.POST or None) if form.is_valid(): content = get_object_or_404(Content, pk=pk) if not request.user.is_superuser and content.feed.moderator_group not in request.user.groups.all( ): # Modo ou SuperAd return utils.denied(request) message = form.cleaned_data['reason'] content.state = 'R' content.user_moderator = request.user content.reject_reason = message content.save() msg_plain = render_to_string('app/email_rejected.txt', { 'user': content.user, 'content': content, 'message': message }) send_mail( 'Refus de votre affichage', msg_plain, settings.DEFAULT_FROM_EMAIL, [content.user.email], ) return redirect( reverse("content_list_moderate", args=[content.feed.pk])) else: return redirect(reverse("content_view", args=[pk]))
def view_screen(request, pk_screen): screen = get_object_or_404(Screen, pk=pk_screen) if not request.user.is_superuser and screen.hidden and screen.owner_group not in request.user.groups.all( ): return utils.denied(request) urgent = Subscription.objects.filter(screen=screen).filter( subscription_type="U").order_by("-priority") normal = Subscription.objects.filter(screen=screen).filter( subscription_type="N").order_by("-priority") hour = Hour.objects.filter( hour_group=screen.place_group.hour_group).order_by( "day", 'first_hour') if request.user.is_superuser or screen.owner_group in request.user.groups.all( ): can_admin = True else: can_admin = False return render( request, 'app/view_screen.html', { "screen": screen, "urgent": urgent, "normal": normal, "hour_list": hour, "can_admin": can_admin })
def content_view(request, pk): content = get_object_or_404(Content, pk=pk) form = RejectContentForm(None) if content.feed.submitter_group not in request.user.groups.all( ) and not request.user.is_superuser and content.feed.moderator_group not in request.user.groups.all( ): return utils.denied(request) if request.user.is_superuser or content.feed.moderator_group in request.user.groups.all( ): can_delete = True can_moderate = True else: can_delete = False can_moderate = False if content.user == request.user: can_delete = True image = Image.objects.filter(content=content) return render( request, 'app/content_view.html', { "content": content, "images": image, "form": form, "can_delete": can_delete, "can_moderate": can_moderate })
def delete_content(request, pk): content = get_object_or_404(Content, pk=pk) if not request.user.is_superuser and content.feed.moderator_group not in request.user.groups.all( ) and content.user != request.user: return utils.denied(request) pk_feed = content.feed.pk content.delete() return redirect(reverse("content_list", args=[pk_feed]))
def content_list_moderate(request, pk): feed = get_object_or_404(Feed, pk=pk) if feed.submitter_group not in request.user.groups.all( ) and not request.user.is_superuser and feed.moderator_group not in request.user.groups.all( ): return utils.denied(request) content = Content.objects.filter(feed=feed).filter(is_valid=True).filter( state="P").order_by('begin_date') return render(request, 'app/content_list.html', {"content": content})
def update_content(request, pk): content = get_object_or_404(Content, pk=pk) if not request.user.is_superuser and content.feed.moderator_group not in request.user.groups.all( ): return utils.denied(request) form = ContentUpdateForm(request.POST or None, instance=content) if form.is_valid(): form.save() return redirect(reverse("content_view", args=[pk])) return render(request, 'app/edit_content.html', { 'form': form, 'content': content })
def restaurant_add(request): form = RestaurantForm(request.POST or None) group_restaurant = Group.objects.get(pk=settings.RESTAURANTS_GROUP_PK) if not request.user.is_superuser and group_restaurant not in request.user.groups.all( ): return utils.denied(request) if form.is_valid(): for i in ["midi1", "midi2", "midi3", "midi4", "midi5"]: if i in request.FILES: content = Content() content.name = i + " - " + str(form.cleaned_data["date"]) content.user = request.user content.content_type = "I" content.content_url = "image" content.state = "P" content.duration = 7 content.begin_date = timezone.datetime.combine( form.cleaned_data["date"], timezone.datetime(1, 1, 1, hour=10).time()) content.end_date = timezone.datetime.combine( form.cleaned_data["date"], timezone.datetime(1, 1, 1, hour=14).time()) content.feed = Feed.objects.get( pk=settings.RESTAURANTS_FEED_PK) validator(request.FILES[i]) content.save() utils.save_image(request.FILES[i], content, request.user) for i in ["soir1", "soir2", "soir3", "soir4", "soir5"]: if i in request.FILES: content = Content() content.name = i + " - " + str(form.cleaned_data["date"]) content.user = request.user content.content_type = "I" content.content_url = "image" content.state = "P" content.duration = 7 content.begin_date = timezone.datetime.combine( form.cleaned_data["date"], timezone.datetime(1, 1, 1, hour=14).time()) content.end_date = timezone.datetime.combine( form.cleaned_data["date"], timezone.datetime(1, 1, 1, hour=20).time()) content.feed = Feed.objects.get( pk=settings.RESTAURANTS_FEED_PK) validator(request.FILES[i]) content.save() utils.save_image(request.FILES[i], content, request.user) return redirect(reverse("content_list", args=[content.feed.pk])) else: return render(request, 'app/restaurants.html', {"form": form})
def approve_content(request, pk): content = get_object_or_404(Content, pk=pk) if not request.user.is_superuser and content.feed.moderator_group not in request.user.groups.all( ): # Modo ou SuperAd return utils.denied(request) content.state = 'A' content.user_moderator = request.user content.save() msg_plain = render_to_string('app/email_approved.txt', { 'user': content.user, 'content': content }) send_mail( 'Validation de votre affichage', msg_plain, settings.DEFAULT_FROM_EMAIL, [content.user.email], ) return redirect(reverse("content_list_moderate", args=[content.feed.pk]))
def screen_monitoring(request): if not request.user.is_superuser: return utils.denied(request) screen = Screen.objects.order_by("name", "place_group") return render(request, "app/screen_monitoring.html", {"screen": screen})