django etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
django etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

22 Ekim 2014 Çarşamba

Enlivepy A Different Approach to Html Templating in Python

Don’t worry - this blog entry won’t consist of me rambling about yet another templating engine that will change the world. Instead, I’ll be focusing on a practical aspect - the problems the current HTML templating libraries have and what can be possibly done about these issues.
Django and all other MVC/MVP frameworks do a great job at separating the Controller logic from the View logic. This way you can have all your complex operations in Controller and send back the data that needs to be shown or rendered to the end user. On the other end of this process you have a templating library - it takes Python objects and renders them.
Now, some of these templating libraries argue that having lots of logic in the representation layer is a bad thing (Django templating for example). Others, like Jinja2, are more lax and allow you to do lots of interesting things.
In both cases what we are actually doing is mixing data with logic. And while this might not seem like a problem with small applications, when you start operating on a greater scale, issues start to appear (a lot). Let me provide a few examples:
  • Front end developers (CSS/HTML developers) start having difficulties when editing html pages when something does not appear the way it should be appearing. They have to learn the templating engine your framework uses.
  • Sometimes HTML/CSS developers break the logic in html pages by replacing something by mistake.
  • Backend developers are not the best at editing both HTML and CSS (well, in most cases, at least!). I have had this happen to me quite a few times too. I receive the HTML from a designer team, after that I put it into the templating engine...and it has a radically changed appearance. When I compare the way it looks on the server and the original things are just looking completely different.
  • If HTML/CSS developers need to play or change something on the system, what they need is a working copy of the whole system. You need to give them ssh access to the staging server or something similar.
Read the rest of the article here.

7 Ekim 2014 Salı

Django Authentication Workflow

The existing Django Documentation explains everything about the Django authentication process in a pretty good way. Directions include adding your back end, replacing the built-in User model and many more. However, despite this good coverage, I had certain problems with seeing the big picture of the overall process. At times when I needed to create a new authentication backend, I always had to glance through the Django source again.
In this blog entry I’ll focus on the Django source code and documentation -- to be more exact, I will share my findings during reading both the source code and the documentation. Read the rest of the article on my new blog

30 Nisan 2009 Perşembe

Using GWT with Django


Well i tried GWT a few days ago and liked it very much. I'm not a js expert and for that reason dont use it too much in my web applications. But from time to time i need some fancy client-side apps to do ajaxian stuff easily. I had written an Independent Django app which was an ajax-driven event calendar. Therefore i did most of the work remotely via Django. I used jquey for ajaxian calls. But if i were a better js programmer i would do that job with less remote calls. But the Magic in GWT is cool you create your application with Java ; a very cool and easy language and it converts the written code into javascript which is compatible with most of the browsers. Therefore you dont bother with strange behaviour of the js and dont bother about if your code will run on BrowserA or BrowserX.

I followed the tutorial in GWT site and had a running application (StockWather). To complete that tutorial you probbaly would need to complete the StockWatcher firstly and then go on from here or you can just pull the code i wrote for that purpose from here[1] and just inspect it.

For communication of both ends i used XML,if you're not a fan of it you can use JSON also. I didnt use JSON because of the JSNI usage in Java code. I dont like hybrid codes like that...

  1. First create the server side code in Django :LINK
  2. You need to build a GET request in you JAVA code so u do that from here: LINK
  3. Parse the incoming XML string from Django and convert it to JAVA objects: LINK
  4. Write unittests for your client side code (GWT) because if you have errors u will get some strange JS errors which are not so decsriptive. : LINK
  5. Put GWT application in your media and put the generated HTML file in your templates directory.

Well that is all,it took some time to glue both of them (Django and GWT) but we have here a happy end :) GWT is cool but it has some little weird stuffs i dont understand yet. One of them is Designing the applications.I should find
an easy way to explain it to my designer :)

[1]: GWT-Django app

17 Mart 2009 Salı

Ajaxian Even Calendar on Django

That is an independent small app that can be useful for others that need some calendar and want to show some events on it. I couldnt find any django calendars which are ajaxian out there. Therefore if you need something like that use it, it is completely free. Let me know if you have any trouble with it.

Features are:
- Showing every month with events
- Small and big(excel like) versions
- Adding same event for a couple of days
- Adding lots of events on same day
- Facebox display of events
- Dual language arabic/english


