My Sweet...Moon!


When this song hits me, I listen to it all over and over again. It's a bit sad but inspiring. I really love kids, like dreaming of having one right now. But I also have this in my mind that I'm not yet capable of giving her(I want a girl BTW) a very beautiful life.
I love the man you're making me
Yeah, every day I'm gonna prove there's nothing I won't do for you
Such a great love for his child.
OK, I should take up guitar lesson now 'cause I'm gonna write a song for my future Naleigh Moon.

Export Data from QuerySet as Excel File in Django

Let's say you have this function in your views.py:
def funtion_name(request):
    if request.method == "GET":
        get_id = request.user.id
        ...
        ...
        ...

        args = []
        kwargs = {
            'landproperty__sownerid__id': get_id,
            'geom__distance_lte': (pnt, D(km=kmdistance)),
            'narea__lte': getarea
        }


        mm = YourModelHere.objects.filter(*args, **kwargs).values_list('fielname1', 'fielname2', 'fielname3','fielname4')
        request.session[0] = mm
        return HttpResponse(json.dumps(list(m)), content_type='application/json')

In order to get or pass the QuerySet from this function, you need to store it in a session as shown above.

Here's how to create an excel file:
def create_excel(request):
    book = xlwt.Workbook(encoding='utf8')
    sheet = book.add_sheet('untitled')

    default_style = xlwt.Style.default_style
    datetime_style = xlwt.easyxf(num_format_str='dd/mm/yyyy hh:mm')
    date_style = xlwt.easyxf(num_format_str='dd/mm/yyyy')

    headers = ['Table Header 1', 'Table Header 2', 'Table Header 3', 'Table Header 4']
    values_list = [headers] + list(request.session[0])

    for row, rowdata in enumerate(values_list):
        for col, val in enumerate(rowdata):
            if isinstance(val, datetime):
                style = datetime_style
            elif isinstance(val, date):
                style = date_style
            else:
                style = default_style
            sheet.write(row, col, val, style=style)

    response = HttpResponse(mimetype='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename=example.xls'
    book.save(response)
    return response

That's it! Just use the session variable from the previous function (funtion_name).
SOURCE 1
SOURCE 2

I like her a lot...

I like her a lot that I stop and just stare her smile like forever. What the F***! I always love cute people and those who smiles like an anti-inflammatory capsule. Women really are powerful  being! Like drugs, they can ease pain and worsen it. They're like a double-edge sword. :D

Too bad, I'm so pessimistic! But I think, just this time I'll be hopeful. hahaha
Like I always say, for a long time I don't like being close to a woman, like having a romantic closeness. Sounds gay! hahaha
It's a choice! I do date sometimes but I just thought that I don't need a girlfriend that time. Too many reasons, right? I guess all those reasons won't matter if your feeling towards that girl is greater than those reasons. It's all about their weight.

And the song for this babble,
 

#MusicPlaylist 1: Getting a Good Night's Sleep


I usually don't play music when I want to sleep 'cause sometimes I sing along with it.

I have to tell you this
Cause my heart goes wild
-Russian Red

Electric-Lorde

When in comes to dancing, Lorde is the BEST! :D
I really love her, it makes my jaw drops and think of something weird. That's how good she is, actually she's just feelin' the song. 

Nah...just watch this video.

Changing password in Django

Add this to your urls.py:


url(r'^accounts/change-password/', 'django.contrib.auth.views.password_change',
    {'post_change_redirect' : '/accounts/password-changed/'}),
url(r'^accounts/password-changed/', 'django.contrib.auth.views.password_change_done'),

Just edit the links above. Then in you templates folder, create new folder and name it  registration . . Then create this html file below:


password_change_form.html
{% extends "edit_profile.html" %}
{% block head_title %}Change Password{% endblock %}
{% block content %}
<div class="jumbotron" style="width: 940px; margin: 80px auto; border-radius: 5px;">
    <form method="post" action=".">

         {% if next %}
                <input type="hidden" name="next" value="{{ next }}" />
            {% endif %}
        {{form.as_p}}
        <input type="submit" value="Change" class="btn btn-primary btn-lg" />
        {% csrf_token %}
    </form>
</div>
{% endblock %}

password_change_done.html
{% extends "edit_profile.html" %}
{% block head_title %}Password Change Successful{% endblock %}
{% block content %}
<div class="jumbotron" style="border-radius: 5px; margin: 80px auto; width: 940px;">
<div class="alert alert-success" style="padding: 5px;">
Your password has been changed successfully. Please <a href="https://www.blogger.com/accounts/logout/">re-login</a> with your new credentials
        or go back to the <a href="https://www.blogger.com/accounts/loggedin/">main page</a>.
    </div>
</div>
{% endblock %}

That's it! It should work fine. Here's what it looks like using Bootstrap.


Serializing Objects and Passing Multiple JSON Data in Django

Below is just an example, just replace the necessary Models and Queries:


def pins_info(request):
 if request.method == "GET":
  getpin = request.GET.get('pin', None)
  keyvals = OrderedDict([
   ('taxdec', 'landproperty__ctaxdec'),
   ('brgy', 'ssectionid__sbrgyid__cbrgyname'),
   ('landarea', 'narea')
  ])
  keyvals1 = OrderedDict([
   ('mydescription', 'description')
  ])

  m = ButuanMaps.objects.filter(clandpin=getpin).values_list(*keyvals.values())
  reference = ButuanMaps.objects.get(clandpin=getpin).geom
  within = SoilType.objects.filter(geom__contains=reference).values_list(*keyvals1.values())
  within1 = ErosionMap.objects.filter(geom__contains=reference).values_list(*keyvals1.values())
  result = dict(zip(keyvals, zip(*m)))
  result1 = dict(zip(keyvals1, zip(*within)))
  result2 = dict(zip(keyvals1, zip(*within1)))
  data = json.dumps([result, result1, result2], cls=DjangoJSONEncoder)
  return HttpResponse(data, content_type='application/json')
and in your template:
success: function(data) {
    taxdec = data[0]['taxdec'];
    brgy = data[0]['brgy'];
    landarea = data[0]['landarea'];
    soiltype = data[1]['mydescription'];
    erosion = data[2]['mydescription'];
    var inputform = $('#forminput').val();
    $('#infotable').append(
        "<tr><td class=\"bold\">Tax Declaration </td><td>" + taxdec +
        "</td></tr>" + "<tr><td class=\"bold\">Barangay</td><td>" +
        brgy + "</td></tr>" +
        "<tr><td class=\"bold\">Area of Land</td><td>" + landarea +
        " m&sup2;</td></tr>" +
        "<tr><td class=\"bold\">Soil Type</td><td>" + soiltype +
        "</td></tr>" + "<tr><td class=\"bold\">Erosion Type</td><td>" +
        erosion + "</td></tr>");
}
In order to identify the index of the data, just look up the console:

PS: Add `from collections import OrderedDict`,and from django.core.serializers.json import DjangoJSONEncoder in your views.py

He's awkward...and he's funny!

I think it is his gift. I mean really, his followers calls him "The King Of Awkwardness".
Watch his video below:


Some of my favorites:

So, I guess Vlad Tepes is the first mutant!

*maybe Apocalypse

After drinking the blood of the Master Vampire, Vlad had a strength of a 100 man. He can also turn into bats when fighting. In fact, he can control them which is cool; a BAT BENDER. haha
His eyesight is like a thermal  scanner.

But before that, he is known as "The Impaler". He doesn't feel anything after killing a thousand men.
blah blah blah.... :)

He is also a loving father and husband. A great leader for his people. Selfless, maybe.
BUT....
  • He can't stand in daylight. 
  • His skin peels off when he touches silver and eyesight seems to blur. 
  • Can be killed with a stick (hahaha)
Meet Merena...

Now, I have one more reason to watch Rurouni Kenshin

I watched the first film on my laptop, Kyoto Inferno in theater with my little sister and I'll be watching the last film in theater again because I just love it. And also,  Maryjun Takahashi is half-pinay Although her role is not quite that big (I haven't heard her voice in the film), she's on  Makoto Shishio's side.
Video ahead...