def create_project(request): form = ProjectCreationForm(request.POST) # TODO: Form validation project = Project.objects.create( project_creator=get_request_contributor(request), project_name=form.data.get('project_name'), project_short_description=form.data.get( 'project_short_description'), project_date_created=timezone.now(), project_url='', project_description='', project_location='', is_created=False) project = Project.objects.get(id=project.id) # Tag fields operate like ManyToMany fields, and so cannot # be added until after the object is created. Tag.merge_tags_field(project.project_issue_area, form.data.get('project_issue_area')) merge_single_file(project, form, FileCategory.THUMBNAIL, 'project_thumbnail_location') project.save() return project
def edit_user(request, user_id): user = Contributor.objects.get(id=user_id) if not (request.user.username == user.username or request.user.is_staff): raise PermissionDenied() project_fields_changed = False form = DemocracyLabUserCreationForm(request.POST) project_fields_changed |= read_form_field_string( user, form, 'first_name') project_fields_changed |= read_form_field_string( user, form, 'last_name') read_form_field_string(user, form, 'about_me') read_form_field_string(user, form, 'postal_code') read_form_field_string(user, form, 'country') Tag.merge_tags_field(user.user_technologies, form.data.get('user_technologies')) user.save() links_json_text = form.data.get('user_links') if len(links_json_text) > 0: links_json = json.loads(links_json_text) ProjectLink.merge_changes(user, links_json) files_json_text = form.data.get('user_files') if len(files_json_text) > 0: files_json = json.loads(files_json_text) ProjectFile.merge_changes(user, files_json) user_thumbnail_location = form.data.get('user_thumbnail_location') if len(user_thumbnail_location) > 0: thumbnail_file_json = json.loads(user_thumbnail_location) project_fields_changed |= ProjectFile.replace_single_file( user, FileCategory.THUMBNAIL, thumbnail_file_json) user_resume_file = form.data.get('user_resume_file') if len(user_resume_file) > 0: user_resume_file_json = json.loads(user_resume_file) ProjectFile.replace_single_file(user, FileCategory.RESUME, user_resume_file_json) if project_fields_changed: user.update_linked_items() SubscribeUserToQiqoChat(user)
def edit_project(request, project_id): project = Project.objects.get(id=project_id) if not request.user.username == project.project_creator.username: raise PermissionDenied() form = ProjectCreationForm(request.POST) project.project_description = form.data.get('project_description') project.project_location = form.data.get('project_location') project.project_name = form.data.get('project_name') project.project_url = form.data.get('project_url') issue_areas = form.data.get('project_issue_area') if issue_areas and len(issue_areas) != 0: Tag.merge_tags_field(project.project_issue_area, issue_areas) project.save() links_json_text = form.data.get('project_links') if len(links_json_text) > 0: links_json = json.loads(links_json_text) ProjectLink.merge_changes(project, links_json) files_json_text = form.data.get('project_files') if len(files_json_text) > 0: files_json = json.loads(files_json_text) ProjectFile.merge_changes(project, files_json) project_thumbnail_location = form.data.get( 'project_thumbnail_location') if len(project_thumbnail_location) > 0: thumbnail_json = json.loads(project_thumbnail_location) existing_thumbnail = ProjectFile.objects.filter( file_project=project.id, file_category=FileCategory.THUMBNAIL.value).first() if not existing_thumbnail: thumbnail = ProjectFile.from_json(project, FileCategory.THUMBNAIL, thumbnail_json) thumbnail.save() elif not thumbnail_json['key'] == existing_thumbnail.file_key: thumbnail = ProjectFile.from_json(project, FileCategory.THUMBNAIL, thumbnail_json) thumbnail.save() existing_thumbnail.delete()
def edit_user(request, user_id): user = Contributor.objects.get(id=user_id) if not request.user.username == user.username: raise PermissionDenied() form = DemocracyLabUserCreationForm(request.POST) user.about_me = form.data.get('about_me') user.postal_code = form.data.get('postal_code') user.country = form.data.get('country') user.first_name = form.data.get('first_name') user.last_name = form.data.get('last_name') Tag.merge_tags_field(user.user_technologies, form.data.get('user_technologies')) user.save() links_json_text = form.data.get('user_links') if len(links_json_text) > 0: links_json = json.loads(links_json_text) ProjectLink.merge_changes(user, links_json) files_json_text = form.data.get('user_files') if len(files_json_text) > 0: files_json = json.loads(files_json_text) ProjectFile.merge_changes(user, files_json) user_thumbnail_location = form.data.get('user_thumbnail_location') if len(user_thumbnail_location) > 0: thumbnail_file_json = json.loads(user_thumbnail_location) ProjectFile.replace_single_file(user, FileCategory.THUMBNAIL, thumbnail_file_json) user_resume_file = form.data.get('user_resume_file') if len(user_resume_file) > 0: user_resume_file_json = json.loads(user_resume_file) ProjectFile.replace_single_file(user, FileCategory.RESUME, user_resume_file_json) SubscribeUserToQiqoChat(user)
def read_form_field_tags(model, form, field_name): """ Read tags form field into model field :param model: Model containing tag field :param form: Form data from front-end :param field_name: Name of field shared by model and form :return: True if changes to model tag field were made """ if field_name in form.data: return Tag.merge_tags_field(getattr(model, field_name), form.data.get(field_name)) return False
def edit_project(request, project_id): project = Project.objects.get(id=project_id) if not is_co_owner_or_staff(request.user, project): raise PermissionDenied() form = ProjectCreationForm(request.POST) project.project_description = form.data.get('project_description') project.project_short_description = form.data.get( 'project_short_description') project.project_location = form.data.get('project_location') project.project_name = form.data.get('project_name') project.project_url = form.data.get('project_url') Tag.merge_tags_field(project.project_issue_area, form.data.get('project_issue_area')) Tag.merge_tags_field(project.project_stage, form.data.get('project_stage')) Tag.merge_tags_field(project.project_technologies, form.data.get('project_technologies')) Tag.merge_tags_field(project.project_organization, form.data.get('project_organization')) project.save() positions_json_text = form.data.get('project_positions') if len(positions_json_text) > 0: positions_json = json.loads(positions_json_text) ProjectPosition.merge_changes(project, positions_json) links_json_text = form.data.get('project_links') if len(links_json_text) > 0: links_json = json.loads(links_json_text) ProjectLink.merge_changes(project, links_json) files_json_text = form.data.get('project_files') if len(files_json_text) > 0: files_json = json.loads(files_json_text) ProjectFile.merge_changes(project, files_json) project_thumbnail_location = form.data.get( 'project_thumbnail_location') if len(project_thumbnail_location) > 0: thumbnail_location_json = json.loads(project_thumbnail_location) ProjectFile.replace_single_file(project, FileCategory.THUMBNAIL, thumbnail_location_json)
def read_form_field_tags(model, form, field_name): if field_name in form.data: Tag.merge_tags_field(getattr(model, field_name), form.data.get(field_name))
def update_from_json(position, position_json): position.position_description = position_json['description'] position.description_url = position_json['descriptionUrl'] new_role = position_json['roleTag']['tag_name'] Tag.merge_tags_field(position.position_role, new_role) position.save()