def app_base_tpl(tpl_path, model_list):
    base_file = file(tpl_path, "w")
    base_file_content = r2s(
        "djenerator/app_base.html",
        dict(model_list=[(model_class_raw(i), i._meta.verbose_name_plural) for i in model_list]),
    )
    base_file.write(base_file_content)
    base_file.close()
Example #2
0
def feed_xfollow(request):
    pk = request.GET.get('pk','')
    obj = m.Feed.objects.get(pk=pk)
    user = request.user
    if user in obj.users.all():
        obj.users.remove(user)
        x = ''
    else:
        obj.users.add(request.user)
        x = 'un'
    template = 'feeds/feed_btn_%sfollow.html' % x
    html = r2s(template,{})
    return {'ret':'ok','html':html}
def create_form_view(
    model_list,
    path,
    importlist=["from django import forms\n", "from .models import *"],
    filename="forms.py",
    template_name="djenerator/forms.html",
):
    os.chdir(path)
    contents, view_file = deque(), file(filename, "w")
    view_file.write("\n".join(importlist) + "\n\n")
    for model in model_list:
        model_class_name = model_class_raw(model, as_is=True)
        file_str = r2s(template_name, dict(model=model_class_name))
        contents.append(file_str)
    else:
        for idx in range(len(contents)):
            view_file.write(contents.pop())
            view_file.write("\n")
        else:
            view_file.close()
Example #4
0
def build_for_user(user):
    print 'building for user:%s' % user
    out = OUT # TODO
    ctx = {'user':user}
    ctx['feeds'] = user.feed_set.all()
    ctx['title'] = 'readfree.me'
    ctx['site'] = 'http://readfree.me'
    for doc in OPF.walkfiles():
        rp = OPF.relpathto(doc)
        r = out/rp
        r.parent.makedirs_p()
        if doc.ext in ['.html','.opf','.ncx']:
            print 'rendering',rp
            s = r2s(doc,ctx)
            r.write_text(s,encoding='utf-8')
        else:
            print 'copying',rp
            copyfile(doc,r)
    cmd = 'kindlegen %s' % (OUT/'content.opf',)
    subprocess.call(cmd.split())
def create_urls_view(model_list, path):
    filename, template_name = "urls.py", "djenerator/urls.html"

    importlist = ["from django.conf.urls import patterns, include, url\n", "from .views import *"]

    os.chdir(path)
    contents, view_file = [], file(filename, "w")
    view_file.write("\n".join(importlist) + "\n\n")
    contents.append(
        "    url(r'^$', TemplateView.as_view(template_name='{0}/{0}_base.html'), name='{0}-base'),".format(
            model_list[0]._meta.app_label, model_list[0]._meta.app_label.replace("_", "")
        )
    )
    for model in model_list:
        model_class = model_class_raw(model, as_is=True)
        contents.append(
            "{0}url(r'^{1}/$', {2}ListView.as_view(), name='{1}-list'),".format(
                " " * 4, model_class.lower(), model_class
            )
        )
        for partial in ["create", "update", "detail", "delete"]:
            line = "{0}url(r'^{1}/{2}/{3}', {4}{5}View.as_view(), name='{1}-{2}'),"
            url_line = line.format(
                " " * 4,
                model_class.lower(),
                partial,
                "$" if partial in ["create", "list"] else "(?P<pk>[0-9]+)/$",
                model_class,
                partial.capitalize(),
            )
            contents.append(url_line)
        # contents.append("    ###")
    else:
        lines = r2s(template_name, dict(urlconf="\n".join(contents))) + "\n"
        view_file.write(lines)
        view_file.close()
def detail_tpl(tpl_path, app_name, model_name, attrs):
    _file = file(tpl_path, "w")
    _file_content = r2s("djenerator/app_detail.html", dict(app_name=app_name, model_name=model_name, attr_list=attrs))
    _file.write(_file_content)
    _file.close()
def delete_tpl(tpl_path, app_name, model_name):
    _file = file(tpl_path, "w")
    _file_content = r2s("djenerator/app_delete.html", dict(app_name=app_name, model_name=model_name))
    _file.write(_file_content)
    _file.close()