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";
@Override
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
guilhermecarvalhocarneiro / admin.py
Created May 20, 2014
Ocultando campos no get_form Django
View admin.py
def get_form(self, request, obj=None, **kwargs):
self.exclude = []
usuario = Usuario(user=request.user).get_user()
try:
if not request.user.is_superuser:
if usuario.estabelecimento:
self.fields["cidade"].queryset = Cidade.objects.filter(pk=usuario.cidade.pk)
self.readonly_fields = ('atrativo', 'cidade', 'estabelecimento')
# Verificar como setar os valores para os campos cidade e estabelecimento
else:
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">
<br>
<label for="phone">Telefone</label>
<input type="text" class="form-control" id="phone" name="phone" data-ng-model="dataForm.telefone">
<br>
<label for="subject">Assunto</label>
View urls.py
from django.conf.urls import patterns
urlpatterns = patterns('company.views',
(r'^$', 'index'),
(r'sobre/$', 'about_us'),
(r'contato/$', 'contact'),
(r'sendmail/', 'send_mail'),
)
View views.py
def send_mail(request):
u"""Method for send contact"""
return_response = {}
try:
print request.POST, request.GET
return_response['resposta'] = request.POST
except Exception, e:
return_response['resposta'] = e
finally:
return HttpResponse(json.dumps(return_response),
View gist:b3308c0e60010993fa37
$scope.sendMail = function(){
$http(
{
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)
{
try
{
if (value != null)
{
// TODO Verificar como realizar a conversão sem gerar exception
string[] date_time_split = value.ToString().Split('T');
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / LendoKMLGoogleMaps.py
Created Aug 1, 2014
Trecho de código para ler os dados contidos no arquivo KML para popular o GoogleMaps.
View LendoKMLGoogleMaps.py
def process_file_kml(sender, created, instance, **kwargs):
try:
if created:
xmldoc = minidom.parse(instance.shape_file)
document_name = \
xmldoc.getElementsByTagName("kml")[0].getElementsByTagName("Document")[0].getElementsByTagName("name")[
0]
type_shape = None
for place in xmldoc.getElementsByTagName("Placemark"):
name_place = place.getElementsByTagName("name")[0].firstChild.data
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.