Пример #1
0
    class HotTable(HotDjango.ModelSerialiser):
        sku = HotDjango.IDNameSerialiser(m.SKU)
        customer = HotDjango.IDNameSerialiser(m.Customer)
        season_var = HotDjango.IDNameSerialiser(m.SeasonalVariation)

        class Meta:
            fields = ('id', 'sku', 'customer', 'season_var', 'price', 'srf')
Пример #2
0
 def render(self, context):
     t = template.loader.get_template('handsontable_extra.html')
     app_name = self.app_name.resolve(context)
     model_name = self.model_name.resolve(context)
     this_id = int(self.id.resolve(context))
     dm = HotDjango.get_rest_apps()[app_name][model_name]
     extra_urls = {}
     field_names = [f.strip() for f in self.field_names.resolve(context).split(',')]
     for field_name in field_names:
         dj_field = dm.model._meta.get_field_by_name(field_name)[0]
         extra_urls[field_name] = {}
         extra_urls[field_name]['heading'] = HotDjango.get_verbose_name(dm, field_name) 
         if isinstance(dj_field, models.ManyToManyField):
             other_model_name = dj_field.rel.to.__name__
             extra_urls[field_name]['field'] = field_name
             url = reverse(rest_views.generate_reverse(app_name, model_name)\
                                                      + '-getm2m',  kwargs={'pk': this_id})
             extra_urls[field_name]['update_url'] = reverse(rest_views.generate_reverse(app_name, model_name)\
                                                      + '-setm2m',  kwargs={'pk': this_id})
         else:
             other_model_name = dj_field.model.__name__
             extra_urls[field_name]['filter_on'] = dj_field.field.name
             extra_urls[field_name]['filter_value'] = this_id
             url = reverse(rest_views.generate_reverse(app_name, other_model_name) + '-list')
         extra_urls[field_name]['url'] = url
     context['extra_urls'] = json.dumps(extra_urls)
     return t.render(template.Context(context))
Пример #3
0
    class HotTable(HotDjango.ModelSerialiser):
        period = HotDjango.IDNameSerialiser(m.SalesPeriod)
        promotion = HotDjango.IDNameSerialiser(m.Promotion)

        class Meta:
            fields = ('id', 'customer', 'period', 'store_count', 'promotion')
            readonly = ('period', )
            add_delete = False
Пример #4
0
    class HotTable(HotDjango.ModelSerialiser):
        group = HotDjango.IDNameSerialiser(m.SKUGroup)
        assemblies = HotDjango.IDNameSerialiser(m.Assembly, many=True)
        dft_season_var = HotDjango.IDNameSerialiser(m.SeasonalVariation)

        class Meta:
            fields = ('id', 'name', 'description', 'comment', 'dft_price',
                      'dft_srf', 'dft_season_var', 'group', 'assemblies')
Пример #5
0
 def set_links(self):
     links = super(DisplayItem, self).set_links()
     if self._disp_model.editable:
         links.append({
             'url':
             reverse('edit_item',
                     args=[self._app_name, self._model_name,
                           self._item.id]),
             'name':
             'Edit ' + self._single_t
         })
     if self._disp_model.deletable:
         links.append({
             'url':
             reverse('delete_item',
                     args=[self._app_name, self._model_name,
                           self._item.id]),
             'name':
             'Delete ' + self._single_t,
             'classes':
             'confirm-follow',
             'msg':
             'Are you sure you wish to delete this item?'
         })
     if hasattr(self._disp_model, 'related_tables'):
         field_names = self._disp_model.related_tables.keys()
         self._add_hot(field_names)
         for field_name in field_names:
             links.append({
                 'onclick':
                 "edit_related('%s')" % field_name,
                 'name':
                 'Edit Associated ' +
                 HotDjango.get_verbose_name(self._disp_model, field_name)
             })
     if hasattr(self._disp_model, 'HotTable'):
         for field_name in self._disp_model.HotTable.Meta.fields:
             dj_field = self._disp_model.model._meta.get_field_by_name(
                 field_name)[0]
             if isinstance(dj_field, models.ManyToManyField):
                 links.append({
                     'onclick':
                     "edit_m2m('%s')" % field_name,
                     'name':
                     'Edit Associated ' + HotDjango.get_verbose_name(
                         self._disp_model, field_name)
                 })
                 self._add_hot([field_name])
     return links
Пример #6
0
 def _get_info(self):
     fields = []
     self._all_apps = HotDjango.get_rest_apps()
     readonly = getattr(self._display_model.HotTable.Meta, 'readonly', [])
     for field_name in self._display_model.HotTable.Meta.fields:
         fields.append(self._get_field_info(field_name, field_name in readonly))
     return fields
Пример #7
0
 def _get_info(self):
     fields = []
     self._all_apps = HotDjango.get_rest_apps()
     readonly = getattr(self._display_model.HotTable.Meta, 'readonly', [])
     for field_name in self._display_model.HotTable.Meta.fields:
         fields.append(
             self._get_field_info(field_name, field_name in readonly))
     return fields
