Skip to content

Instantly share code, notes, and snippets.

Guilherme de Carvalho Carneiro guilhermecarvalhocarneiro

Block or report user

Report or block guilhermecarvalhocarneiro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9742501
public class MessageBroadCast extends BroadcastReceiver {
String tag = "Mensagem";
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
try {
if(extras != null){
Log.i(tag, "Mensagem" + extras.getString("param1", "Nada"));
} catch (Exception e) {
guilhermecarvalhocarneiro /
Created May 20, 2014
Ocultando campos no get_form Django
def get_form(self, request, obj=None, **kwargs):
self.exclude = []
usuario = Usuario(user=request.user).get_user()
if not request.user.is_superuser:
if usuario.estabelecimento:
self.fields["cidade"].queryset = Cidade.objects.filter(
self.readonly_fields = ('atrativo', 'cidade', 'estabelecimento')
# Verificar como setar os valores para os campos cidade e estabelecimento
View formDjangoAngularJS
<form class="form" role="form" id="form-send-mail" name="formContact" novalidate>
{% csrf_token %}
<div class="form-group">
<label for="name">Nome</label>
<input type="text" class="form-control" required id="name" name="name" placeholder="Nome" data-ng-model="dataForm.nome">
<label for="phone">Telefone</label>
<input type="text" class="form-control" id="phone" name="phone" data-ng-model="dataForm.telefone">
<label for="subject">Assunto</label>
from django.conf.urls import patterns
urlpatterns = patterns('company.views',
(r'^$', 'index'),
(r'sobre/$', 'about_us'),
(r'contato/$', 'contact'),
(r'sendmail/', 'send_mail'),
def send_mail(request):
u"""Method for send contact"""
return_response = {}
print request.POST, request.GET
return_response['resposta'] = request.POST
except Exception, e:
return_response['resposta'] = e
return HttpResponse(json.dumps(return_response),
View gist:b3308c0e60010993fa37
$scope.sendMail = function(){
method: 'POST',
data: $.param($scope.dataForm),
url: '/company/sendmail/',
headers: {
'X-CSRFToken': $cookies['csrftoken']
}).success(function(data, status, headers, config){
View gist:5d9ca5716a704d32f776
public class ConvertDate : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
if (value != null)
// TODO Verificar como realizar a conversão sem gerar exception
string[] date_time_split = value.ToString().Split('T');
guilhermecarvalhocarneiro /
Created Aug 1, 2014
Trecho de código para ler os dados contidos no arquivo KML para popular o GoogleMaps.
def process_file_kml(sender, created, instance, **kwargs):
if created:
xmldoc = minidom.parse(instance.shape_file)
document_name = \
type_shape = None
for place in xmldoc.getElementsByTagName("Placemark"):
name_place = place.getElementsByTagName("name")[0]
View ClassesParaUsarNaAPIRestFull
# Create your models here.
class Abastecimento(models.Model):
valor_etanol = models.DecimalField("Valor Etanol", max_digits=9, decimal_places=2)
valor_gasolina = models.DecimalField("Valor Gasolina", max_digits=9, decimal_places=2)
valor_diesel = models.DecimalField("Valor Diesel", max_digits=9, decimal_places=2)
usuario = models.ForeignKey(Usuario, blank=True, null=True)
posto = models.ForeignKey('Posto', blank=True, null=True)
def __unicode__(self):
return u"Posto: %s - Valores: Gas R$ %s Alc R$ %s Die R$ %s" % (self.posto, self.valor_gasolina, self.valor_etanol, self.valor_diesel)
View AbastacimentoSerializer
class AbastecimentoSerializer(serializers.ModelSerializer):
class Meta:
model = Abastecimento
fields = ('posto', 'valor_etanol', 'valor_gasolina', 'valor_diesel')
depth = 2
You can’t perform that action at this time.