def setup(request): if not request.auth_info.admin: raise Http404 from admin.inflect_data import INFLECT_PATTERNS for p in INFLECT_PATTERNS: # logging.info('p=%s',p) inflect = Inflect() inflect.init(owner=request.auth_info.email,gender=p[1],part=p[0],pattern=p[2],proposal=p[3]) inflect.save() return HttpResponse('ok')
def create(request): inflect = Inflect() inflect.init(owner=request.auth_info.email) if request.method == 'POST': form = InflectForm(request.POST, instance=inflect) if form.is_valid(): logging.info('edit inflect before %s'% inflect) form.save(commit=False) logging.info('edit inflect after %s'% inflect) inflect.save() return HttpResponseRedirect('..') else: form = InflectForm(instance=inflect) return render_to_response('admin/inflects_create.html', RequestContext(request, {'form':form}))
def clear_all(request): if not request.auth_info.admin: raise Http404 inflect_keys=Inflect.keys_all() logging.info('clear all inflect patterns %s'%inflect_keys) db.delete(inflect_keys) return HttpResponseRedirect('..')
def init_dicts(): global DICTS logging.info("init dicts") inflect_list = Inflect.list() DICTS = dict() for i in inflect_list: dict_key = "%s_%s" % (i.gender, i.part) if not dict_key in DICTS: DICTS[dict_key] = InflectDict() DICTS[dict_key].add(i.pattern, i.proposal)
def delete(request, inflect_id): inflect = Inflect.get_by_id(int(inflect_id)) if inflect is None: raise Http404 inflect.delete() return HttpResponseRedirect('../..')
def edit(request, inflect_id): inflect = Inflect.get_by_id(int(inflect_id)) if inflect is None: raise Http404 if request.method == 'POST': form = InflectForm(request.POST, instance=inflect) if form.is_valid(): logging.info('edit inflect before %s'% inflect) form.save(commit=False) logging.info('edit inflect after %s'% inflect) inflect.save() return HttpResponseRedirect('../..') else: form = InflectForm(instance=inflect) return render_to_response('admin/inflects_edit.html', RequestContext(request, {'form':form}))
def index(request): inflect_list=Inflect.list() return render_to_response('admin/inflects_index.html', RequestContext(request, { 'inflect_list': inflect_list }))