Пример #8
0
	def get_context_data(self, **kw):
		self._context = super(Index, self).get_context_data(**kw)
		self._context = super(Index, self).get_context_data(**kw)
		self._context['title'] = settings.SITE_TITLE
		table = HotDjango.get_all_apps()['ht_scoring__scoring']['Competition'].Table2
		self._context['table'] = table(m.Competition.objects.all())
		self.scoring_base()
		return self._context
Пример #9
0
	def set_links(self):
		links = super(DisplayItem, self).set_links()
		if self._disp_model.editable:
			links.append({'url': reverse('edit_item', args=[self._app_name, self._model_name, self._item.id]), 'name': 'Edit ' + self._single_t})
		if self._disp_model.deletable:
			links.append({'url': reverse('delete_item', args=[self._app_name, self._model_name, self._item.id]), 
					  'name': 'Delete ' + self._single_t, 'classes': 'confirm-follow', 
                      'msg': 'Are you sure you wish to delete this item?'})
		if hasattr(self._disp_model, 'related_tables'):
			field_names = self._disp_model.related_tables.keys()
			self._add_hot(field_names)
			for field_name in field_names:
				links.append({'onclick': "edit_related('%s')" % field_name,  
							'name': 'Edit Associated ' + HotDjango.get_verbose_name(self._disp_model, field_name)})
		if hasattr(self._disp_model, 'HotTable'):
			for field_name in self._disp_model.HotTable.Meta.fields:
				dj_field = self._disp_model.model._meta.get_field_by_name(field_name)[0]
				if isinstance(dj_field, models.ManyToManyField):
					links.append({'onclick': "edit_m2m('%s')" % field_name,  
								'name': 'Edit Associated ' + HotDjango.get_verbose_name(self._disp_model, field_name)})
					self._add_hot([field_name])
		return links
Пример #10
0
def generate_viewsets():
    modelviewsets = []
    for app_name, app in HotDjango.get_rest_apps().items():
        for model_name, disp_model in app.items():
            props={'model': disp_model.model}
            props['serializer_class'] = disp_model.HotTable
            props['_display_model'] = disp_model
            props['_app_name'] = app_name
            props['permission_classes'] = [permissions.IsAuthenticated, CustomIsAuthenticated]
            prefix = '%s.%s' % (app_name, model_name)
            cls=type(model_name, (ManyEnabledViewSet,), props)
            reverser = generate_reverse(app_name, model_name)
            modelviewsets.append((prefix, cls, reverser))
    return modelviewsets
Пример #11
0
 def _get_field_info(self, field_name, readonly):
     dm = self._display_model
     dj_field = dm.model._meta.get_field_by_name(field_name)[0]
     verb_name = HotDjango.get_verbose_name(dm, field_name)
     field = {'heading': verb_name, 'name': field_name, 'readonly': readonly or field_name == 'id'}
     field['type'] = dj_field.__class__.__name__
     if isinstance(dj_field, models.ForeignKey) or isinstance(dj_field, models.ManyToManyField):
         mod = dj_field.rel.to
         field['fk_items'] = self._add_fk_model(mod)
     elif isinstance(dj_field, models.related.RelatedObject) and hasattr(dm, 'related_tables'):
         other_disp_model = dm.related_tables[field_name]
         field['url'] = reverse(generate_reverse(self._app_name, other_disp_model.__name__) + '-list')
         field['filter_on'] = dj_field.field.name
     elif hasattr(dj_field, 'choices') and len(dj_field.choices) > 0:
         field['choices'] = [choice[1] for choice in dj_field.choices]
     return field
Пример #12
0
def generate_viewsets():
    modelviewsets = []
    for app_name, app in HotDjango.get_rest_apps().items():
        for model_name, disp_model in app.items():
            props = {'model': disp_model.model}
            props['serializer_class'] = disp_model.HotTable
            props['_display_model'] = disp_model
            props['_app_name'] = app_name
            props['permission_classes'] = [
                permissions.IsAuthenticated, CustomIsAuthenticated
            ]
            prefix = '%s.%s' % (app_name, model_name)
            cls = type(model_name, (ManyEnabledViewSet, ), props)
            reverser = generate_reverse(app_name, model_name)
            modelviewsets.append((prefix, cls, reverser))
    return modelviewsets
def basic_context(request, top_active=None):
    if top_active is not None:
        request.session['top_active'] = top_active
    elif 'top_active' in request.session:
        top_active = request.session['top_active']
    context = {}
    if 'message' in request.session:
        context['info'] = request.session.pop('info')
    if 'success' in request.session:
        context['success'] = request.session.pop('success')
    if 'errors' in request.session:
        context['errors'] = request.session.pop('errors')
    context['base_template'] = 'sk_page_base.html'
    if hasattr(settings, 'PAGE_BASE'):
        context['base_template'] = settings.PAGE_BASE
    raw_menu = []
    for item in settings.TOP_MENU:
        if 'groups' in item:
            if HotDjango.is_allowed_hot(request.user,
                                        permitted_groups=item['groups']):
                raw_menu.append(item)
        else:
            raw_menu.append(item)
    if request.user.is_staff:
        raw_menu.append({
            'url': 'admin:index',
            'name': 'Staff Admin',
            'glyph': 'wrench'
        })
    top_menu = []
    for item in raw_menu:
        menu_item = {'url': reverse(item['url']), 'name': item['name']}
        if 'glyph' in item:
            menu_item['glyph'] = item['glyph']
        if item['url'] == top_active:
            menu_item['class'] = 'active'
        top_menu.append(menu_item)

    context['top_menu'] = top_menu
    context['site_title'] = settings.SITE_TITLE
    return context
