Exemple #1
0
    def _pre_save(self):
        if self.default:
            cur_defs = get_model('mapplace').objects.filter(default=True)
            for c in cur_defs:
                c.default = False
                c.save()

        else:
            cur_defs = get_model('mapplace').objects.filter(default=True)
            if len(cur_defs) == 0:
                self.default = True
Exemple #2
0
    def _pre_save(self):
        if self.default:
            cur_defs = get_model("mapplace").objects.filter(default=True)
            for c in cur_defs:
                c.default = False
                c.save()

        else:
            cur_defs = get_model("mapplace").objects.filter(default=True)
            if len(cur_defs) == 0:
                self.default = True
 def tag_string_to_list(csv):
     ''' Parses a string of tags and returns a set of tag names. '''
     tag_model = get_model('tag')
     tags = set(map(lambda rawtag: tag_model.filter_tag(rawtag), csv.split(',')))
     if '' in tags:
         tags.remove('')
     return tags
    def create_activity(self, user, object, action):
        ''' 
        Creates a new User Activity object 

        Arguments:

            user
                User object who initiated the action

            object
                The object that was acted upon

            action
                The action as a string. Must be defined in 
                settings.USER_ACTIONS
        '''

        if settings.USER_ACTIONS and not action in settings.USER_ACTIONS:
            raise Exception('Invalid Action')

        if user.is_authenticated():
            ua = get_model('useractivity')()
            ua.user = user
            ua.action = action
            ua.content_object = object
            ua.save()
            user_activity_signal.send(sender=ua, action=ua.action)
Exemple #5
0
    def create_activity(self, user, object, action):
        ''' 
        Creates a new User Activity object 

        Arguments:

            user
                User object who initiated the action

            object
                The object that was acted upon

            action
                The action as a string. Must be defined in 
                settings.USER_ACTIONS
        '''

        if settings.USER_ACTIONS and not action in settings.USER_ACTIONS:
            raise Exception('Invalid Action')

        if user.is_authenticated():
            ua = get_model('useractivity')()
            ua.user = user
            ua.action = action
            ua.content_object = object
            ua.save()
            user_activity_signal.send(sender=ua, action=ua.action)
Exemple #6
0
    def get_route_feature(self, object):
        """ Get the route feature container for this object. """

        ct = ContentType.objects.get_for_model(object)
        pf = get_model("routefeature").objects.get(content_type=ct, object_id=object.id)

        return pf
 def comment(self, user, body):
     comment_model = get_model('comment')
     c = comment_model()
     c.author = user
     c.body = body
     c.content_object = self
     c.save()
     return c
    def get_tag_by_name(self, tagname):
        tag = None
        try:
            tag = self.tags.get(name=tagname)
        except get_model('tag').DoesNotExist:
            pass

        return tag
Exemple #9
0
    def get_route_feature(self, object):
        ''' Get the route feature container for this object. '''

        ct = ContentType.objects.get_for_model(object)
        pf = get_model('routefeature').objects.get(
            content_type = ct, object_id = object.id)

        return pf
 def tag_string_to_list(csv):
     ''' Parses a string of tags and returns a set of tag names. '''
     tag_model = get_model('tag')
     tags = set(
         map(lambda rawtag: tag_model.filter_tag(rawtag), csv.split(',')))
     if '' in tags:
         tags.remove('')
     return tags
 def comment(self, user, body):
     comment_model = get_model('comment')
     c = comment_model()
     c.author = user
     c.body = body
     c.content_object = self
     c.save()
     return c
    def get_tag_by_name(self, tagname):
        tag = None
        try:
            tag = self.tags.get(name=tagname)
        except get_model('tag').DoesNotExist:
            pass

        return tag
def get_user_model():
    ''' Gets the custom user model as defined by a specific locast app '''

    model_name = settings.USER_MODEL.split('.', 2)[1].lower()
    model = get_model(model_name)
    if not model:
        raise ImproperlyConfigured('Custom User Model incorrectly defined')

    return model
Exemple #14
0
    def add_feature(self, object, index = None):
        ''' Add a feature. '''

        if not self.has_feature(object):
            pf = get_model('routefeature')(route = self)
            pf.content_object = object
            if not index:
                pf.index = (self.routefeature_set.count()+1)
            pf.save()
    def add_feature(self, object, index = None):
        ''' Add a feature. '''

        if not self.has_feature(object):
            pf = get_model('routefeature')(route = self)
            pf.content_object = object
            if not index:
                pf.index = (self.routefeature_set.count()+1)
            pf.save()
def get_user_model():
    ''' Gets the custom user model as defined by a specific locast app '''

    model_name = settings.USER_MODEL.split('.',2)[1].lower()
    model = get_model(model_name)
    if not model:
        raise ImproperlyConfigured('Custom User Model incorrectly defined')

    return model
