Skip to content

Commit

Permalink
work on cydhcp templates, purge pdb finally
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Dec 11, 2012
1 parent 82cdd6b commit 42615d0
Show file tree
Hide file tree
Showing 89 changed files with 140 additions and 313 deletions.
10 changes: 10 additions & 0 deletions cyder/base/helpers.py
@@ -1,5 +1,6 @@
# Jingo helpers (Jinja2 custom filters)
import json
import string

from jingo import register

Expand All @@ -22,6 +23,15 @@ def humanized_class_name(obj, *args, **kwargs):

return humanized

@register.filter
def humanized_model_name(model_name, *args, **kwargs):
"""
Capitalize and add spaces to underscored db table names.
"""
model_name.replace('_', ' ')
return string.join([word[0].upper() + word[1:]
for word in model_name.split()])

@register.filter
def prettify_record_type(record_type, *args, **kwargs):
"""
Expand Down
44 changes: 24 additions & 20 deletions cyder/base/mixins.py
Expand Up @@ -9,39 +9,43 @@ class uses the ``_meta.db_table`` instance variable of an object to
calculate URLs. Because of this, you must use the app label of your
class when declaring urls in your urls.py.
"""
def get_detail_url(self):
@classmethod
def get_list_url(cls):
"""
Return the detail url of an object.
Return the 'list' url of an object. Class method since don't
need specific instance of object.
"""
return reverse(self._meta.db_table.replace('-', '_') + '-detail',
args=[self.pk])
return reverse(cls._meta.db_table)

def get_list_url(self):
@classmethod
def get_create_url(cls):
"""
Return the list url of an object.
Return the create url of the type of object (to be posted to).
"""
return reverse(self._meta.db_table.replace('-', '_') + '-list')
return cls.get_list_url() + '-create'

def get_update_url(self):
"""
Return the update url of an object.
Return the update url of an object (to be posted to). Not class method
because object pk needed.
"""
return reverse(self._meta.db_table.replace('-', '_') + '-update',
args=[self.pk])
return reverse(self._meta.db_table + '-update', args=[self.pk])

def get_delete_url(self):
"""
Return the delete url of an object.
Return the delete url of an object (to be posted to).
"""
return reverse(self._meta.db_table + '-delete', args=[self.pk])

def get_detail_url(self):
"""
Return the detail url of an object.
"""
return reverse(self._meta.db_table.replace('-', '_') + '-delete',
args=[self.pk])
return reverse(self._meta.db_table + '-detail', args=[self.pk])

def get_create_url(self):
def details(self):
"""
Return the create url of the type of object.
Return base details with generic postback URL for editable tables.
"""
try:
return reverse(self._meta.db_table.replace('-', '_') + '-create',
args=[self.pk])
except:
return reverse(self._meta.db_table.replace('-', '_') + '-create')
return {'url': reverse(self._meta.db_table + '-table-update',
args=[self.pk])}
16 changes: 8 additions & 8 deletions cyder/base/templates/base/includes/pagination.html
@@ -1,21 +1,21 @@
<div class="pagination">
<ul>
<li><a href="?page=1">First</a></li>
{% if object_list.has_previous() %}
{% if page_obj.has_previous() %}
<li>
<a href="?page={{ object_list.previous_page_number() }}">Prev</a>
<a href="?page={{ page_obj.previous_page_number() }}">Prev</a>
</li>
{% else %}
<li class="disabled">
<a href="#">Prev</a></li>
{% endif %}
</li>

