# Path: moedjpack/moepad/mputils.py
# def sub_dict(somedict, somekeys, default=None):
# def loggerInit(logfile):
# def utcnow():
# def _deletePrefix(key):
# def create_default_db():


import feedparser
import datetime
import logging
import redis
import json
from django.http import HttpResponse, Http404
from django.shortcuts import *
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.forms import UserCreationForm
from forms import MPConfigForm, ForbiddenForm
from moedjpack.moepad.mputils import rs
from moedjpack.moepad.mpdefs import *

        if form.is_valid():
            rs.hmset("MoePadConf", request.POST)
        return render(request, "index.html", {"form": form})
    else:
        data = rs.hgetall("MoePadConf")
        form = MPConfigForm(initial=data)
        return render(request, "index.html", {"form": form})


@login_required
def forbidden_proc(request):
    print request.GET
    if request.method == 'POST':
        forbidden_keywords = request.POST['keywords'].split(',')
        f_set = set(forbidden_keywords)
        f_set.discard("")
        if f_set:
            for keyword in f_set:
                rs.sadd(FORBIDDENS, keyword)
    form = ForbiddenForm()
    forbidden_keywords = rs.smembers(FORBIDDENS)
    return render(request, "forbidden.html",
                  {"form": form, "forbiddens": forbidden_keywords})


@csrf_exempt
@login_required
def forbidden_item(request, item):
    if request.method == "DELETE":
        try:

# Path: moedjpack/moepad/mputils.py
# def sub_dict(somedict, somekeys, default=None):
# def loggerInit(logfile):
# def utcnow():
# def _deletePrefix(key):
# def create_default_db():


# Path: moedjpack/moewiki/views.py
import feedparser
import datetime
import logging
import redis
import json
from django.http import HttpResponse, Http404
from django.shortcuts import *
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.forms import UserCreationForm
from forms import MPConfigForm, ForbiddenForm
from moedjpack.moepad.mputils import rs
from moedjpack.moepad.mpdefs import *

        if form.is_valid():
            rs.hmset("MoePadConf", request.POST)
        return render(request, "index.html", {"form": form})
    else:
        data = rs.hgetall("MoePadConf")
        form = MPConfigForm(initial=data)
        return render(request, "index.html", {"form": form})


@login_required
def forbidden_proc(request):
    print request.GET
    if request.method == 'POST':
        forbidden_keywords = request.POST['keywords'].split(',')
        f_set = set(forbidden_keywords)
        f_set.discard("")
        if f_set:
            for keyword in f_set:
                rs.sadd(FORBIDDENS, keyword)
    form = ForbiddenForm()
    forbidden_keywords = rs.smembers(FORBIDDENS)
    return render(request, "forbidden.html",
                  {"form": form, "forbiddens": forbidden_keywords})


@csrf_exempt
@login_required
def forbidden_item(request, item):
    if request.method == "DELETE":
        try:

            rs.srem(FORBIDDENS, item)
