Ejemplo n.º 1
0
    def _create_subject(self):
        title = self.form_result['title']
        id = ''.join(Random().sample(string.ascii_lowercase, 8))  # use random id first
        lecturer = self.form_result['lecturer']
        location = self.form_result['location']
        sub_department_id = self.form_result.get('sub_department_id', None)
        description = self.form_result['description']

        if lecturer == '':
            lecturer = None

        #check to see what kind of tags we have got
        tags = [tag.strip().lower() for tag in self.form_result.get('tagsitem', [])]
        if tags == []:
            tags = [tag.strip().lower() for tag in self.form_result.get('tags', '').split(',')]

        stags = []
        for tag in tags:
            stags.append(SimpleTag.get(tag))

        subj = Subject(id, title, location, lecturer, description, stags)
        subj.sub_department_id = sub_department_id

        meta.Session.add(subj)
        meta.Session.flush()

        newid = subj.generate_new_id()
        if newid is not None:
            subj.subject_id = newid

        return subj
Ejemplo n.º 2
0
    def update(self, subject):
        if not hasattr(self, 'form_result'):
            redirect(url(controller='subject', action='add'))

        #check if we need to regenerate the id
        clash = Subject.get(self.form_result.get('location', None), subject.subject_id)
        if clash is not None and clash is not subject:
            subject.subject_id = subject.generate_new_id()

        subject.title = self.form_result['title']
        subject.lecturer = self.form_result['lecturer']
        subject.location = self.form_result['location']
        subject.description = self.form_result.get('description', None)
        subject.sub_department_id = self.form_result.get('sub_department_id', None)

        #check to see what kind of tags we have got
        tags = [tag.strip().lower() for tag in self.form_result.get('tagsitem', []) if len(tag.strip().lower()) < 250 and tag.strip() != '']
        if tags == []:
            tags = [tag.strip().lower() for tag in self.form_result.get('tags', '').split(',') if len(tag.strip()) < 250 and tag.strip() != '']

        subject.tags = []
        for tag in tags:
            subject.tags.append(SimpleTag.get(tag))

        # update subject permissions
        if check_crowds(["teacher", "moderator", "root"], c.user, subject) and 'subject_visibility' in self.form_result:
            subject.visibility = self.form_result['subject_visibility']
            subject.edit_settings_perm = self.form_result['subject_edit']
            subject.post_discussion_perm = self.form_result['subject_post_discussions']
            # remove subject from watched list for users who can't view subject anymore
            if subject.visibility != 'everyone':
                crowd_fn = is_university_member if subject.visibility == 'university_members' else is_department_member
                for watcher in subject.watching_users:
                    if not crowd_fn(watcher.user, subject):
                        watcher.user.unwatchSubject(subject)

        meta.Session.commit()

        redirect(url(controller='subject',
                    action='home',
                    id=subject.subject_id,
                    tags=subject.location_path))
Ejemplo n.º 3
0
    def update(self, group):
        values = self.form_result
        group.title = values['title']
        if values['year']:
            group.year = date(int(values['year']), 1, 1)
        group.description = values['description']
        group.default_tab = values['default_tab']
        group.admins_approve_members = (
                self.form_result['approve_new_members'] == 'admin')
        group.forum_is_public = (
                self.form_result['forum_visibility'] == 'public')
        group.mailinglist_moderated = (
                self.form_result['mailinglist_moderated'] == 'moderated')
        group.mailinglist_enabled = True
        group.wants_to_watch_subjects = self.form_result['can_add_subjects']
        group.has_file_area = self.form_result['file_storage']

        if not group.mailinglist_enabled and not group.forum_categories:
            group.forum_categories.append(ForumCategory(_('General'), _('Discussions on anything and everything')))


        # Fix default tab setting if needed.
        if group.default_tab == 'forum' \
           or group.default_tab == 'mailinglist':
            group.default_tab = 'home'

        if group.default_tab == 'files' \
           and not group.has_file_area:
            group.default_tab =  'home'

        if group.default_tab == 'subjects' \
           and not group.wants_to_watch_subjects:
            group.default_tab == 'home'

        if values['logo_delete']:
            group.logo = None

        if values['logo_upload'] is not None:
            logo = values['logo_upload']
            group.logo = logo.file.read()

        #check to see what kind of tags we have got
        tags = [tag.strip().lower() for tag in self.form_result.get('tagsitem', []) if len(tag.strip()) < 250 and tag.strip() != '']
        if tags == []:
            tags = [tag.strip().lower() for tag in self.form_result.get('tags', '').split(',') if len(tag.strip()) < 250 and tag.strip() != '']

        group.tags = []
        for tag in tags:
            group.tags.append(SimpleTag.get(tag))

        if not group.moderators or is_root(c.user):
            tag = values.get('location', None)
            group.location = tag

        if is_root(c.user):
            group.moderators = values['moderators']

        meta.Session.commit()
        h.flash(_('Group information and settings updated.'))

        redirect(url(controller='group', action='home', id=group.group_id))