{% for page in range(1, object_list.paginator.num_pages + 1) %}
{% for page in range(1, page_obj.paginator.num_pages + 1) %}
{# Divide range of pages into 10 so it doesn't fill up screen.
So 100-page-paginator would show 0...10...20...30 #}
{% if object_list.paginator.num_pages / 10 == 0 or object_list.paginator.num_pages < 10 %}
{% if object_list.number == page %}
{% if page_obj.paginator.num_pages / 10 == 0 or page_obj.paginator.num_pages < 10 %}
{% if page_obj.number == page %}
<li class="active">
<a href="#">{{ page }}</a>
</li>
Expand All @@ -27,14 +27,14 @@
{% endif %}
{% endfor %}

{% if object_list.has_next() %}
{% if page_obj.has_next() %}
<li>
<a href="?page={{ object_list.next_page_number() }}">Next</a></li>
<a href="?page={{ page_obj.next_page_number() }}">Next</a></li>
{% else %}
<li class="disabled">
<a href="#">Next</a></li>
{% endif %}
</li>
<li><a href="?page={{ object_list.paginator.num_pages }}">Last</a></li>
<li><a href="?page={{ page_obj.paginator.num_pages }}">Last</a></li>
</ul>
</div>
2 changes: 1 addition & 1 deletion cyder/base/templates/base/includes/sidebars.html
@@ -1,7 +1,7 @@
{% macro render_sidebar(request, urls_names) -%}
{% for named_url, name in urls_names %}
<span class="nav-item">
<a class="nav-link {{ 'selected' if url(named_url) in request.path }}" href="{{ url(named_url) }}">{{ name }}</a>
<a class="nav-link {{ 'selected' if url(named_url) == request.path }}" href="{{ url(named_url) }}">{{ name }}</a>
</span>
{% endfor %}
{%- endmacro %}
18 changes: 6 additions & 12 deletions cyder/base/templates/base/list.html
@@ -1,25 +1,19 @@
{% extends "base/base.html" %}
{% from "base/tables.html" import render_table %}

{% block title %}
{% if object_list %}
{{ object_list[0]|humanized_class_name + 's'}}
{% endif %}
{% endblock %}

{% block header %}
{% if object_list %}
{{ object_list[0]|humanized_class_name + 's'}}
{% endif %}
{% endblock %}
{% block title %}{{ model_name|humanized_model_name + 's'}}{% endblock %}
{% block header %}{{ model_name|humanized_model_name + 's'}}{% endblock %}

{% block action_bar %}
<a class="btn" href="{{ Model.get_create_url() }}">
Create {{ model_name|humanized_model_name }}
</a>
{% endblock %}

{% block content %}
{% block form %}{% endblock %}

{% if object_list and object_list.paginator %}
{% if page_obj %}
{% include "base/includes/pagination.html" %}
{% endif %}

Expand Down
7 changes: 3 additions & 4 deletions cyder/base/views.py
Expand Up @@ -17,13 +17,12 @@ class BaseListView(ListView):
"""
template_name = 'list.html'
extra_context = None
paginate_by = 200
paginate_by = 50

def get_context_data(self, **kwargs):
context = super(ListView, self).get_context_data(**kwargs)
context['form_title'] = "{0} Details".format(
self.form_class.Meta.model.__name__
)
context['Model'] = self.model
context['model_name'] = self.model._meta.db_table

# Extra_context takes precedence over original values in context.
try:
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/compile_search.py
Expand Up @@ -10,7 +10,6 @@
from cyder.cydhcp.vlan.models import Vlan
from cyder.cydhcp.utils import IPFilterSet

import pdb
import ipaddr


Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/compiler/compiler.py
Expand Up @@ -16,7 +16,6 @@
from parser import Parser
from utils import *
from itertools import izip
import pdb


class Compiler(object):
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/compiler/lexer.py
@@ -1,5 +1,4 @@
import re
import pdb


class Lexer(object):
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/compiler/parser.py
@@ -1,5 +1,4 @@
import re
import pdb
from copy import deepcopy
from tokenizer import Tokenizer
from utils import *
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/compiler/tokenizer.py
Expand Up @@ -15,7 +15,6 @@

from lexer import Lexer
import re
import pdb

PR_UOP = 1
PR_LPAREN = 2
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/parser.py
@@ -1,5 +1,4 @@
import re
import pdb

"""
<stmt> -> <term> <stmt>
Expand Down
1 change: 0 additions & 1 deletion cyder/core/search/search.py
Expand Up @@ -9,7 +9,6 @@
from cyder.cydhcp.site.models import Site
from cyder.cydhcp.vlan.models import Vlan

import pdb
import ipaddr


Expand Down
33 changes: 3 additions & 30 deletions cyder/core/search/views.py
@@ -1,37 +1,9 @@
from django.db.models import Q
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.shortcuts import get_object_or_404, redirect
from django.shortcuts import render
from django.contrib import messages
from django.forms.util import ErrorList
from django.http import HttpResponse

from cyder.core.system.models import System

from cyder.core.views import CoreDeleteView, CoreCreateView
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.interface.static_intr.models import StaticIntrKeyValue
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceForm
from cyder.cydhcp.interface.static_intr.forms import FullStaticInterfaceForm
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceQuickForm
from cyder.cydhcp.interface.static_intr.forms import CombineForm
from cyder.cydhcp.keyvalue.utils import get_attrs, update_attrs, get_aa, get_docstrings
from cyder.cydhcp.keyvalue.utils import get_docstrings, dict_to_kv
from cyder.cydhcp.range.models import Range
from cyder.cydhcp.network.utils import calc_parent_str

from cyder.cydns.domain.models import Domain
from cyder.cydns.address_record.models import AddressRecord
from cyder.cydns.ptr.models import PTR

from cyder.core.search.parser import parse
from cyder.core.search.search import compile_search

import re
import ipaddr
import operator
import simplejson as json


def search(request):
search = request.GET.get('search', None)
Expand All @@ -41,8 +13,9 @@ def search(request):
dos_terms = ['10', 'com', 'mozilla.com', 'mozilla', 'network:10/8',
'network:10.0.0.0/8']
if search in dos_terms:
return HttpResponse('Denial of Service attack prevented. The search '
'term \'{0}\' is too general'.format(search))
return HttpResponse(
'Denial of Service attack prevented. The search '
'term \'{0}\' is too general'.format(search))
query = parse(search)
print '----------------------'
print query
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/build/subnet.py
@@ -1,7 +1,6 @@
from cyder.cydhcp.network.models import Network
from cyder.cydhcp.interface.static_intr.models import StaticInterface

import pdb

# This doesn't work for IPv6

Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/build/views.py
Expand Up @@ -3,7 +3,6 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse

import pdb


def build_network(request, network_pk):
Expand Down
30 changes: 0 additions & 30 deletions cyder/cydhcp/bulk_change/views.py
@@ -1,39 +1,9 @@
from django.db.models import Q
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.shortcuts import get_object_or_404, redirect, render_to_response
from django.shortcuts import render
from django.contrib import messages
from django.forms.util import ErrorList
from django.http import HttpResponse

from cyder.core.system.models import System

from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.interface.static_intr.models import StaticIntrKeyValue
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceForm
from cyder.cydhcp.interface.static_intr.forms import FullStaticInterfaceForm
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceQuickForm
from cyder.cydhcp.interface.static_intr.forms import CombineForm
from cyder.cydhcp.keyvalue.utils import get_attrs, update_attrs, get_aa, get_docstrings
from cyder.cydhcp.keyvalue.utils import get_docstrings, dict_to_kv
from cyder.cydhcp.views import CydhcpDeleteView, CydhcpCreateView
from cyder.cydhcp.range.models import Range
from cyder.cydhcp.network.utils import calc_parent_str

from cyder.cydns.domain.models import Domain
from cyder.cydns.address_record.models import AddressRecord
from cyder.cydns.ptr.models import PTR

from cyder.core.search.parser import parse
from cyder.core.search.search import compile_search

import pdb
import re
import ipaddr
import operator
import simplejson as json


from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('cydhcp.bulk_change', 'templates'))

Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/A_tests.py
Expand Up @@ -9,7 +9,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class AStaticRegTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/CNAME_tests.py
Expand Up @@ -9,7 +9,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class CNAMEStaticRegTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/PTR_tests.py
Expand Up @@ -8,7 +8,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class PTRStaticRegTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/aux_attrs.py
Expand Up @@ -10,7 +10,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class AuxAttrTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/basic.py
Expand Up @@ -10,7 +10,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class StaticInterTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion cyder/cydhcp/interface/static_intr/tests/deletetion.py
Expand Up @@ -10,7 +10,6 @@

from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize

import pdb


class DeleteStaticInterTests(TestCase):
Expand Down

0 comments on commit 42615d0

Please sign in to comment.