示例#1
0
def post(request):
    res = Result()
    config = SiteConfig.getSiteConfig()

    try:
        data = json.loads(request.body)["body"]

        config.name = data.get("name", config.name)
        config.link = data.get("link", config.link)
        config.enable_likes = data.get("enable_likes", config.enable_likes)

        if data.get("default_gallery"):
            gallery = Gallery.objects.get(pk=data["default_gallery"])
            config.default_gallery = gallery
    except RawPostDataException:
        if request.FILES.get("favicon"):
            dest = getRoot() / "favicon.ico"
            handle_uploaded_file(dest, request.FILES["favicon"])
            config.favicon = "favicon.ico"
        if request.FILES.get("icon"):
            dest = getRoot() / request.FILES["icon"].name
            handle_uploaded_file(dest, request.FILES["icon"])
            config.favicon = request.FILES["icon"].name

    config.save()

    res.append(SiteConfig.getSiteConfig().json())

    return JsonResponse(res.asDict())
示例#2
0
文件: comment.py 项目: ptrr/frog
def emailComment(comment, obj, request):
    """Send an email to the author about a new comment"""
    if not obj.author.frog_prefs.get().json()["emailComments"]:
        return

    if obj.author == request.user:
        return

    config = SiteConfig.getSiteConfig()

    html = render_to_string(
        "frog/comment_email.html",
        {
            "user": comment.user,
            "comment": comment.comment,
            "object": obj,
            "action_type": "commented on",
            "image": isinstance(obj, Image),
            "SITE_URL": FROG_SITE_URL,
        },
    )

    subject = "{}: Comment from {}".format(config.name, comment.user_name)
    fromemail = comment.user_email
    to = obj.author.email
    text_content = "This is an important message."
    html_content = html

    send_mail(subject,
              text_content,
              fromemail, [to],
              html_message=html_content)
示例#3
0
def emailLike(request, obj):
    if not obj.author.frog_prefs.get_or_create()[0].json()["emailLikes"]:
        return

    if obj.author == request.user:
        return

    config = SiteConfig.getSiteConfig()
    html = render_to_string(
        "frog/comment_email.html",
        {
            "user": request.user,
            "object": obj,
            "comment": "",
            "action_type": "liked",
            "image": isinstance(obj, Image),
            "SITE_URL": FROG_SITE_URL,
        },
    )
    subject = "{}: {} liked {}".format(
        config.name, request.user.username, obj.title
    )
    fromemail = request.user.email
    to = obj.author.email
    text_content = "This is an important message."
    html_content = html

    send_mail(subject, text_content, fromemail, [to], html_message=html_content)
示例#4
0
def emailUser(video, error=None):
    """Emails the author of the video that it has finished processing"""
    config = SiteConfig.getSiteConfig()
    html = render_to_string(
        "frog/video_email.html",
        {
            "user": video.author,
            "error": error,
            "video": video,
            "SITE_URL": config.site_url,
        },
    )
    subject, from_email, to = (
        "Video Processing Finished{}".format(error or ""),
        "*****@*****.**",
        video.author.email,
    )
    text_content = "This is an important message."
    html_content = html

    send_mail(subject,
              text_content,
              from_email, [to],
              html_message=html_content)
示例#5
0
def get(request):
    res = Result()
    res.append(SiteConfig.getSiteConfig().json())

    return JsonResponse(res.asDict())