Exemple #17
0
    def add_feature(self, object, index=None):
        """ Add a feature. """

        if not self.has_feature(object):
            pf = get_model("routefeature")(route=self)
            pf.content_object = object
            if not index:
                pf.index = self.routefeature_set.count() + 1
            pf.save()
    def add_tag_by_name(self, tagname, system_tag=False):
        # TODO: better length checking. exception perhaps?
        if len(tagname) <= 32:
            tag_model = get_model('tag')
            tag, created = tag_model.objects.get_or_create(name=tagname)
            if created and system_tag:
                tag.system_tag = True
                tag.save()

            self.tags.add(tag)
    def get_routes_by_feature(self, feature):
        routes = []
        ct = ContentType.objects.get_for_model(feature)
        pfs = get_model('routefeature').objects.filter(content_type=ct,
                                                       object_id=feature.id)

        for pf in pfs:
            routes.append(pf.route)

        return routes
    def get_routes_by_feature(self, feature):
        routes = []
        ct = ContentType.objects.get_for_model(feature)
        pfs = get_model('routefeature').objects.filter(content_type = ct,
            object_id = feature.id)

        for pf in pfs:
            routes.append(pf.route)

        return routes
    def add_tag_by_name(self, tagname, system_tag=False):
        # TODO: better length checking. exception perhaps?
        if len(tagname) <= 32:
            tag_model = get_model('tag')
            tag, created = tag_model.objects.get_or_create(name=tagname)
            if created and system_tag:
                tag.system_tag = True
                tag.save()

            self.tags.add(tag)
    def flag(self, user, reason=''):
        ''' Flag this object. '''

        if not user.is_authenticated():
            return None

        flag_model = get_model('flag')
        flag = None

        if not self.is_flagged_by(user):
            flag = flag_model(content_object=self, user=user, reason=reason)
            flag.save()

        return flag
    def flag(self, user, reason=''):
        ''' Flag this object. '''

        if not user.is_authenticated():
            return None

        flag_model = get_model('flag')
        flag = None

        if not self.is_flagged_by(user):
            flag = flag_model(content_object=self, user=user, reason=reason)
            flag.save()

        return flag
Exemple #24
0
def get_comments(request, object, comment_id=None):
    comment_model = get_model('comment')

    if comment_id:
        comment = check_comment(object, comment_id)
        return APIResponseOK(content=api_serialize(comment))

    comments = comment_model.objects.get_comments(object)
    comments, total, pg = paginate(comments, request.GET)

    comment_arr=[]
    for c in comments:
        comment_arr.append(api_serialize(c))

    return APIResponseOK(content=comment_arr, total=len(comment_arr), pg=pg)
def get_comments(request, object, comment_id=None):
    comment_model = get_model('comment')

    if comment_id:
        comment = check_comment(object, comment_id)
        return APIResponseOK(content=api_serialize(comment))

    comments = comment_model.objects.get_comments(object)
    comments, total, pg = paginate(comments, request.GET)

    comment_arr = []
    for c in comments:
        comment_arr.append(api_serialize(c))

    return APIResponseOK(content=comment_arr, total=len(comment_arr), pg=pg)
Exemple #26
0
def content_page(request, fragment):
    fragment = fragment.split('/');
    if len(fragment) < 2:
        raise Http404

    model = get_model(fragment[0])
    if not model or (not model == Cast):
        raise Http404

    try:
        id = int(fragment[1])
    except ValueError:
        raise Http404

    cast = get_object_or_404(model, id=id)

    return render_to_response('cast_content_page.django.html', locals(), context_instance = RequestContext(request))
def content_page(request, fragment):
    fragment = fragment.split('/');
    if len(fragment) < 2:
        raise Http404

    model = get_model(fragment[0])
    if not model or (not model == models.Cast):
        raise Http404

    try:
        id = int(fragment[1])
    except ValueError:
        raise Http404

    cast = get_object_or_404(model, id=id)

    return render_to_response('cast_view.django.html', locals(), context_instance = RequestContext(request))
    def set_tags(self, tags):
        '''
        Sets the tags from either a list of tags or a simple comma-separated
        list of tags. Does not correctly handle quoted or escaped commas.
        '''

        tag_model = get_model('tag')

        # If it's a string, make it into a list of tag names
        if isinstance(tags, str) or isinstance(tags, unicode):
            tags = Taggable.tag_string_to_list(tags)

        # Clear all non-system tags
        for t in self.tags.filter(system_tag=False):
            self.tags.remove(t)

        # Add all the tags.
        for tagname in tags:
            self.add_tag_by_name(tagname)
    def set_tags(self, tags):
        '''
        Sets the tags from either a list of tags or a simple comma-separated
        list of tags. Does not correctly handle quoted or escaped commas.
        '''

        tag_model = get_model('tag')

        # If it's a string, make it into a list of tag names
        if isinstance(tags, str) or isinstance(tags, unicode):
            tags = Taggable.tag_string_to_list(tags)

        # Clear all non-system tags
        for t in self.tags.filter(system_tag=False):
            self.tags.remove(t)

        # Add all the tags.
        for tagname in tags:
            self.add_tag_by_name(tagname)
    def get_default_boundry(self):
        defs = get_model('boundry').objects.filter(default = True)
        if len(defs):
            return defs[0]

        return None
    def get_activities_by_model(self, model):
        ''' Returns all activities relating to a certain model. '''

        ct = ContentType.objects.get_for_model(model)
        return get_model('useractivity').objects.filter(content_type=ct)
    def get_activities_by_user(self, user):
        ''' Returns all activities initiated by a certain user. '''

        return get_model('useractivity').objects.filter(
            user=user).order_by('-time')
 def _pre_save(self):
     if self.default:
         cur_defs = get_model('boundry').objects.filter(default=True)
         for c in cur_defs:
             c.default = False
             c.save()
Exemple #34
0
 def _pre_save(self):
     if self.default:
         cur_defs = get_model('boundary').objects.filter(default=True)
         for c in cur_defs:
             c.default = False
             c.save()
    def get_default_boundry(self):
        defs = get_model('boundry').objects.filter(default=True)
        if len(defs):
            return defs[0]

        return None
    def get_activities_by_model(self, model):
        ''' Returns all activities relating to a certain model. '''

        ct = ContentType.objects.get_for_model(model)
        return get_model('useractivity').objects.filter(content_type=ct)
    def get_activities_by_user(self, user):
        ''' Returns all activities initiated by a certain user. '''

        return get_model('useractivity').objects.filter(user=user).order_by('-time')