def save_settings_form(self): """ Save the updated settings in the database Setting's save will trigger a cache update. If the field type is 'file' a file entry will be created. """ for setting in self.settings: old_value = setting.get_value() try: field_value = self.cleaned_data[setting.name] if setting.input_type == "file": if field_value: # save a file object and set the value at that file object's id. from tendenci.apps.files.models import File as TendenciFile uploaded_file = TendenciFile() uploaded_file.owner = self.user uploaded_file.owner_username = self.user.username uploaded_file.creator = self.user uploaded_file.creator_username = self.user.username uploaded_file.content_type = ContentType.objects.get( app_label="site_settings", model="setting") uploaded_file.file.save(field_value.name, File(field_value)) uploaded_file.save() field_value = uploaded_file.pk else: #retain the old file if no file is set field_value = setting.get_value() # update value if changed and save if old_value != field_value: setting.set_value(field_value) setting.save() # save updates the cash automatically # update the django site value in the contrib backend if setting.name == "siteurl" and setting.scope == "site": if field_value: django_site = Site.objects.get(pk=1) if urlparse(field_value).scheme == "": # prefix http:// if no scheme field_value = 'http://%s' % field_value netloc = urlparse(field_value).netloc django_site.domain = netloc django_site.name = netloc django_site.save() # update checklist for theme logo if setting.name == 'logo' and setting.scope_category == 'theme': checklist_update('upload-logo') # update checklist for contact form if setting.name == 'contact_form' and setting.scope == "site": checklist_update('update-contact') except KeyError: pass
def save_settings_form(self): """ Save the updated settings in the database Setting's save will trigger a cache update. If the field type is 'file' a file entry will be created. """ for setting in self.settings: old_value = setting.get_value() try: field_value = self.cleaned_data[setting.name] if setting.input_type == "file": if field_value: # save a file object and set the value at that file object's id. from tendenci.apps.files.models import File as TendenciFile uploaded_file = TendenciFile() uploaded_file.owner = self.user uploaded_file.owner_username = self.user.username uploaded_file.creator = self.user uploaded_file.creator_username = self.user.username uploaded_file.content_type = ContentType.objects.get(app_label="site_settings", model="setting") uploaded_file.file.save(field_value.name, File(field_value)) uploaded_file.save() field_value = uploaded_file.pk else: #retain the old file if no file is set field_value = setting.get_value() # update value if changed and save if old_value != field_value: setting.set_value(field_value) setting.save() # save updates the cash automatically # update the django site value in the contrib backend if setting.name == "siteurl" and setting.scope == "site": if field_value: django_site = Site.objects.get(pk=1) if urlparse(field_value).scheme == "": # prefix http:// if no scheme field_value = 'http://%s' % field_value netloc = urlparse(field_value).netloc django_site.domain = netloc django_site.name = netloc django_site.save() # update checklist for theme logo if setting.name == 'logo' and setting.scope_category == 'theme': checklist_update('upload-logo') # update checklist for contact form if setting.name == 'contact_form' and setting.scope == "site": checklist_update('update-contact') except KeyError: pass
def save_header_image(self, request, job): if self.is_valid(): f = self.cleaned_data['header_image'] if f: header_image = File() header_image.content_type = ContentType.objects.get_for_model(Job) header_image.object_id = job.id header_image.creator = request.user header_image.creator_username = request.user.username header_image.owner = request.user header_image.owner_username = request.user.username filename = "%s-%s" % (job.slug, f.name) f.file.seek(0) header_image.file.save(filename, f) job.header_image = header_image job.save() assign_files_perms(job, files=[job.header_image])
def save_file_from_url(self, url, instance): file_name = os.path.basename(urllib.unquote(url).replace(' ', '_')) tfile = TFile() tfile.name = file_name tfile.content_type = ContentType.objects.get_for_model(instance) tfile.object_id = instance.id if hasattr(instance, 'creator'): tfile.creator = instance.creator if hasattr(instance, 'creator_username'): tfile.creator_username = instance.creator_username if hasattr(instance, 'owner'): tfile.owner = instance.owner if hasattr(instance, 'owner_username'): tfile.owner_username = instance.owner_username #file_path = file_directory(tfile, tfile.name) tfile.file.save(file_name, ContentFile(urllib2.urlopen(url).read())) tfile.save() return tfile