Пример #14
0
def base_context(request):
    context = {}
    apps = HotDjango.get_rest_apps()
    context['menu'] = []
    for app_name, app in apps.iteritems():
        for model_name in app.keys():
            context['menu'].append({
                'name':
                model_name,
                'url':
                reverse('hot-table',
                        kwargs={
                            'app': app_name,
                            'model': model_name
                        })
            })
    context['menu'].append({
        'name': 'Restful API',
        'url': reverse('all-hot-table') + 'restful'
    })
    context.update(csrf(request))
    return context
def basic_context(request, top_active = None):
    if top_active is not None:
        request.session['top_active'] = top_active
    elif 'top_active' in request.session:
        top_active = request.session['top_active']
    context = {}
    if 'message' in request.session:
        context['info'] = request.session.pop('info')
    if 'success' in request.session:
        context['success'] = request.session.pop('success')
    if 'errors' in request.session:
        context['errors'] = request.session.pop('errors')
    context['base_template'] = 'sk_page_base.html'
    if hasattr(settings, 'PAGE_BASE'):
        context['base_template'] = settings.PAGE_BASE
    raw_menu = []
    for item in settings.TOP_MENU:
        if 'groups' in item:
            if HotDjango.is_allowed_hot(request.user, permitted_groups=item['groups']):
                raw_menu.append(item)
        else:
            raw_menu.append(item)
    if request.user.is_staff:
        raw_menu.append({'url': 'admin:index', 'name': 'Staff Admin', 'glyph':'wrench'})
    top_menu = []
    for item in raw_menu:
        menu_item = {'url': reverse(item['url']), 'name': item['name']}
        if 'glyph' in item:
            menu_item['glyph'] = item['glyph']
        if item['url'] == top_active:
            menu_item['class'] = 'active'
        top_menu.append(menu_item)
    
    context['top_menu'] = top_menu
    context['site_title'] = settings.SITE_TITLE
    return context
Пример #16
0
 def _get_field_info(self, field_name, readonly):
     dm = self._display_model
     dj_field = dm.model._meta.get_field_by_name(field_name)[0]
     verb_name = HotDjango.get_verbose_name(dm, field_name)
     field = {
         'heading': verb_name,
         'name': field_name,
         'readonly': readonly or field_name == 'id'
     }
     field['type'] = dj_field.__class__.__name__
     if isinstance(dj_field, models.ForeignKey) or isinstance(
             dj_field, models.ManyToManyField):
         mod = dj_field.rel.to
         field['fk_items'] = self._add_fk_model(mod)
     elif isinstance(dj_field, models.related.RelatedObject) and hasattr(
             dm, 'related_tables'):
         other_disp_model = dm.related_tables[field_name]
         field['url'] = reverse(
             generate_reverse(self._app_name, other_disp_model.__name__) +
             '-list')
         field['filter_on'] = dj_field.field.name
     elif hasattr(dj_field, 'choices') and len(dj_field.choices) > 0:
         field['choices'] = [choice[1] for choice in dj_field.choices]
     return field
def get_display_apps():
    return HotDjango.get_all_apps()
Пример #18
0
    class HotTable(HotDjango.ModelSerialiser):
        component = HotDjango.IDNameSerialiser(m.Component)

        class Meta:
            fields = ('id', 'assembly', 'component', 'count')
Пример #19
0
 def has_permission(self, request, view):
     if request.user and request.user.is_authenticated():
         return HotDjango.is_allowed_hot(request.user)
     return False
Пример #20
0
    class HotTable(HotDjango.ModelSerialiser):
        skus = HotDjango.IDNameSerialiser(m.SKU, many=True)

        class Meta:
            fields = ('id', 'name', 'srf', 'price_ratio', 'skus')
Пример #21
0
    class HotTable(HotDjango.ModelSerialiser):
        manufacturer = HotDjango.IDNameSerialiser(m.Manufacturer)

        class Meta:
            fields = ('id', 'name', 'description', 'comment', 'minimum_order',
                      'manufacturer', 'costlevels')
 def is_allowed(self):
     return HotDjango.is_allowed_hot(self.request.user)
Пример #23
0
 def has_permission(self, request, view):
     if request.user and request.user.is_authenticated():
         return HotDjango.is_allowed_hot(request.user)
     return False
 def is_allowed(self):
     return HotDjango.is_allowed_hot(self.request.user)
def get_display_apps():
    return HotDjango.get_all_apps()
Пример #26
0
    class HotTable(HotDjango.ModelSerialiser):
        order_group = HotDjango.IDNameSerialiser(m.OrderGroup)

        class Meta:
            fields = ('id', 'name', 'description', 'comment', 'order_group')