Demo small : Link (on the left)
Demo Big : Link
Source : Link
Static directory : Link

For instalation look at README file in the source.
Have FUN and thanks to ADK for his design help ...

20 Ocak 2009 Salı

Django Admin ManyToMAny Behaviour

In that post want to share an experience with a Django behaviour that took all my day to solve it. In nowadays , i'm working on a freelance project and trying to finish project due to deadline (hate deadlines). Here is the small part of models i'm using


class SchoolSection(models.Model):
#snip

class GalleryItem(models.Model):
school_section = models.ManyToManyField(SchoolSection)
#snip



A pretty easy structure , the problem occurred when i connected the post_save signal to a method which was using the models above. When a new GalleryItem was saved i wanted to pre-populate some xml files according to new commers. Here is the simple code that was pulling the gallery items :


sc=SchoolSection.objects.all()
gi = GalleryItem.objects.filter(school_section = sc[0])


When i save an object i was not able to see the new added in query above. When i saved the object second time (edit->save) the new entry appeared. In a moment when i was going go crazy someone from #django channel told me that Django doesnt save the m2m relationships immediately due to performance issues. Therefore the solution was to override a method in admin part , here is the solution :


class GalleryItemAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
super(GalleryItemAdmin, self).save_model(request, obj, form, change)
form.save_m2m()
obj.save()



That is all, hope to help someone who has the same problem :)

29 Ekim 2008 Çarşamba

A new Django Site Added to public

In last 2 weeks i've been working as freelancer, searching for people around the world who need Django/Python help for their projects. It is kind of exciting because i meet new people and do different kind of work everytime. Well one of these was injazzat.com a static firm site which was converted to Django site. The guy who was responsible for that site hired me to fix some of bugzz in site. It seemed as an easy stuff there was a few typos some template errors. However when i went deeper into code saw that hardcoded parts that made that job a nightmare :) I spent all my week to fix that mess and now most of the parts are real dynamic and the site follows the DRY :) At the end of work the guy told me that i was the 4th person who tried to fix that site and succeed finally. All previous developers escaped or dissappeared ... The temporary link of site is here ,i dont know if it will be there tomorrow but as reference just put it here. I hope got more exciting projects in the future ...

To conclude , do not write hardcoded programs because someday they will be seen by other people believe me :)

Note : and also thanks to adk for his help with those designer and css stuff

18 Kasım 2007 Pazar

Django veya Zope Hangisi ?

Bu kısa yazımda yukarıdaki başlıkta yer alan Web geliştirme ortamları veya ecnebicesi “frameworkler” hakkında bahsedeceğim. Birini kötüleyip diğerini yüceltmek gibi bir yola başvurmak yerine hangisi nerede daha uygun şeklinde bir yol izlemeye çalışılacaktır.

Evet, Python ile Web geliştirme dünyasına dalmayı düşünüyorsanız bu yazı oldukça yararlı olacaktır diye düşünüyorum. Fazla boş lafa dalmadan başlayalım :

Öğrenme süreci :

Öğrenme süreci bakımından iki framework'u karşılaştıracak olursak. Zope ile aşina olmam benim 2 veya 3 ayımı aldı diyebilirim. Bu sürenin neden bu kadar çok sürdüğünü aşağıda yer alan diğer karşılaştırma maddelerinden anlayabilirsiniz. Django ile ilk uygulamamı onların sitesinde yer alan “hızlı tur” denilen belgeyi okuduktan sonra yazdım. Ve ilk haftanın sonunda şu andan üzerinde çalışmakta olduğum iptables Web arayüzü uygulamamı Django'ya port etmeye başlamış oldum. Django ile öğrenme sürecinin bu kadar kısa olması beni çok şaşırtmıştı ama bunun bir nedeni de daha önce Zope gibi bir framework ile cebelleşmemden kaynaklanıyor olabilir de :)...

Versiyon Karmaşası :

