| | 552 | def get_filename(self): |
| | 553 | """ |
| | 554 | How to make it URL and filesystem save? |
| | 555 | """ |
| | 556 | return self.name + ".css" |
| | 557 | |
| | 558 | def get_absolute_url(self): |
| | 559 | """ |
| | 560 | Get the absolute url (without the domain/host part) |
| | 561 | """ |
| | 562 | filename = self.get_filename() |
| | 563 | url = posixpath.join( |
| | 564 | "", |
| | 565 | settings.MEDIA_URL, |
| | 566 | settings.PYLUCID_MEDIA_DIR, |
| | 567 | filename, # FIXME: url save? |
| | 568 | "" |
| | 569 | ) |
| | 570 | return url |
| | 571 | |
| | 572 | def get_filepath(self): |
| | 573 | """ |
| | 574 | FIXME: How to handle special characters? |
| | 575 | """ |
| | 576 | filename = self.get_filename() |
| | 577 | filepath = os.path.join( |
| | 578 | settings.MEDIA_ROOT, |
| | 579 | settings.PYLUCID_MEDIA_DIR, |
| | 580 | filename |
| | 581 | ) |
| | 582 | # FIXME: Should we use os.path.abspath() ? |
| | 583 | return filepath |
| | 584 | |
| | 585 | def save(self): |
| | 586 | """ |
| | 587 | Save a new or updated stylesheet. |
| | 588 | try to store the content into a file in the media path. |
| | 589 | """ |
| | 590 | filepath = self.get_filepath() |
| | 591 | try: |
| | 592 | f = file(filepath, "w") # FIXME: Encoding? |
| | 593 | content = self.content.encode(settings.FILE_CHARSET) |
| | 594 | f.write(content) |
| | 595 | f.close() |
| | 596 | except Exception, e: |
| | 597 | # FIXME: How can we give feedback? |
| | 598 | # print "Style save error:", e # Olny for dev server |
| | 599 | pass |
| | 600 | |
| | 601 | super(Style, self).save() # Call the "real" save() method |
| | 602 | |