Skip to content

Instantly share code, notes, and snippets.

View gcavalcante8808's full-sized avatar

Gabriel Abdalla Cavalcante gcavalcante8808

View GitHub Profile
Environment:
Request Method: POST
Request URL: http://localhost:8000/admin/core/domaincredential/add/
Django Version: 1.4b1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
@gcavalcante8808
gcavalcante8808 / urls.py
Created April 24, 2012 13:39
Exemplo Views.py --> Urls Amigáveis
from django.conf.urls.defaults import *
urlpatterns = patterns ('',
(r'^divulgacao/(?P<slug_categoria>[\w_-]+)/(?P<slug_divulgacao>[\w_-]+)/$', 'CAMINHOPARAAVIEW'),
)
@gcavalcante8808
gcavalcante8808 / views.py
Created June 8, 2013 14:59
IronWiki - Views - Article
class ArticleView(ListView):
model = Article
template_name = 'wiki/view.html'
def get_queryset(self, article_id=None):
article_id = self.kwargs.get("article_id")
self.queryset = Article.objects.filter(id=article_id)
return self.queryset
def get_context_data(self, **kwargs):
@gcavalcante8808
gcavalcante8808 / view.html
Created June 8, 2013 15:01
IronWiki - Template - ListView --> Article
{% extends "index.html" %}
{% load mptt_tags %}
{% load i18n %}
{% block wiki_breadcrumbs %}
{% recursetree nodes %}
{% if node.get_ancestors %}
{% for item in node.get_ancestors %}
<a href="{% url 'get' item.id %}">{{ item }}</a>
<span class="divider">/</span>
@gcavalcante8808
gcavalcante8808 / models.py
Created June 8, 2013 15:04
IronWiki --> models
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from mptt.models import MPTTModel, TreeForeignKey
#TODO: Handle the change agains current revision. At this moment, the change is manual.
class Article(MPTTModel):
"""
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/SEP/semcomputer/126DA47BC0A801A800C915099B9968CF/
Django Version: 1.5.3
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
@gcavalcante8808
gcavalcante8808 / djpyodbc_error.py
Created January 7, 2014 20:08
Django-PyODBC error with django 1.6.
Traceback (most recent call last):
File "/home/RFOC/01388863189/dev/pyodbc_test/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/RFOC/01388863189/dev/pyodbc_test/lib/python2.7/site-packages/django/contrib/admin/options.py", line 432, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/RFOC/01388863189/dev/pyodbc_test/lib/python2.7/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/RFOC/01388863189/dev/pyodbc_test/lib/python2.7/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/RFOC/01388863189/dev/pyodbc_test/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 198, in inner
import sys
import os
sys.path.insert(0, '/var/www/html/htpwd')
from htpwd import app as htpwdapp
def application(req_environ, start_response):
os.environ['HTPASSWD_FILE'] = req_environ['HTPASSWD_FILE']
os.environ['SECRET_KEY'] = req_environ['SECRET_KEY']
@gcavalcante8808
gcavalcante8808 / objectGUID support on django-ldapdb
Created September 3, 2014 14:53
A simple recipe to read objectGUID field from an active directory object on django-ldapdb.
from ldapdb.models.fields import CharField
from uuid import UUID
def guid2string(val):
""" convert an active directory binary objectGUID value as returned by
python-ldap into a string that can be used as an LDAP query value """
s = UUID(bytes_le=val)
return s
@gcavalcante8808
gcavalcante8808 / zabbix_models.py
Created November 5, 2014 00:32
Autogenerated models.py for Zabbix - Django ORM
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [app_label]'
# into your database.
from __future__ import unicode_literals