Bunun da karşılaştırması olur mu demeyin. Eğer Zope ile uğraşmaya başladıysanız zaten ne demek istediğimi anlıyorsunuzdur. Şöyle ki Zope ile başlayayım dediniz ve zope.org adresine gittiniz. Orada bulunan Zope 2 belgelerinden birini okumaya başladınız. Oradaki howto'yu okuduktan sonra bir de baktınız Zope 3 diye bir şey varmış. O da ne ki herhalde Zope2'nin bir devamıdır diyeceksiniz. Hayır oradaki amcalar yepyeni bir framework geliştirmeye başlamışlar. Yani Zope 2'nin Zope 3 versiyonuyla alakası yokmuş. Evet ben ilk önce Zope 2 ile alakalı birsürü belge okuduktan sonra bir de Zope 3 için o kadarını okumuştum :). Ama başlayacaksanız kesinlikle Zope 3 ile başlayın (Allah yardımcınız olsun :) ) çünkü, Zope 2 birkaç sene içinde belki de ortadan kaybolacaktır. Peki Django'da işler nasıl? evet onlarda o şekilde bir karmaşa yok. Ama ilginç olan bir nokta yeni sürümler çıkarmak yerine her zaman svn'in son versiyonlarını tavsiye etmeleridir. Evet versiyon ile alakalı bu kadar yeter.


Belge ve Kaynaklar:

Yeni bir teknolojiyi öğrenirken bu konu hakkındaki dokümanlar oldukça önemli bir yere sahiptir. Zope ile başlarsak, zope.org adresinde bulunan dokümanların çoğu oldukça eski. Bu yüzden de oradaki örnekleri uygulamaya çalışırken çoğu “import” ifadesinin hata verdiğini veya kullanılan methodların orada olmadığını göreceksiniz. Zope 3 de Doküman olarak kendini güncel tutmaya baksa da nereden başlayacağınızı kestirmeniz oldukça güçtür. Dökümanlarını wiki tarzında tutmaktalar ve adresi şurada : http://wiki.zope.org/zope3/Zope3Wiki. Fakat oraya girdiğinizde kendiniz de göreceksiniz ki aradığınızı bulmak oldukça güçtür. Django'da işler nasıl ? Evet http://www.djangoproject.com/documentation/ adresine giriyorsunuz ve yukarıdan aşağı doğru okumaya başlıyorsunuz. Sanırım daha fazla açıklamaya gerek yok.

Destek :

Yine bir teknojiyi öğrenirken, ki bu bir açık kaynak teknolojisi ise destek oldukça önemlidir. Destek derken paralı destekten bahsetmiyoruz, o işle uğraşan gönüllülerden bahsediyoruz. Zope ile başlarsak freenode'daki #zope kanalına girip zamanınızı kaybetmeyin derim . Bir soru sorduğunuzda cevabını ya birkaç saat sonra ya da hiç alamayacaksınız. Bunun yanında mail listelerini deneyebilirsiniz fakat , kolay sorular sormayın :) . Oradaki abiler oldukça bu işi ilerlettikleri için çok kolay sorulara zaman ayıramıyorlar. Django'da ise #django kanalına girdiğiniz zaman adamlar size cevap vermek için sıraya giriyor sanki. Kanalda bulunan kişi sayısı 300 altına genelde düşmüyor. Mail listesi de oldukça aktif günde 50'nin üzerinde mail siliyorum. Ayrıca evet salakça ve kolay sorular sorabilirsiniz :)

Bayağı yazılacak şey varmış aslında. O zaman bu sefer burada bırakıp bu yazıyı ikiye böleyim ben :) İkinci bölümde de iki platformdaki yazılım geliştirme aşamaları ve altyapıları hakkında biraz dedikodu yaparım. Bol Pythonlu günler....

Kaynakça:

Django : http://www.djangoproject.com/

Zope: http://www.zope.org/



17 Ekim 2007 Çarşamba

Static dosyalar -Django

Bugünlerde bir django projesi ile uğraşmaktayım. Bu yazının sebebi az önce çözdüğüm bir sorunu ileride yaşamak istememem :) Django statik dosyaları yani javascript,css,resimleri statik dosyalar olarak yorumlar,bu yüzden ona statiklerin nerede olduğunu söylemek gerekir.

Öncelikle settings.py içinde :

MEDIA_ROOT = '/home/medianin/oldugu/yer'

MEDIA_URL = '/yer/'


Daha sonra urls.py içine de :

urlpatterns += patterns ('',

(r'media/(?P.*)$','django.views.static.serve',{'document_root':'/home/template/yolu'}),
)

Başında '^' işaretinin olmadığına dikkat etmek gerekir.

En son olarak da template içeresinden çağırıken :



şeklinde çağrılar gerçekleştirilir.


Bu kadar bunu unutma !